From b0bb64181247a7f1c1a3dc091b17ad2bf149e644 Mon Sep 17 00:00:00 2001 From: TiagoFar78 Date: Fri, 10 May 2024 17:38:23 +0100 Subject: [PATCH 1/3] added rotation for vaults and their signs --- .../bukkit/BukkitWorldEditor.java | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/main/java/net/tiagofar78/prisonescape/bukkit/BukkitWorldEditor.java b/src/main/java/net/tiagofar78/prisonescape/bukkit/BukkitWorldEditor.java index c68a8419..522dcfcb 100644 --- a/src/main/java/net/tiagofar78/prisonescape/bukkit/BukkitWorldEditor.java +++ b/src/main/java/net/tiagofar78/prisonescape/bukkit/BukkitWorldEditor.java @@ -1,18 +1,20 @@ package net.tiagofar78.prisonescape.bukkit; -import net.tiagofar78.prisonescape.game.prisonbuilding.PrisonEscapeLocation; -import net.tiagofar78.prisonescape.managers.ConfigManager; - import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; import org.bukkit.block.Sign; +import org.bukkit.block.data.Directional; import org.bukkit.block.data.type.Door; import org.bukkit.block.sign.Side; import org.bukkit.entity.TNTPrimed; +import net.tiagofar78.prisonescape.game.prisonbuilding.PrisonEscapeLocation; +import net.tiagofar78.prisonescape.managers.ConfigManager; + public class BukkitWorldEditor { private static final World WORLD = Bukkit.getWorld(ConfigManager.getInstance().getWorldName()); @@ -29,8 +31,14 @@ public static World getWorld() { public static void addSignAboveVault(PrisonEscapeLocation location, String text) { Location bukkitLocation = new Location(WORLD, location.getX(), location.getY() + 1, location.getZ()); - bukkitLocation.getBlock().setType(Material.OAK_WALL_SIGN); - Sign sign = (Sign) bukkitLocation.getBlock().getState(); + Block block = bukkitLocation.getBlock(); + block.setType(Material.OAK_WALL_SIGN); + + Directional rotatable = (Directional) block.getBlockData(); + rotatable.setFacing(BlockFace.WEST); + block.setBlockData(rotatable); + + Sign sign = (Sign) block.getState(); sign.getSide(Side.FRONT).setLine(SIGN_INDEX, text); sign.update(); } @@ -40,6 +48,10 @@ public static void addVault(PrisonEscapeLocation location) { Block block = bukkitLocation.getBlock(); block.setType(Material.CHEST); + + Directional rotatable = (Directional) block.getBlockData(); + rotatable.setFacing(BlockFace.WEST); + block.setBlockData(rotatable); } public static void deleteVaultAndRespectiveSign(PrisonEscapeLocation location) { From 1629f3a8aefac08c1ab19112ca91a36f4fe8807c Mon Sep 17 00:00:00 2001 From: TiagoFar78 Date: Fri, 10 May 2024 18:03:37 +0100 Subject: [PATCH 2/3] code refactor --- .../bukkit/BukkitWorldEditor.java | 49 +------------- .../game/prisonbuilding/PrisonBuilding.java | 24 +++---- .../game/prisonbuilding/Vault.java | 67 ++++++++++++++++++- 3 files changed, 80 insertions(+), 60 deletions(-) diff --git a/src/main/java/net/tiagofar78/prisonescape/bukkit/BukkitWorldEditor.java b/src/main/java/net/tiagofar78/prisonescape/bukkit/BukkitWorldEditor.java index 522dcfcb..e6262585 100644 --- a/src/main/java/net/tiagofar78/prisonescape/bukkit/BukkitWorldEditor.java +++ b/src/main/java/net/tiagofar78/prisonescape/bukkit/BukkitWorldEditor.java @@ -1,20 +1,16 @@ package net.tiagofar78.prisonescape.bukkit; +import net.tiagofar78.prisonescape.game.prisonbuilding.PrisonEscapeLocation; +import net.tiagofar78.prisonescape.managers.ConfigManager; + import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.block.Sign; -import org.bukkit.block.data.Directional; import org.bukkit.block.data.type.Door; -import org.bukkit.block.sign.Side; import org.bukkit.entity.TNTPrimed; -import net.tiagofar78.prisonescape.game.prisonbuilding.PrisonEscapeLocation; -import net.tiagofar78.prisonescape.managers.ConfigManager; - public class BukkitWorldEditor { private static final World WORLD = Bukkit.getWorld(ConfigManager.getInstance().getWorldName()); @@ -23,45 +19,6 @@ public static World getWorld() { return WORLD; } -// ######################################### -// # Vault # -// ######################################### - - private static final int SIGN_INDEX = 1; - - public static void addSignAboveVault(PrisonEscapeLocation location, String text) { - Location bukkitLocation = new Location(WORLD, location.getX(), location.getY() + 1, location.getZ()); - Block block = bukkitLocation.getBlock(); - block.setType(Material.OAK_WALL_SIGN); - - Directional rotatable = (Directional) block.getBlockData(); - rotatable.setFacing(BlockFace.WEST); - block.setBlockData(rotatable); - - Sign sign = (Sign) block.getState(); - sign.getSide(Side.FRONT).setLine(SIGN_INDEX, text); - sign.update(); - } - - public static void addVault(PrisonEscapeLocation location) { - Location bukkitLocation = new Location(WORLD, location.getX(), location.getY(), location.getZ()); - - Block block = bukkitLocation.getBlock(); - block.setType(Material.CHEST); - - Directional rotatable = (Directional) block.getBlockData(); - rotatable.setFacing(BlockFace.WEST); - block.setBlockData(rotatable); - } - - public static void deleteVaultAndRespectiveSign(PrisonEscapeLocation location) { - Location vaultLocation = new Location(WORLD, location.getX(), location.getY(), location.getZ()); - Location signLocation = new Location(WORLD, location.getX(), location.getY() + 1, location.getZ()); - - vaultLocation.getBlock().setType(Material.AIR); - signLocation.getBlock().setType(Material.AIR); - } - // ######################################## // # Time # // ######################################## 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 aad52532..217bf97c 100644 --- a/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/PrisonBuilding.java +++ b/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/PrisonBuilding.java @@ -21,6 +21,8 @@ public class PrisonBuilding { private static final String PRISON_REGION_NAME = "PRISON"; + private PrisonEscapeLocation _reference; + private PrisonEscapeLocation _waitingLobbyLocation; private Region _prison; private List _regions; @@ -34,7 +36,6 @@ public class PrisonBuilding { private Hashtable _policeSecretPassageLocations; private List _vaults; - private List _vaultsLocations; private Hashtable _chests; private Hashtable _doors; @@ -53,6 +54,8 @@ public class PrisonBuilding { public PrisonBuilding(PrisonEscapeLocation reference) { ConfigManager config = ConfigManager.getInstance(); + _reference = reference; + PrisonEscapeLocation prisonUpperCorner = config.getPrisonUpperCornerLocation().add(reference); PrisonEscapeLocation prisonLowerCorner = config.getPrisonLowerCornerLocation().add(reference); _prison = new SquaredRegion(PRISON_REGION_NAME, false, true, prisonUpperCorner, prisonLowerCorner); @@ -74,7 +77,6 @@ public PrisonBuilding(PrisonEscapeLocation reference) { _policeSecretPassageLocations = createLocationsMap(reference, config.getPoliceSecretPassageLocations()); _vaults = new ArrayList<>(); - _vaultsLocations = createLocationsList(reference, config.getVaultsLocations()); _chests = new Hashtable<>(); for (PrisonEscapeLocation loc : config.getChestsLocations()) { @@ -232,13 +234,11 @@ public boolean checkIfMetalDetectorTriggered(PrisonEscapeLocation location, Pris // ######################################### public void addVaults(List prisioners) { - for (int i = 0; i < prisioners.size(); i++) { - _vaults.add(new Vault(prisioners.get(i))); + ConfigManager config = ConfigManager.getInstance(); + List vaultsLocations = createLocationsList(_reference, config.getVaultsLocations()); - String signText = prisioners.get(i).getName(); - PrisonEscapeLocation vaultLocation = _vaultsLocations.get(i); - BukkitWorldEditor.addSignAboveVault(vaultLocation, signText); - BukkitWorldEditor.addVault(vaultLocation); + for (int i = 0; i < prisioners.size(); i++) { + _vaults.add(new Vault(prisioners.get(i), vaultsLocations.get(i))); } } @@ -247,8 +247,8 @@ public Vault getVault(int index) { } public int getVaultIndex(PrisonEscapeLocation location) { - for (int i = 0; i < _vaultsLocations.size(); i++) { - if (_vaultsLocations.get(i).equals(location)) { + for (int i = 0; i < _vaults.size(); i++) { + if (_vaults.get(i).isIn(location)) { return i; } } @@ -257,8 +257,8 @@ public int getVaultIndex(PrisonEscapeLocation location) { } public void deleteVaults() { - for (PrisonEscapeLocation location : _vaultsLocations) { - BukkitWorldEditor.deleteVaultAndRespectiveSign(location); + for (Vault vault : _vaults) { + vault.deleteVaultAndRespectiveSignFromWorld(); } } diff --git a/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/Vault.java b/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/Vault.java index c89302c3..f486d20f 100644 --- a/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/Vault.java +++ b/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/Vault.java @@ -1,12 +1,22 @@ package net.tiagofar78.prisonescape.game.prisonbuilding; import net.tiagofar78.prisonescape.bukkit.BukkitMenu; +import net.tiagofar78.prisonescape.bukkit.BukkitWorldEditor; import net.tiagofar78.prisonescape.game.PrisonEscapePlayer; import net.tiagofar78.prisonescape.items.Item; import net.tiagofar78.prisonescape.items.NullItem; import net.tiagofar78.prisonescape.menus.ClickReturnAction; import net.tiagofar78.prisonescape.menus.Clickable; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.block.Sign; +import org.bukkit.block.data.Directional; +import org.bukkit.block.sign.Side; + import java.util.ArrayList; import java.util.List; @@ -14,6 +24,7 @@ public class Vault implements Clickable { private static final int NON_HIDDEN_SIZE = 4; private static final int HIDDEN_SIZE = 1; + private static final int SIGN_OWNER_NAME_LINE__INDEX = 1; private List _nonHiddenContents; private List _hiddenContents; @@ -21,12 +32,22 @@ public class Vault implements Clickable { private PrisonEscapePlayer _owner; - public Vault(PrisonEscapePlayer owner) { + private PrisonEscapeLocation _location; + + public Vault(PrisonEscapePlayer owner, PrisonEscapeLocation location) { _nonHiddenContents = createContentsList(NON_HIDDEN_SIZE); _hiddenContents = createContentsList(HIDDEN_SIZE); _isOpen = false; - this._owner = owner; + _owner = owner; + + _location = location; + createWorldVault(location); + createWorldSignAboveVault(location, _owner.getName()); + } + + public boolean isIn(PrisonEscapeLocation location) { + return _location.equals(location); } private List createContentsList(int size) { @@ -116,4 +137,46 @@ public ClickReturnAction click(PrisonEscapePlayer player, int slot, Item itemHel return ClickReturnAction.CHANGE_HOLD_AND_SELECTED; } +// ######################################### +// # World # +// ######################################### + + private void createWorldVault(PrisonEscapeLocation location) { + World world = BukkitWorldEditor.getWorld(); + Location bukkitLocation = new Location(world, location.getX(), location.getY(), location.getZ()); + + Block block = bukkitLocation.getBlock(); + block.setType(Material.CHEST); + + rotate(block); + } + + private void createWorldSignAboveVault(PrisonEscapeLocation location, String text) { + World world = BukkitWorldEditor.getWorld(); + Location bukkitLocation = new Location(world, location.getX(), location.getY() + 1, location.getZ()); + Block block = bukkitLocation.getBlock(); + block.setType(Material.OAK_WALL_SIGN); + + rotate(block); + + Sign sign = (Sign) block.getState(); + sign.getSide(Side.FRONT).setLine(SIGN_OWNER_NAME_LINE__INDEX, text); + sign.update(); + } + + private void rotate(Block block) { + Directional rotatable = (Directional) block.getBlockData(); + rotatable.setFacing(BlockFace.WEST); + block.setBlockData(rotatable); + } + + public void deleteVaultAndRespectiveSignFromWorld() { + World world = BukkitWorldEditor.getWorld(); + Location vaultLocation = new Location(world, _location.getX(), _location.getY(), _location.getZ()); + Location signLocation = new Location(world, _location.getX(), _location.getY() + 1, _location.getZ()); + + vaultLocation.getBlock().setType(Material.AIR); + signLocation.getBlock().setType(Material.AIR); + } + } From 8b6bf8963c28f086af1fc336ae5043b4dc0949d8 Mon Sep 17 00:00:00 2001 From: TiagoFar78 Date: Fri, 10 May 2024 18:15:37 +0100 Subject: [PATCH 3/3] added configurable direction --- TestServer/plugins/TF_PrisonEscape/config.yml | 1 + .../tiagofar78/prisonescape/game/prisonbuilding/Vault.java | 5 ++++- .../net/tiagofar78/prisonescape/managers/ConfigManager.java | 6 ++++++ src/main/resources/config.yml | 1 + 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/TestServer/plugins/TF_PrisonEscape/config.yml b/TestServer/plugins/TF_PrisonEscape/config.yml index bbc43fa2..b0d8f243 100644 --- a/TestServer/plugins/TF_PrisonEscape/config.yml +++ b/TestServer/plugins/TF_PrisonEscape/config.yml @@ -131,6 +131,7 @@ PoliceSecretPassagesLocation: X: 3 Y: 100 Z: 8 +VaultsDirection: "WEST" VaultsLocations: "1": X: 5 diff --git a/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/Vault.java b/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/Vault.java index f486d20f..ab2f0855 100644 --- a/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/Vault.java +++ b/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/Vault.java @@ -5,6 +5,7 @@ import net.tiagofar78.prisonescape.game.PrisonEscapePlayer; import net.tiagofar78.prisonescape.items.Item; import net.tiagofar78.prisonescape.items.NullItem; +import net.tiagofar78.prisonescape.managers.ConfigManager; import net.tiagofar78.prisonescape.menus.ClickReturnAction; import net.tiagofar78.prisonescape.menus.Clickable; @@ -165,8 +166,10 @@ private void createWorldSignAboveVault(PrisonEscapeLocation location, String tex } private void rotate(Block block) { + ConfigManager config = ConfigManager.getInstance(); + Directional rotatable = (Directional) block.getBlockData(); - rotatable.setFacing(BlockFace.WEST); + rotatable.setFacing(BlockFace.valueOf(config.getVaultsDirection())); block.setBlockData(rotatable); } diff --git a/src/main/java/net/tiagofar78/prisonescape/managers/ConfigManager.java b/src/main/java/net/tiagofar78/prisonescape/managers/ConfigManager.java index 716f0a1c..8741fab6 100644 --- a/src/main/java/net/tiagofar78/prisonescape/managers/ConfigManager.java +++ b/src/main/java/net/tiagofar78/prisonescape/managers/ConfigManager.java @@ -71,6 +71,7 @@ public static ConfigManager getInstance() { private Hashtable _prisionersSecretPassageLocations; private Hashtable _policeSecretPassageLocations; private List _vaultsLocations; + private String _vaultsDirection; private List _chestsLocations; private List _goldenDoorsLocations; private List _grayDoorsLocations; @@ -143,6 +144,7 @@ public ConfigManager() { _prisionersSecretPassageLocations = createLocationsMap(config, "PrisionersSecretPassagesLocation"); _policeSecretPassageLocations = createLocationsMap(config, "PoliceSecretPassagesLocation"); _vaultsLocations = createLocationList(config, "VaultsLocations"); + _vaultsDirection = config.getString("VaultsDirection"); _chestsLocations = createLocationList(config, "ChestsLocations"); _goldenDoorsLocations = createLocationList(config, "GoldenDoorsLocations"); _grayDoorsLocations = createLocationList(config, "GrayDoorsLocations"); @@ -489,6 +491,10 @@ public List getVaultsLocations() { return createLocationsListCopy(_vaultsLocations); } + public String getVaultsDirection() { + return _vaultsDirection; + } + public List getChestsLocations() { return createLocationsListCopy(_chestsLocations); } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index f2e79d7f..2d7528bc 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -94,6 +94,7 @@ PoliceSecretPassagesLocation: X: 0 Y: 0 Z: 0 +VaultsDirection: "NORTH" VaultsLocations: "1": X: 0