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/bukkit/BukkitWorldEditor.java b/src/main/java/net/tiagofar78/prisonescape/bukkit/BukkitWorldEditor.java index c68a8419..e6262585 100644 --- a/src/main/java/net/tiagofar78/prisonescape/bukkit/BukkitWorldEditor.java +++ b/src/main/java/net/tiagofar78/prisonescape/bukkit/BukkitWorldEditor.java @@ -8,9 +8,7 @@ import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; -import org.bukkit.block.Sign; import org.bukkit.block.data.type.Door; -import org.bukkit.block.sign.Side; import org.bukkit.entity.TNTPrimed; public class BukkitWorldEditor { @@ -21,35 +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()); - bukkitLocation.getBlock().setType(Material.OAK_WALL_SIGN); - Sign sign = (Sign) bukkitLocation.getBlock().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); - } - - 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..ab2f0855 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,23 @@ 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.managers.ConfigManager; 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 +25,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 +33,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 +138,48 @@ 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) { + ConfigManager config = ConfigManager.getInstance(); + + Directional rotatable = (Directional) block.getBlockData(); + rotatable.setFacing(BlockFace.valueOf(config.getVaultsDirection())); + 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); + } + } 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