-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## #43: Prevent players from swimming up waterfalls
[Problem] Players can swim up waterfalls in areas where we want waterfalls as decoration but also need to restrict access. [Solution] Well there is none so far, since we tested and setting a player's hunger to 6 or lower does not work, since it is not implemented in Minestom to stop players from swimming or sprinting in this state. Also added some comments about potential structuring of handling these types of events when we have a solution.
- Loading branch information
Showing
3 changed files
with
100 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
modules/player/src/main/java/net/hollowcube/player/event/PlayerBubbleColumnSinkEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package net.hollowcube.player.event; | ||
|
||
import net.minestom.server.entity.Player; | ||
import net.minestom.server.event.trait.PlayerInstanceEvent; | ||
import net.minestom.server.instance.block.Block; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class PlayerBubbleColumnSinkEvent implements PlayerInstanceEvent { | ||
private final Player player; | ||
private final int energyLevel; | ||
|
||
public PlayerBubbleColumnSinkEvent(Player player, int energyLevel) { | ||
this.player = player; | ||
this.energyLevel = energyLevel; | ||
} | ||
|
||
@Override | ||
public @NotNull Player getPlayer() { | ||
return player; | ||
} | ||
|
||
public int getEnergyLevel() { | ||
return energyLevel; | ||
} | ||
|
||
public void cancelPlayerSwimming() { | ||
if (player.getInstance().getBlock(player.getPosition()) == Block.BUBBLE_COLUMN) { | ||
player.setFood(6); | ||
} | ||
} | ||
|
||
public void restorePlayerEnergy() { | ||
if (player.getInstance().getBlock(player.getPosition()) != Block.BUBBLE_COLUMN) { | ||
player.setFood(energyLevel); | ||
} | ||
} | ||
} |