diff --git a/src/main/java/net/knarcraft/minigames/arena/AbstractPlayerEntryState.java b/src/main/java/net/knarcraft/minigames/arena/AbstractPlayerEntryState.java index bfbce94..8c06be1 100644 --- a/src/main/java/net/knarcraft/minigames/arena/AbstractPlayerEntryState.java +++ b/src/main/java/net/knarcraft/minigames/arena/AbstractPlayerEntryState.java @@ -16,6 +16,7 @@ import org.jetbrains.annotations.NotNull; import java.util.HashMap; import java.util.HashSet; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.UUID; import java.util.logging.Level; @@ -32,6 +33,7 @@ public abstract class AbstractPlayerEntryState implements PlayerEntryState { private final boolean originalAllowFlight; private final boolean originalInvulnerable; private final boolean originalIsSwimming; + private final boolean originalCollideAble; /** * Instantiates a new abstract player entry state @@ -46,6 +48,7 @@ public abstract class AbstractPlayerEntryState implements PlayerEntryState { this.originalAllowFlight = player.getAllowFlight(); this.originalInvulnerable = player.isInvulnerable(); this.originalIsSwimming = player.isSwimming(); + this.originalCollideAble = player.isCollidable(); } /** @@ -58,10 +61,12 @@ public abstract class AbstractPlayerEntryState implements PlayerEntryState { * @param originalAllowFlight

Whether the player was allowed flight before entering the arena

* @param originalInvulnerable

Whether the player was invulnerable before entering the arena

* @param originalIsSwimming

Whether the player was swimming before entering the arena

+ * @param originalCollideAble

Whether the player was collide-able before entering the arena

*/ public AbstractPlayerEntryState(@NotNull UUID playerId, Location entryLocation, boolean originalIsFlying, GameMode originalGameMode, boolean originalAllowFlight, - boolean originalInvulnerable, boolean originalIsSwimming) { + boolean originalInvulnerable, boolean originalIsSwimming, + boolean originalCollideAble) { this.playerId = playerId; this.entryLocation = entryLocation; this.originalIsFlying = originalIsFlying; @@ -69,6 +74,7 @@ public abstract class AbstractPlayerEntryState implements PlayerEntryState { this.originalAllowFlight = originalAllowFlight; this.originalInvulnerable = originalInvulnerable; this.originalIsSwimming = originalIsSwimming; + this.originalCollideAble = originalCollideAble; } @Override @@ -88,6 +94,7 @@ public abstract class AbstractPlayerEntryState implements PlayerEntryState { @Override public void restore(@NotNull Player player) { + player.setCollidable(this.originalCollideAble); player.setAllowFlight(this.originalAllowFlight); player.setFlying(player.getAllowFlight() && this.originalIsFlying); player.setGameMode(this.originalGameMode); @@ -126,6 +133,7 @@ public abstract class AbstractPlayerEntryState implements PlayerEntryState { data.put("originalAllowFlight", this.originalAllowFlight); data.put("originalInvulnerable", this.originalInvulnerable); data.put("originalIsSwimming", this.originalIsSwimming); + data.put("originalCollideAble", this.originalCollideAble); return data; } @@ -155,4 +163,16 @@ public abstract class AbstractPlayerEntryState implements PlayerEntryState { } } + /** + * Gets a boolean value from a serialization map + * + * @param data

The serialization data to look through

+ * @param key

The key to get

+ * @return

The boolean value of the key

+ */ + protected static boolean getBoolean(Map data, String key) { + Boolean value = (Boolean) data.get(key); + return Objects.requireNonNullElse(value, false); + } + } diff --git a/src/main/java/net/knarcraft/minigames/arena/dropper/DropperPlayerEntryState.java b/src/main/java/net/knarcraft/minigames/arena/dropper/DropperPlayerEntryState.java index 9bec80a..48e764c 100644 --- a/src/main/java/net/knarcraft/minigames/arena/dropper/DropperPlayerEntryState.java +++ b/src/main/java/net/knarcraft/minigames/arena/dropper/DropperPlayerEntryState.java @@ -44,14 +44,15 @@ public class DropperPlayerEntryState extends AbstractPlayerEntryState { * @param originalIsSwimming

Whether the player was swimming before entering the arena

* @param originalFlySpeed

The fly-speed of the player before entering the arena

* @param horizontalVelocity

The horizontal velocity of the player before entering the arena

+ * @param originalCollideAble

Whether the player was collide-able before entering the arena

*/ public DropperPlayerEntryState(@NotNull UUID playerId, Location entryLocation, boolean originalIsFlying, GameMode originalGameMode, boolean originalAllowFlight, boolean originalInvulnerable, boolean originalIsSwimming, float originalFlySpeed, float horizontalVelocity, - DropperArenaGameMode arenaGameMode) { + DropperArenaGameMode arenaGameMode, boolean originalCollideAble) { super(playerId, entryLocation, originalIsFlying, originalGameMode, originalAllowFlight, - originalInvulnerable, originalIsSwimming); + originalInvulnerable, originalIsSwimming, originalCollideAble); this.originalFlySpeed = originalFlySpeed; this.horizontalVelocity = horizontalVelocity; this.arenaGameMode = arenaGameMode; @@ -111,18 +112,19 @@ public class DropperPlayerEntryState extends AbstractPlayerEntryState { public static DropperPlayerEntryState deserialize(Map data) { UUID playerId = ((SerializableUUID) data.get("playerId")).getRawValue(); Location entryLocation = (Location) data.get("entryLocation"); - boolean originalIsFlying = (boolean) data.get("originalIsFlying"); + boolean originalIsFlying = getBoolean(data, "originalIsFlying"); GameMode originalGameMode = GameMode.valueOf((String) data.get("originalGameMode")); - boolean originalAllowFlight = (boolean) data.get("originalAllowFlight"); - boolean originalInvulnerable = (boolean) data.get("originalInvulnerable"); - boolean originalIsSwimming = (boolean) data.get("originalIsSwimming"); + boolean originalAllowFlight = getBoolean(data, "originalAllowFlight"); + boolean originalInvulnerable = getBoolean(data, "originalInvulnerable"); + boolean originalIsSwimming = getBoolean(data, "originalIsSwimming"); float originalFlySpeed = ((Number) data.get("originalFlySpeed")).floatValue(); float horizontalVelocity = ((Number) data.get("horizontalVelocity")).floatValue(); DropperArenaGameMode arenaGameMode = (DropperArenaGameMode) data.get("arenaGameMode"); + boolean originalCollideAble = getBoolean(data, "originalCollideAble"); return new DropperPlayerEntryState(playerId, entryLocation, originalIsFlying, originalGameMode, originalAllowFlight, originalInvulnerable, originalIsSwimming, - originalFlySpeed, horizontalVelocity, arenaGameMode); + originalFlySpeed, horizontalVelocity, arenaGameMode, originalCollideAble); } } diff --git a/src/main/java/net/knarcraft/minigames/arena/parkour/ParkourPlayerEntryState.java b/src/main/java/net/knarcraft/minigames/arena/parkour/ParkourPlayerEntryState.java index cc9904c..fa00dff 100644 --- a/src/main/java/net/knarcraft/minigames/arena/parkour/ParkourPlayerEntryState.java +++ b/src/main/java/net/knarcraft/minigames/arena/parkour/ParkourPlayerEntryState.java @@ -34,12 +34,13 @@ public class ParkourPlayerEntryState extends AbstractPlayerEntryState { * @param originalAllowFlight

Whether the player was allowed flight before entering the arena

* @param originalInvulnerable

Whether the player was invulnerable before entering the arena

* @param originalIsSwimming

Whether the player was swimming before entering the arena

+ * @param originalCollideAble

Whether the player was collide-able before entering the arena

*/ public ParkourPlayerEntryState(@NotNull UUID playerId, Location entryLocation, boolean originalIsFlying, GameMode originalGameMode, boolean originalAllowFlight, - boolean originalInvulnerable, boolean originalIsSwimming) { + boolean originalInvulnerable, boolean originalIsSwimming, boolean originalCollideAble) { super(playerId, entryLocation, originalIsFlying, originalGameMode, originalAllowFlight, - originalInvulnerable, originalIsSwimming); + originalInvulnerable, originalIsSwimming, originalCollideAble); } @Override @@ -63,14 +64,15 @@ public class ParkourPlayerEntryState extends AbstractPlayerEntryState { public static ParkourPlayerEntryState deserialize(Map data) { UUID playerId = ((SerializableUUID) data.get("playerId")).getRawValue(); Location entryLocation = (Location) data.get("entryLocation"); - boolean originalIsFlying = (boolean) data.get("originalIsFlying"); + boolean originalIsFlying = getBoolean(data, "originalIsFlying"); GameMode originalGameMode = GameMode.valueOf((String) data.get("originalGameMode")); - boolean originalAllowFlight = (boolean) data.get("originalAllowFlight"); - boolean originalInvulnerable = (boolean) data.get("originalInvulnerable"); - boolean originalIsSwimming = (boolean) data.get("originalIsSwimming"); + boolean originalAllowFlight = getBoolean(data, "originalAllowFlight"); + boolean originalInvulnerable = getBoolean(data, "originalInvulnerable"); + boolean originalIsSwimming = getBoolean(data, "originalIsSwimming"); + boolean originalCollideAble = getBoolean(data, "originalCollideAble"); return new ParkourPlayerEntryState(playerId, entryLocation, originalIsFlying, - originalGameMode, originalAllowFlight, originalInvulnerable, originalIsSwimming); + originalGameMode, originalAllowFlight, originalInvulnerable, originalIsSwimming, originalCollideAble); } } diff --git a/src/main/java/net/knarcraft/minigames/command/dropper/JoinDropperArenaCommand.java b/src/main/java/net/knarcraft/minigames/command/dropper/JoinDropperArenaCommand.java index 192b569..320c4bc 100644 --- a/src/main/java/net/knarcraft/minigames/command/dropper/JoinDropperArenaCommand.java +++ b/src/main/java/net/knarcraft/minigames/command/dropper/JoinDropperArenaCommand.java @@ -91,6 +91,9 @@ public class JoinDropperArenaCommand implements CommandExecutor { ArenaPlayerRegistry playerRegistry = MiniGames.getInstance().getDropperArenaPlayerRegistry(); playerRegistry.registerPlayer(player.getUniqueId(), newSession); + // Update visibility and hit-box for the player + MiniGames.getInstance().getPlayerVisibilityManager().updateHiddenPlayers(playerRegistry, player); + // Try to teleport the player to the arena boolean teleported = PlayerTeleporter.teleportPlayer(player, specifiedArena.getSpawnLocation(), false, false); if (!teleported) { @@ -98,10 +101,9 @@ public class JoinDropperArenaCommand implements CommandExecutor { newSession.triggerQuit(false, true); return false; } else { - // Make sure to update the state again in the air to remove a potential swimming state + // Update the player's state to follow the arena's rules newSession.getEntryState().setArenaState(); - // Update visibility for the player - MiniGames.getInstance().getPlayerVisibilityManager().updateHiddenPlayers(playerRegistry, player); + player.getInventory().addItem(GUIHelper.getGUIOpenItem()); player.sendMessage(Message.SUCCESS_ARENA_JOINED.getMessage()); return true; diff --git a/src/main/java/net/knarcraft/minigames/command/parkour/JoinParkourArenaCommand.java b/src/main/java/net/knarcraft/minigames/command/parkour/JoinParkourArenaCommand.java index 2d78d1c..1d536db 100644 --- a/src/main/java/net/knarcraft/minigames/command/parkour/JoinParkourArenaCommand.java +++ b/src/main/java/net/knarcraft/minigames/command/parkour/JoinParkourArenaCommand.java @@ -89,6 +89,9 @@ public class JoinParkourArenaCommand implements CommandExecutor { ArenaPlayerRegistry playerRegistry = MiniGames.getInstance().getParkourArenaPlayerRegistry(); playerRegistry.registerPlayer(player.getUniqueId(), newSession); + // Update visibility and hit-box for the player + MiniGames.getInstance().getPlayerVisibilityManager().updateHiddenPlayers(playerRegistry, player); + // Try to teleport the player to the arena boolean teleported = PlayerTeleporter.teleportPlayer(player, specifiedArena.getSpawnLocation(), false, false); if (!teleported) { @@ -96,10 +99,9 @@ public class JoinParkourArenaCommand implements CommandExecutor { newSession.triggerQuit(false, true); return false; } else { - // Make sure to update the state again in the air to remove a potential swimming state + // Update the player's state to follow the arena's rules newSession.getEntryState().setArenaState(); - // Update visibility for the player - MiniGames.getInstance().getPlayerVisibilityManager().updateHiddenPlayers(playerRegistry, player); + player.getInventory().addItem(GUIHelper.getGUIOpenItem()); player.sendMessage(Message.SUCCESS_ARENA_JOINED.getMessage()); return true;