From fa0f008409fd9f40db25d8478c57c0fb0979c0dd Mon Sep 17 00:00:00 2001 From: TiagoFar78 Date: Fri, 14 Jun 2024 14:50:29 +0100 Subject: [PATCH 1/5] fixed bomb item not being consumed --- .../java/net/tiagofar78/prisonescape/items/BombItem.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/tiagofar78/prisonescape/items/BombItem.java b/src/main/java/net/tiagofar78/prisonescape/items/BombItem.java index 5b581f35..dcb5009e 100644 --- a/src/main/java/net/tiagofar78/prisonescape/items/BombItem.java +++ b/src/main/java/net/tiagofar78/prisonescape/items/BombItem.java @@ -1,11 +1,13 @@ package net.tiagofar78.prisonescape.items; +import net.tiagofar78.prisonescape.game.PEGame; import net.tiagofar78.prisonescape.managers.GameManager; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerInteractEvent; import java.util.ArrayList; @@ -35,8 +37,12 @@ public void use(PlayerInteractEvent e) { return; } + PEGame game = GameManager.getGame(); Location blockLoc = getPlacedBlockLocation(block.getLocation(), e.getBlockFace()); - GameManager.getGame().placeBomb(blockLoc); + game.placeBomb(blockLoc); + + Player player = e.getPlayer(); + game.getPEPlayer(player.getName()).removeItem(player.getInventory().getHeldItemSlot()); } private Location getPlacedBlockLocation(Location blockLocation, BlockFace face) { From 58a30fe7a55e81937b050c020e7028c1ee6ac870 Mon Sep 17 00:00:00 2001 From: TiagoFar78 Date: Fri, 14 Jun 2024 14:55:15 +0100 Subject: [PATCH 2/5] fixed bug where players could play with external potion effects --- .../java/net/tiagofar78/prisonescape/game/PEGame.java | 1 + .../net/tiagofar78/prisonescape/game/PEPlayer.java | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/src/main/java/net/tiagofar78/prisonescape/game/PEGame.java b/src/main/java/net/tiagofar78/prisonescape/game/PEGame.java index cccbcb9b..ec5ae0cd 100644 --- a/src/main/java/net/tiagofar78/prisonescape/game/PEGame.java +++ b/src/main/java/net/tiagofar78/prisonescape/game/PEGame.java @@ -118,6 +118,7 @@ public int playerJoin(String playerName) { BukkitTeleporter.teleport(player, _prison.getWaitingLobbyLocation()); player.setKit(new TeamSelectorKit()); + player.clearEffects(); int maxPlayers = config.getMaxPlayers(); int playerNumber = _playersOnLobby.size(); diff --git a/src/main/java/net/tiagofar78/prisonescape/game/PEPlayer.java b/src/main/java/net/tiagofar78/prisonescape/game/PEPlayer.java index 8e57e97f..76671049 100644 --- a/src/main/java/net/tiagofar78/prisonescape/game/PEPlayer.java +++ b/src/main/java/net/tiagofar78/prisonescape/game/PEPlayer.java @@ -369,6 +369,17 @@ public void setEffect(PotionEffectType effect, int seconds, int level) { player.addPotionEffect(new PotionEffect(effect, ticksDuration, level)); } + public void clearEffects() { + Player player = Bukkit.getPlayer(getName()); + if (player == null || !player.isOnline()) { + return; + } + + for (PotionEffect effect : player.getActivePotionEffects()) { + player.removePotionEffect(effect.getType()); + } + } + private void setItemBukkit(int index, Item item) { Player bukkitPlayer = Bukkit.getPlayer(getName()); if (bukkitPlayer == null || !bukkitPlayer.isOnline()) { From 7803c9f3300dd6e2f9181300eb7b11bdbd5d1ff7 Mon Sep 17 00:00:00 2001 From: TiagoFar78 Date: Fri, 14 Jun 2024 14:59:27 +0100 Subject: [PATCH 3/5] fixed bug where doors were not starting the game closed --- .../prisonescape/game/prisonbuilding/PrisonBuilding.java | 6 +++--- .../prisonescape/game/prisonbuilding/doors/CellDoor.java | 1 + .../prisonescape/game/prisonbuilding/doors/CodeDoor.java | 6 ++++-- .../prisonescape/game/prisonbuilding/doors/Door.java | 4 ++-- .../prisonescape/game/prisonbuilding/doors/GoldenDoor.java | 6 ++++-- .../prisonescape/game/prisonbuilding/doors/GrayDoor.java | 6 ++++++ 6 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/PrisonBuilding.java b/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/PrisonBuilding.java index b4c66783..6c193e29 100644 --- a/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/PrisonBuilding.java +++ b/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/PrisonBuilding.java @@ -100,19 +100,19 @@ public PrisonBuilding(Location reference) { _doors = new Hashtable<>(); for (Location loc : config.getGoldenDoorsLocations()) { Location referenceLoc = loc.add(reference); - GoldenDoor goldenDoor = new GoldenDoor(); + GoldenDoor goldenDoor = new GoldenDoor(referenceLoc); _doors.put(referenceLoc, goldenDoor); _doors.put(referenceLoc.clone().add(0, 1, 0), goldenDoor); } for (Location loc : config.getGrayDoorsLocations()) { Location referenceLoc = loc.add(reference); - GrayDoor grayDoor = new GrayDoor(); + GrayDoor grayDoor = new GrayDoor(referenceLoc); _doors.put(referenceLoc, grayDoor); _doors.put(referenceLoc.clone().add(0, 1, 0), grayDoor); } for (Location loc : config.getCodeDoorsLocations()) { Location referenceLoc = loc.add(reference); - CodeDoor codeDoor = new CodeDoor(); + CodeDoor codeDoor = new CodeDoor(referenceLoc); _doors.put(referenceLoc, codeDoor); _doors.put(referenceLoc.clone().add(0, 1, 0), codeDoor); } diff --git a/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/doors/CellDoor.java b/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/doors/CellDoor.java index 4e2b732e..fd63f602 100644 --- a/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/doors/CellDoor.java +++ b/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/doors/CellDoor.java @@ -10,6 +10,7 @@ public class CellDoor extends Door { private Location _location; public CellDoor(Location location) { + super(location); _location = location; } diff --git a/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/doors/CodeDoor.java b/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/doors/CodeDoor.java index 2eb2dcae..9fd15822 100644 --- a/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/doors/CodeDoor.java +++ b/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/doors/CodeDoor.java @@ -5,10 +5,12 @@ import net.tiagofar78.prisonescape.items.Item; import net.tiagofar78.prisonescape.managers.GameManager; +import org.bukkit.Location; + public class CodeDoor extends Door { - public CodeDoor() { - super(); + public CodeDoor(Location location) { + super(location); } public ClickDoorReturnAction click(PEPlayer player, Item itemHeld) { diff --git a/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/doors/Door.java b/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/doors/Door.java index 1d7ea732..9614a46d 100644 --- a/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/doors/Door.java +++ b/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/doors/Door.java @@ -11,8 +11,8 @@ public abstract class Door { private boolean _isOpen; - public Door() { - _isOpen = false; + public Door(Location location) { + close(location); } public boolean isOpened() { diff --git a/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/doors/GoldenDoor.java b/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/doors/GoldenDoor.java index fe44c983..533cd94a 100644 --- a/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/doors/GoldenDoor.java +++ b/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/doors/GoldenDoor.java @@ -6,10 +6,12 @@ import net.tiagofar78.prisonescape.items.Item; import net.tiagofar78.prisonescape.managers.GameManager; +import org.bukkit.Location; + public class GoldenDoor extends Door { - public GoldenDoor() { - super(); + public GoldenDoor(Location location) { + super(location); } public ClickDoorReturnAction click(PEPlayer player, Item itemHeld) { diff --git a/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/doors/GrayDoor.java b/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/doors/GrayDoor.java index 6e2fab3d..16da4da5 100644 --- a/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/doors/GrayDoor.java +++ b/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/doors/GrayDoor.java @@ -6,8 +6,14 @@ import net.tiagofar78.prisonescape.items.Item; import net.tiagofar78.prisonescape.managers.GameManager; +import org.bukkit.Location; + public class GrayDoor extends Door { + public GrayDoor(Location location) { + super(location); + } + public ClickDoorReturnAction click(PEPlayer player, Item itemHeld) { PEGame game = GameManager.getGame(); boolean isOpened = isOpened(); From 131aa66c7f319043d0e524050b0f86690090c716 Mon Sep 17 00:00:00 2001 From: TiagoFar78 Date: Fri, 14 Jun 2024 15:08:30 +0100 Subject: [PATCH 4/5] fixed bug where disable function was called twice --- .../tiagofar78/prisonescape/game/PEGame.java | 7 +++++ .../prisonescape/game/phases/Disabled.java | 30 +++++++++++++++++++ .../prisonescape/game/phases/Finished.java | 7 ++++- .../prisonescape/game/phases/Ongoing.java | 5 ++++ .../prisonescape/game/phases/Phase.java | 2 ++ .../prisonescape/game/phases/Waiting.java | 5 ++++ 6 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 src/main/java/net/tiagofar78/prisonescape/game/phases/Disabled.java diff --git a/src/main/java/net/tiagofar78/prisonescape/game/PEGame.java b/src/main/java/net/tiagofar78/prisonescape/game/PEGame.java index ec5ae0cd..dc9ee490 100644 --- a/src/main/java/net/tiagofar78/prisonescape/game/PEGame.java +++ b/src/main/java/net/tiagofar78/prisonescape/game/PEGame.java @@ -5,6 +5,7 @@ import net.tiagofar78.prisonescape.bukkit.BukkitSoundBoard; import net.tiagofar78.prisonescape.bukkit.BukkitTeleporter; import net.tiagofar78.prisonescape.bukkit.BukkitWorldEditor; +import net.tiagofar78.prisonescape.game.phases.Disabled; import net.tiagofar78.prisonescape.game.phases.Finished; import net.tiagofar78.prisonescape.game.phases.Phase; import net.tiagofar78.prisonescape.game.phases.Waiting; @@ -418,6 +419,12 @@ public void run() { } private void disableGame() { + if (_phase.isGameDisabled()) { + return; + } + + _phase = new Disabled(); + for (PEPlayer player : _playersOnLobby) { teleportToLeavingLocation(player); player.removeScoreboard(); diff --git a/src/main/java/net/tiagofar78/prisonescape/game/phases/Disabled.java b/src/main/java/net/tiagofar78/prisonescape/game/phases/Disabled.java new file mode 100644 index 00000000..6f21377d --- /dev/null +++ b/src/main/java/net/tiagofar78/prisonescape/game/phases/Disabled.java @@ -0,0 +1,30 @@ +package net.tiagofar78.prisonescape.game.phases; + +public class Disabled extends Phase { + + @Override + public Phase next() { + return null; + } + + @Override + public boolean isClockStopped() { + return true; + } + + @Override + public boolean hasGameStarted() { + return true; + } + + @Override + public boolean hasGameEnded() { + return true; + } + + @Override + public boolean isGameDisabled() { + return true; + } + +} diff --git a/src/main/java/net/tiagofar78/prisonescape/game/phases/Finished.java b/src/main/java/net/tiagofar78/prisonescape/game/phases/Finished.java index e80eadc8..b24a302f 100644 --- a/src/main/java/net/tiagofar78/prisonescape/game/phases/Finished.java +++ b/src/main/java/net/tiagofar78/prisonescape/game/phases/Finished.java @@ -4,7 +4,7 @@ public class Finished extends Phase { @Override public Phase next() { - return null; + return new Disabled(); } @Override @@ -21,4 +21,9 @@ public boolean hasGameStarted() { public boolean hasGameEnded() { return true; } + + @Override + public boolean isGameDisabled() { + return false; + } } diff --git a/src/main/java/net/tiagofar78/prisonescape/game/phases/Ongoing.java b/src/main/java/net/tiagofar78/prisonescape/game/phases/Ongoing.java index 80cd29d8..d866f7fc 100644 --- a/src/main/java/net/tiagofar78/prisonescape/game/phases/Ongoing.java +++ b/src/main/java/net/tiagofar78/prisonescape/game/phases/Ongoing.java @@ -21,4 +21,9 @@ public boolean hasGameStarted() { public boolean hasGameEnded() { return false; } + + @Override + public boolean isGameDisabled() { + return false; + } } diff --git a/src/main/java/net/tiagofar78/prisonescape/game/phases/Phase.java b/src/main/java/net/tiagofar78/prisonescape/game/phases/Phase.java index a2b6a1ae..6f1833ee 100644 --- a/src/main/java/net/tiagofar78/prisonescape/game/phases/Phase.java +++ b/src/main/java/net/tiagofar78/prisonescape/game/phases/Phase.java @@ -10,4 +10,6 @@ public abstract class Phase { public abstract boolean hasGameEnded(); + public abstract boolean isGameDisabled(); + } diff --git a/src/main/java/net/tiagofar78/prisonescape/game/phases/Waiting.java b/src/main/java/net/tiagofar78/prisonescape/game/phases/Waiting.java index 5d119a92..0bbef6a9 100644 --- a/src/main/java/net/tiagofar78/prisonescape/game/phases/Waiting.java +++ b/src/main/java/net/tiagofar78/prisonescape/game/phases/Waiting.java @@ -21,4 +21,9 @@ public boolean hasGameStarted() { public boolean hasGameEnded() { return false; } + + @Override + public boolean isGameDisabled() { + return false; + } } From 42ab04a982bf564df8386a9535619d13ed2e35e2 Mon Sep 17 00:00:00 2001 From: TiagoFar78 Date: Fri, 14 Jun 2024 15:25:02 +0100 Subject: [PATCH 5/5] changed GoldenKeyItem representation --- .../java/net/tiagofar78/prisonescape/items/GoldenKeyItem.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/tiagofar78/prisonescape/items/GoldenKeyItem.java b/src/main/java/net/tiagofar78/prisonescape/items/GoldenKeyItem.java index 98166763..be7e3f5a 100644 --- a/src/main/java/net/tiagofar78/prisonescape/items/GoldenKeyItem.java +++ b/src/main/java/net/tiagofar78/prisonescape/items/GoldenKeyItem.java @@ -19,7 +19,7 @@ public boolean isIllegal() { @Override public Material getMaterial() { - return Material.TORCH; + return Material.BLAZE_ROD; } @Override