From 6d7f07ebe81d9e4db2a3c2eb4ccce889398a6197 Mon Sep 17 00:00:00 2001 From: TheKingElessar Date: Wed, 8 Sep 2021 22:24:06 -0600 Subject: [PATCH] Keep players from going to the wrong side Took 27 minutes --- README.md | 13 +--- .../playermovement/PlayerMoveHandler.java | 59 ++++++++++++++++++- .../assault/game/player/GamePlayer.java | 2 +- .../assault/game/world/map/Map.java | 11 ++++ src/main/resources/maps/map_saloon.yml | 2 + 5 files changed, 72 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 3892ed4..3255a65 100644 --- a/README.md +++ b/README.md @@ -2,24 +2,13 @@ ### Bugs +- Bugs probably exist surrounding the FT5S mode, especially with ties - can still get over wall barriers - `NullPointerException` with `GamePlayer` when leave and rejoin - Citizens NPCs aren't deleted properly, so they stick around in Citizens' config ### Features -### Modifier: First to Five Stars - -- ~~Make new modifier~~ -- ~~Keep track of times picked up~~ -- ~~Update scoreboard with times picked up~~ -- ~~On item pickup, don't end until counter reaches 5~~ -- ~~If time ends and counter not at 5, winning team is the one with the most stars~~ -- ~~Different 480 time when enabled~~ -- Test (especially ties) - -### Other - - Multiverse support - Package maps with plugin - Add more game modifiers: diff --git a/src/main/java/com/thekingelessar/assault/game/eventhandlers/playermovement/PlayerMoveHandler.java b/src/main/java/com/thekingelessar/assault/game/eventhandlers/playermovement/PlayerMoveHandler.java index 04e980f..400a45a 100644 --- a/src/main/java/com/thekingelessar/assault/game/eventhandlers/playermovement/PlayerMoveHandler.java +++ b/src/main/java/com/thekingelessar/assault/game/eventhandlers/playermovement/PlayerMoveHandler.java @@ -3,11 +3,11 @@ import com.thekingelessar.assault.Assault; import com.thekingelessar.assault.game.GameInstance; import com.thekingelessar.assault.game.GameStage; -import com.thekingelessar.assault.game.world.map.MapBase; import com.thekingelessar.assault.game.player.DeathType; import com.thekingelessar.assault.game.player.GamePlayer; import com.thekingelessar.assault.game.player.PlayerMode; import com.thekingelessar.assault.game.team.GameTeam; +import com.thekingelessar.assault.game.world.map.MapBase; import org.bukkit.Location; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -103,8 +103,63 @@ else if ((System.nanoTime() - gamePlayer.startTimeInAir) / 1000000000. > 5) if (voidY < gameInstance.gameMap.voidLevel && gameInstance.gameMap.voidEnabled) { GamePlayer gamePlayer = gameInstance.getGamePlayer(player); - gamePlayer.respawn(null, true, DeathType.VOID); + if (gamePlayer != null) + { + gamePlayer.respawn(null, true, DeathType.VOID); + } + } + + if (gameInstance.gameStage.equals(GameStage.PREGAME)) + { + return; + } + + if (gameInstance.gameStage.equals(GameStage.BUILDING)) + { + GamePlayer gamePlayer = gameInstance.getGamePlayer(player); + if (gamePlayer != null) + { + if (newLocation.getX() > gameInstance.gameMap.borderX && gamePlayer.gameTeam.mapBase.objective.x < gameInstance.gameMap.borderX) + { + cancelMovement(playerMoveEvent); + + player.sendMessage(Assault.ASSAULT_PREFIX + "You can't go over here!"); + return; + } + + if (newLocation.getX() < gameInstance.gameMap.borderX && gamePlayer.gameTeam.mapBase.objective.x > gameInstance.gameMap.borderX) + { + cancelMovement(playerMoveEvent); + + player.sendMessage(Assault.ASSAULT_PREFIX + "You can't go over here!"); + return; + } + } + + return; + } + + if (newLocation.getX() > gameInstance.gameMap.borderX && gameInstance.getDefendingTeam().mapBase.objective.x < gameInstance.gameMap.borderX) + { + player.sendMessage(Assault.ASSAULT_PREFIX + "You can't go over here!"); + GamePlayer gamePlayer = gameInstance.getGamePlayer(player); + if (gamePlayer != null) + { + cancelMovement(playerMoveEvent); + return; + } + } + + if (newLocation.getX() < gameInstance.gameMap.borderX && gameInstance.getDefendingTeam().mapBase.objective.x > gameInstance.gameMap.borderX) + { + player.sendMessage(Assault.ASSAULT_PREFIX + "You can't go over here!"); + GamePlayer gamePlayer = gameInstance.getGamePlayer(player); + if (gamePlayer != null) + { + cancelMovement(playerMoveEvent); + } } + } private void cancelMovement(PlayerMoveEvent playerMoveEvent) diff --git a/src/main/java/com/thekingelessar/assault/game/player/GamePlayer.java b/src/main/java/com/thekingelessar/assault/game/player/GamePlayer.java index 371e05b..9aa2c7b 100644 --- a/src/main/java/com/thekingelessar/assault/game/player/GamePlayer.java +++ b/src/main/java/com/thekingelessar/assault/game/player/GamePlayer.java @@ -99,7 +99,7 @@ public void addSpawnItem(ItemStack spawnItem) spawnItems.add(spawnItem); } - public void spawn(PlayerMode playerMode, boolean keepInventory) + public void spawn(PlayerMode playerMode, boolean keepInventory) // keepInventory and checking if GameStage is BUILDING is a little redundant { GameTeam playerTeam = gameInstance.getPlayerTeam(player); PlayerMode mode = PlayerMode.setPlayerMode(player, playerMode, gameInstance); diff --git a/src/main/java/com/thekingelessar/assault/game/world/map/Map.java b/src/main/java/com/thekingelessar/assault/game/world/map/Map.java index 8ae8e94..060f8f1 100644 --- a/src/main/java/com/thekingelessar/assault/game/world/map/Map.java +++ b/src/main/java/com/thekingelessar/assault/game/world/map/Map.java @@ -31,6 +31,8 @@ public class Map public int attackTimeLimit = 480; public int firstToFiveStarsTimeLimit = 480; + public double borderX = 0; + public double maxZ = 86; public double minZ = 2; @@ -132,6 +134,15 @@ public Map(YamlConfiguration config) Assault.INSTANCE.getLogger().log(Level.WARNING, "first_to_five_stars_time_limit invalid; defaulting to 480"); } + try + { + borderX = config.getDouble("border_x"); + } + catch (Exception exception) + { + Assault.INSTANCE.getLogger().log(Level.WARNING, "border_x invalid; defaulting to 0"); + } + try { maxZ = config.getDouble("max_z"); diff --git a/src/main/resources/maps/map_saloon.yml b/src/main/resources/maps/map_saloon.yml index 5b28ba7..8c1e712 100644 --- a/src/main/resources/maps/map_saloon.yml +++ b/src/main/resources/maps/map_saloon.yml @@ -14,6 +14,8 @@ building_coins: 100 attack_time_limit: 480 first_to_five_stars_time_limit: 480 +border_x: 0 + max_z: 86. min_z: 2.