From ba12143cdd36a882d4d14ee7fdea9f7ec65975ce Mon Sep 17 00:00:00 2001 From: TiagoFar78 Date: Wed, 12 Jun 2024 12:42:50 +0100 Subject: [PATCH 01/10] Fixed vault being overwritten by sign Closes #245 --- .../net/tiagofar78/prisonescape/game/prisonbuilding/Vault.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 8eb7397d..1bfdc7db 100644 --- a/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/Vault.java +++ b/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/Vault.java @@ -156,7 +156,7 @@ private void createWorldVault(Location location) { } private void createWorldSignAboveVault(Location location, String text) { - Block block = location.getBlock(); + Block block = location.clone().add(0, 1, 0).getBlock(); block.setType(Material.OAK_WALL_SIGN); rotate(block); From 17811989e1098e7e856ec4d8fe5599d955ca9a04 Mon Sep 17 00:00:00 2001 From: TiagoFar78 Date: Wed, 12 Jun 2024 12:54:28 +0100 Subject: [PATCH 02/10] fixed buggy teleport to underground --- TestServer/plugins/TF_PrisonEscape/config.yml | 8 ++++---- .../tiagofar78/prisonescape/bukkit/BukkitTeleporter.java | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/TestServer/plugins/TF_PrisonEscape/config.yml b/TestServer/plugins/TF_PrisonEscape/config.yml index 8324fb0c..fd3e372c 100644 --- a/TestServer/plugins/TF_PrisonEscape/config.yml +++ b/TestServer/plugins/TF_PrisonEscape/config.yml @@ -141,7 +141,7 @@ PrisonersSecretPassagesLocation: Z: 8 Value: X: 0 - Y: 83 + Y: 82 Z: 5 "2": Key: @@ -150,7 +150,7 @@ PrisonersSecretPassagesLocation: Z: 2 Value: X: 0 - Y: 83 + Y: 82 Z: 0 "3": Key: @@ -159,7 +159,7 @@ PrisonersSecretPassagesLocation: Z: -4 Value: X: 0 - Y: 83 + Y: 82 Z: -5 "4": Key: @@ -168,7 +168,7 @@ PrisonersSecretPassagesLocation: Z: -10 Value: X: 0 - Y: 83 + Y: 82 Z: -10 "5": Key: diff --git a/src/main/java/net/tiagofar78/prisonescape/bukkit/BukkitTeleporter.java b/src/main/java/net/tiagofar78/prisonescape/bukkit/BukkitTeleporter.java index 316f0343..b4e67bde 100644 --- a/src/main/java/net/tiagofar78/prisonescape/bukkit/BukkitTeleporter.java +++ b/src/main/java/net/tiagofar78/prisonescape/bukkit/BukkitTeleporter.java @@ -16,7 +16,7 @@ public static void teleport(PEPlayer player, Location loc) { return; } - bukkitPlayer.teleport(loc.add(0, CENTER_OF_BLOCK, 0)); + bukkitPlayer.teleport(loc.clone().add(CENTER_OF_BLOCK, 0, CENTER_OF_BLOCK)); } } From f1a854c311ef89f09911dde12bb9b3630ac11c5a Mon Sep 17 00:00:00 2001 From: TiagoFar78 Date: Wed, 12 Jun 2024 12:58:58 +0100 Subject: [PATCH 03/10] fixed bug where goldbar was not obtainable --- TestServer/plugins/TF_PrisonEscape/config.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/TestServer/plugins/TF_PrisonEscape/config.yml b/TestServer/plugins/TF_PrisonEscape/config.yml index fd3e372c..ef4e7319 100644 --- a/TestServer/plugins/TF_PrisonEscape/config.yml +++ b/TestServer/plugins/TF_PrisonEscape/config.yml @@ -1256,6 +1256,7 @@ ChestsContents: Stick: 0.005 PlasticPlate: 0.01 Copper: 0.01 + GoldBar: 0.01 Battery: 0.005 NotePart: 0.01 EnergyDrink: 0.1 @@ -1269,6 +1270,7 @@ ChestsContents: Stick: 0.005 PlasticPlate: 0.01 Copper: 0.01 + GoldBar: 0.01 Battery: 0.005 NotePart: 0.01 EnergyDrink: 0.1 @@ -1282,6 +1284,7 @@ ChestsContents: Stick: 0.005 PlasticPlate: 0.01 Copper: 0.05 + GoldBar: 0.03 Antena: 0.025 Battery: 0.025 NotePart: 0.05 @@ -1299,6 +1302,7 @@ ChestsContents: Stick: 0.025 PlasticPlate: 0.01 Copper: 0.01 + GoldBar: 0.01 Battery: 0.005 NotePart: 0.01 EnergyDrink: 0.1 @@ -1313,6 +1317,7 @@ ChestsContents: PlasticPlate: 0.05 MetalPlate: 0.01 Copper: 0.01 + GoldBar: 0.01 Battery: 0.005 NotePart: 0.01 EnergyDrink: 0.1 @@ -1328,6 +1333,7 @@ ChestsContents: PlasticPlate: 0.1 MetalPlate: 0.01 Copper: 0.01 + GoldBar: 0.01 Battery: 0.005 NotePart: 0.01 EnergyDrink: 0.1 @@ -1341,6 +1347,7 @@ ChestsContents: Stick: 0.005 PlasticPlate: 0.01 Copper: 0.01 + GoldBar: 0.01 Battery: 0.005 NotePart: 0.01 EnergyDrink: 0.1 From e0a4607564493d66132047996814ba3e4bf7fa80 Mon Sep 17 00:00:00 2001 From: TiagoFar78 Date: Wed, 12 Jun 2024 13:17:49 +0100 Subject: [PATCH 04/10] added functionality to DoorCodeItem --- .../TF_PrisonEscape/languages/english.yml | 1 + .../tiagofar78/prisonescape/game/PEGame.java | 4 ++++ .../game/prisonbuilding/doors/CodeDoor.java | 11 +++++++-- .../prisonescape/items/DoorCodeItem.java | 24 ++++++++++++++++++- .../managers/MessageLanguageManager.java | 6 +++++ src/main/resources/languages/english.yml | 1 + 6 files changed, 44 insertions(+), 3 deletions(-) diff --git a/TestServer/plugins/TF_PrisonEscape/languages/english.yml b/TestServer/plugins/TF_PrisonEscape/languages/english.yml index 98bd0b82..0357e8a0 100644 --- a/TestServer/plugins/TF_PrisonEscape/languages/english.yml +++ b/TestServer/plugins/TF_PrisonEscape/languages/english.yml @@ -159,6 +159,7 @@ Messages: TradeAlreadyAccepted: "&aYou already accepted the trade, wait for your friend to accept." TradeRequestSent: "&eTrade request sent to &b{PLAYER}&e." TradeRequestReceived: "&eYou received a trade request. Shift+Click &b{PLAYER} &eto accept. You have &b{TIME} seconds" + CodeFound: "&eSomeone found the main door code." Announcements: GameStarting: - "&6===================================" diff --git a/src/main/java/net/tiagofar78/prisonescape/game/PEGame.java b/src/main/java/net/tiagofar78/prisonescape/game/PEGame.java index 935ed991..e25726a7 100644 --- a/src/main/java/net/tiagofar78/prisonescape/game/PEGame.java +++ b/src/main/java/net/tiagofar78/prisonescape/game/PEGame.java @@ -1207,4 +1207,8 @@ public void findDoorCode() { _hasDoorCode = true; } + public void changeDoorCode() { + _hasDoorCode = false; + } + } 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 dd1caf55..2eb2dcae 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 @@ -15,8 +15,15 @@ public ClickDoorReturnAction click(PEPlayer player, Item itemHeld) { PEGame game = GameManager.getGame(); boolean isOpened = isOpened(); - if (game.isGuard(player)) - return isOpened ? ClickDoorReturnAction.CLOSE_DOOR : ClickDoorReturnAction.NOTHING; + if (game.isGuard(player)) { + if (isOpened) { + game.changeDoorCode(); + return ClickDoorReturnAction.CLOSE_DOOR; + } + + return ClickDoorReturnAction.NOTHING; + } + if (game.isPrisoner(player)) return !isOpened && game.playersHaveDoorCode() diff --git a/src/main/java/net/tiagofar78/prisonescape/items/DoorCodeItem.java b/src/main/java/net/tiagofar78/prisonescape/items/DoorCodeItem.java index a5a1c6c5..df97d025 100644 --- a/src/main/java/net/tiagofar78/prisonescape/items/DoorCodeItem.java +++ b/src/main/java/net/tiagofar78/prisonescape/items/DoorCodeItem.java @@ -1,8 +1,15 @@ package net.tiagofar78.prisonescape.items; +import net.tiagofar78.prisonescape.bukkit.BukkitMessageSender; +import net.tiagofar78.prisonescape.game.PEGame; +import net.tiagofar78.prisonescape.game.Prisoner; +import net.tiagofar78.prisonescape.managers.GameManager; +import net.tiagofar78.prisonescape.managers.MessageLanguageManager; + import org.bukkit.Material; +import org.bukkit.event.player.PlayerInteractEvent; -public class DoorCodeItem extends Item { +public class DoorCodeItem extends FunctionalItem { @Override public boolean isMetalic() { @@ -19,4 +26,19 @@ public Material getMaterial() { return Material.FILLED_MAP; } + @Override + public void use(PlayerInteractEvent e) { + PEGame game = GameManager.getGame(); + + game.findDoorCode(); + + String playerName = e.getPlayer().getName(); + game.getPEPlayer(playerName).removeItem(e.getPlayer().getInventory().getHeldItemSlot()); + + for (Prisoner prisoner : game.getPrisonerTeam().getMembers()) { + MessageLanguageManager messages = MessageLanguageManager.getInstanceByPlayer(prisoner.getName()); + BukkitMessageSender.sendChatMessage(prisoner, messages.getCodeFoundMessage()); + } + } + } diff --git a/src/main/java/net/tiagofar78/prisonescape/managers/MessageLanguageManager.java b/src/main/java/net/tiagofar78/prisonescape/managers/MessageLanguageManager.java index e7fc782b..b22f10b2 100644 --- a/src/main/java/net/tiagofar78/prisonescape/managers/MessageLanguageManager.java +++ b/src/main/java/net/tiagofar78/prisonescape/managers/MessageLanguageManager.java @@ -145,6 +145,7 @@ private static String getPlayerLanguage(String playerName) { private String _tradeAlreadyAcceptedMessage; private String _tradeRequestSentMessage; private String _tradeRequestReceivedMessage; + private String _codeFoundMessage; // ######################################## // # Announcements # @@ -297,6 +298,7 @@ private MessageLanguageManager(String language) { _tradeAlreadyAcceptedMessage = createMessage(messages.getString(warningPath + "TradeAlreadyAccepted")); _tradeRequestSentMessage = createMessage(messages.getString(warningPath + "TradeRequestSent")); _tradeRequestReceivedMessage = createMessage(messages.getString(warningPath + "TradeRequestReceived")); + _codeFoundMessage = createMessage(messages.getString(warningPath + "CodeFound")); String announcementPath = messagePath + "Announcements."; _gameStartingAnnouncementMessage = createMessage(messages.getStringList(announcementPath + "GameStarting")); @@ -627,6 +629,10 @@ public String getTradeRequestReceivedMessage(String playerName, int time) { return _tradeRequestReceivedMessage.replace("{PLAYER}", playerName).replace("{TIME}", Integer.toString(time)); } + public String getCodeFoundMessage() { + return _codeFoundMessage; + } + // ######################################## // # Announcements # // ######################################## diff --git a/src/main/resources/languages/english.yml b/src/main/resources/languages/english.yml index 98bd0b82..0357e8a0 100644 --- a/src/main/resources/languages/english.yml +++ b/src/main/resources/languages/english.yml @@ -159,6 +159,7 @@ Messages: TradeAlreadyAccepted: "&aYou already accepted the trade, wait for your friend to accept." TradeRequestSent: "&eTrade request sent to &b{PLAYER}&e." TradeRequestReceived: "&eYou received a trade request. Shift+Click &b{PLAYER} &eto accept. You have &b{TIME} seconds" + CodeFound: "&eSomeone found the main door code." Announcements: GameStarting: - "&6===================================" From ad4cb0d662e86cdc53c5ade6cb35432baecfdf65 Mon Sep 17 00:00:00 2001 From: TiagoFar78 Date: Wed, 12 Jun 2024 14:18:03 +0100 Subject: [PATCH 05/10] fixed bug where players could move inventory items --- .../net/tiagofar78/prisonescape/Events.java | 24 ++++--------------- .../tiagofar78/prisonescape/game/PEGame.java | 2 +- 2 files changed, 5 insertions(+), 21 deletions(-) diff --git a/src/main/java/net/tiagofar78/prisonescape/Events.java b/src/main/java/net/tiagofar78/prisonescape/Events.java index 1e3823c1..51b65751 100644 --- a/src/main/java/net/tiagofar78/prisonescape/Events.java +++ b/src/main/java/net/tiagofar78/prisonescape/Events.java @@ -9,7 +9,6 @@ import net.tiagofar78.prisonescape.menus.ClickReturnAction; import org.bukkit.Location; -import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.entity.Entity; @@ -38,7 +37,6 @@ import org.bukkit.event.player.PlayerToggleSneakEvent; import org.bukkit.event.weather.WeatherChangeEvent; import org.bukkit.inventory.EquipmentSlot; -import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; public class Events implements Listener { @@ -156,28 +154,14 @@ public void playerClickInventory(InventoryClickEvent e) { } Player player = (Player) e.getWhoClicked(); - boolean isPlayerInv = false; - if (e.getClickedInventory().getType() == InventoryType.PLAYER) { - Inventory topInv = e.getView().getTopInventory(); - if (topInv == null) { - e.setCancelled(true); - return; - } + boolean isPlayerInv = e.getClickedInventory().getType() == InventoryType.PLAYER; - if (e.getCurrentItem() != null && e.getCurrentItem().getType() == Material.BLACK_STAINED_GLASS_PANE) { + if (isPlayerInv && e.getAction() == InventoryAction.DROP_ONE_SLOT) { + if (game.playerDropItem(player.getName(), e.getSlot()) == -1) { e.setCancelled(true); - return; } - if (e.getAction() == InventoryAction.DROP_ALL_SLOT || e.getAction() == InventoryAction.DROP_ONE_SLOT) { - int slot = e.getSlot(); - if (game.playerDropItem(player.getName(), slot) == -1) { - e.setCancelled(true); - } - return; - } - - isPlayerInv = true; + return; } ItemStack cursor = e.getCursor(); diff --git a/src/main/java/net/tiagofar78/prisonescape/game/PEGame.java b/src/main/java/net/tiagofar78/prisonescape/game/PEGame.java index e25726a7..346f078d 100644 --- a/src/main/java/net/tiagofar78/prisonescape/game/PEGame.java +++ b/src/main/java/net/tiagofar78/prisonescape/game/PEGame.java @@ -718,7 +718,7 @@ public ClickReturnAction playerClickMenu(String playerName, int slot, Item itemH Clickable menu = player.getOpenedMenu(); if (menu == null) { - return ClickReturnAction.IGNORE; + return ClickReturnAction.NOTHING; } return menu.click(player, slot, itemHeld, clickedPlayerInv); From adc50b3758072c80f9dd65bb7c3a5d228a56232e Mon Sep 17 00:00:00 2001 From: TiagoFar78 Date: Wed, 12 Jun 2024 15:12:04 +0100 Subject: [PATCH 06/10] fixed bug where tool items were changing its durability --- .../net/tiagofar78/prisonescape/Events.java | 11 +++-- .../tiagofar78/prisonescape/game/PEGame.java | 4 +- .../prisonescape/game/PEPlayer.java | 4 ++ .../game/prisonbuilding/Chest.java | 2 +- .../game/prisonbuilding/Vault.java | 43 +++++++++++++++++-- .../prisonescape/items/ItemFactory.java | 12 ------ .../prisonescape/menus/Clickable.java | 3 +- .../tiagofar78/prisonescape/menus/Shop.java | 2 +- .../prisonescape/menus/TradeMenu.java | 7 +-- 9 files changed, 54 insertions(+), 34 deletions(-) diff --git a/src/main/java/net/tiagofar78/prisonescape/Events.java b/src/main/java/net/tiagofar78/prisonescape/Events.java index 51b65751..28a2ba0f 100644 --- a/src/main/java/net/tiagofar78/prisonescape/Events.java +++ b/src/main/java/net/tiagofar78/prisonescape/Events.java @@ -3,7 +3,6 @@ import net.tiagofar78.prisonescape.game.PEGame; import net.tiagofar78.prisonescape.items.FunctionalItem; import net.tiagofar78.prisonescape.items.Item; -import net.tiagofar78.prisonescape.items.ItemFactory; import net.tiagofar78.prisonescape.managers.ConfigManager; import net.tiagofar78.prisonescape.managers.GameManager; import net.tiagofar78.prisonescape.menus.ClickReturnAction; @@ -167,8 +166,7 @@ public void playerClickInventory(InventoryClickEvent e) { ItemStack cursor = e.getCursor(); ItemStack current = e.getCurrentItem(); - Item item = ItemFactory.createItem(e.getCursor()); - ClickReturnAction returnAction = game.playerClickMenu(player.getName(), e.getSlot(), item, isPlayerInv); + ClickReturnAction returnAction = game.playerClickMenu(player.getName(), e.getSlot(), isPlayerInv); if (returnAction == ClickReturnAction.IGNORE) { return; } @@ -279,7 +277,8 @@ public void onPlayerInteractWithPlayer(PlayerInteractEntityEvent e) { @EventHandler public void onPlayerCombat(EntityDamageByEntityEvent e) { - if (GameManager.getGame() == null) { + PEGame game = GameManager.getGame(); + if (game == null) { return; } @@ -290,8 +289,8 @@ public void onPlayerCombat(EntityDamageByEntityEvent e) { Player pAttacker = (Player) eAttacker; - @SuppressWarnings("deprecation") - Item item = ItemFactory.createItem(pAttacker.getItemInHand()); + String attackerName = pAttacker.getName(); + Item item = game.getPEPlayer(attackerName).getItemAt(pAttacker.getInventory().getHeldItemSlot()); if (item.isFunctional()) { ((FunctionalItem) item).use(e); diff --git a/src/main/java/net/tiagofar78/prisonescape/game/PEGame.java b/src/main/java/net/tiagofar78/prisonescape/game/PEGame.java index 346f078d..cccbcb9b 100644 --- a/src/main/java/net/tiagofar78/prisonescape/game/PEGame.java +++ b/src/main/java/net/tiagofar78/prisonescape/game/PEGame.java @@ -710,7 +710,7 @@ public void playerCloseMenu(String playerName) { player.closeMenu(); } - public ClickReturnAction playerClickMenu(String playerName, int slot, Item itemHeld, boolean clickedPlayerInv) { + public ClickReturnAction playerClickMenu(String playerName, int slot, boolean clickedPlayerInv) { PEPlayer player = getPEPlayer(playerName); if (player == null) { return ClickReturnAction.IGNORE; @@ -721,7 +721,7 @@ public ClickReturnAction playerClickMenu(String playerName, int slot, Item itemH return ClickReturnAction.NOTHING; } - return menu.click(player, slot, itemHeld, clickedPlayerInv); + return menu.click(player, slot, clickedPlayerInv); } public void playerSneak(String playerName) { diff --git a/src/main/java/net/tiagofar78/prisonescape/game/PEPlayer.java b/src/main/java/net/tiagofar78/prisonescape/game/PEPlayer.java index 3e82e8a7..bacfd4bc 100644 --- a/src/main/java/net/tiagofar78/prisonescape/game/PEPlayer.java +++ b/src/main/java/net/tiagofar78/prisonescape/game/PEPlayer.java @@ -111,6 +111,10 @@ public void playerRejoined() { // # Inventory # // ######################################### + public List getItemsInInventory() { + return _inventory; + } + public Item getItemAt(int slot) { Item item = _currentKit.getItemAt(slot); if (item != null) { diff --git a/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/Chest.java b/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/Chest.java index f4e78390..ee930d86 100644 --- a/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/Chest.java +++ b/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/Chest.java @@ -82,7 +82,7 @@ private Item getRandomItem() { } @Override - public ClickReturnAction click(PEPlayer player, int slot, Item itemHeld, boolean clickedPlayerInv) { + public ClickReturnAction click(PEPlayer player, int slot, boolean clickedPlayerInv) { if (clickedPlayerInv) { return ClickReturnAction.NOTHING; } 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 1bfdc7db..79bb78eb 100644 --- a/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/Vault.java +++ b/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/Vault.java @@ -35,6 +35,7 @@ public class Vault implements Clickable { private List _nonHiddenContents; private List _hiddenContents; + private Item _cursorItem; private Prisoner _owner; @@ -43,6 +44,7 @@ public class Vault implements Clickable { public Vault(Prisoner owner, Location location) { _nonHiddenContents = createContentsList(NON_HIDDEN_SIZE); _hiddenContents = createContentsList(HIDDEN_SIZE); + _cursorItem = new NullItem(); _owner = owner; @@ -99,19 +101,22 @@ public int search() { private void clearContents(List contents, int size) { for (int i = 0; i < size; i++) { - contents.set(i, null); + contents.set(i, new NullItem()); } } @Override - public ClickReturnAction click(PEPlayer player, int slot, Item itemHeld, boolean clickedPlayerInv) { + public ClickReturnAction click(PEPlayer player, int slot, boolean clickedPlayerInv) { if (clickedPlayerInv) { int index = player.convertToInventoryIndex(slot); if (index == -1) { return ClickReturnAction.NOTHING; } - player.setItem(index, itemHeld); + Item currentItem = player.getItemsInInventory().get(index); + + player.setItem(index, _cursorItem); + _cursorItem = currentItem; return ClickReturnAction.CHANGE_HOLD_AND_SELECTED; } @@ -122,10 +127,40 @@ public ClickReturnAction click(PEPlayer player, int slot, Item itemHeld, boolean boolean isHidden = isHiddenIndex(slot); - setItem(isHidden, itemIndex, itemHeld); + Item currentItem = isHidden ? _hiddenContents.get(itemIndex) : _nonHiddenContents.get(itemIndex); + + setItem(isHidden, itemIndex, _cursorItem); + _cursorItem = currentItem; return ClickReturnAction.CHANGE_HOLD_AND_SELECTED; } + @Override + public void close(PEPlayer player) { + if (_cursorItem.equals(new NullItem())) { + return; + } + + if (player.giveItem(_cursorItem) != -1) { + return; + } + + for (int i = 0; i < _hiddenContents.size(); i++) { + if (_hiddenContents.get(i).equals(new NullItem())) { + setItem(false, i, _cursorItem); + return; + } + } + + for (int i = 0; i < _nonHiddenContents.size(); i++) { + if (_nonHiddenContents.get(i).equals(new NullItem())) { + setItem(true, i, _cursorItem); + return; + } + } + + throw new RuntimeException("There are more items in inventory + vault now than when it was opened"); + } + private int convertToIndex(int slot) { for (int i = 0; i < NON_HIDDEN_ITEMS_INDEXES.length; i++) { if (NON_HIDDEN_ITEMS_INDEXES[i] == slot) { diff --git a/src/main/java/net/tiagofar78/prisonescape/items/ItemFactory.java b/src/main/java/net/tiagofar78/prisonescape/items/ItemFactory.java index edee2bd9..cab5992e 100644 --- a/src/main/java/net/tiagofar78/prisonescape/items/ItemFactory.java +++ b/src/main/java/net/tiagofar78/prisonescape/items/ItemFactory.java @@ -1,7 +1,5 @@ package net.tiagofar78.prisonescape.items; -import org.bukkit.inventory.ItemStack; - public class ItemFactory { private static Item[] items = { @@ -43,16 +41,6 @@ public class ItemFactory { new OpenCamerasItem(), new MissionsItem()}; - public static Item createItem(ItemStack bukkitItem) { - for (Item item : items) { - if (item.matches(bukkitItem)) { - return instantiateItem(item.getClass()); - } - } - - return new NullItem(); - } - public static Item createItem(String name) { for (Item item : items) { if (item.getConfigName().equals(name)) { diff --git a/src/main/java/net/tiagofar78/prisonescape/menus/Clickable.java b/src/main/java/net/tiagofar78/prisonescape/menus/Clickable.java index c2a11f76..7fb755f3 100644 --- a/src/main/java/net/tiagofar78/prisonescape/menus/Clickable.java +++ b/src/main/java/net/tiagofar78/prisonescape/menus/Clickable.java @@ -1,7 +1,6 @@ package net.tiagofar78.prisonescape.menus; import net.tiagofar78.prisonescape.game.PEPlayer; -import net.tiagofar78.prisonescape.items.Item; import net.tiagofar78.prisonescape.managers.MessageLanguageManager; import org.bukkit.inventory.Inventory; @@ -18,6 +17,6 @@ public default void updateInventory(Inventory inv, PEPlayer player) { // Nothing } - public abstract ClickReturnAction click(PEPlayer player, int slot, Item itemHeld, boolean clickedPlayerInv); + public abstract ClickReturnAction click(PEPlayer player, int slot, boolean clickedPlayerInv); } diff --git a/src/main/java/net/tiagofar78/prisonescape/menus/Shop.java b/src/main/java/net/tiagofar78/prisonescape/menus/Shop.java index 35ba6447..d5b82153 100644 --- a/src/main/java/net/tiagofar78/prisonescape/menus/Shop.java +++ b/src/main/java/net/tiagofar78/prisonescape/menus/Shop.java @@ -40,7 +40,7 @@ private List createContentsList() { } @Override - public ClickReturnAction click(PEPlayer player, int slot, Item itemHeld, boolean clickedPlayerInv) { + public ClickReturnAction click(PEPlayer player, int slot, boolean clickedPlayerInv) { Guard guard = (Guard) player; if (clickedPlayerInv) { diff --git a/src/main/java/net/tiagofar78/prisonescape/menus/TradeMenu.java b/src/main/java/net/tiagofar78/prisonescape/menus/TradeMenu.java index 262bc6c2..1fa7355b 100644 --- a/src/main/java/net/tiagofar78/prisonescape/menus/TradeMenu.java +++ b/src/main/java/net/tiagofar78/prisonescape/menus/TradeMenu.java @@ -104,12 +104,7 @@ public void close(PEPlayer firstCloser) { } @Override - public ClickReturnAction click( - PEPlayer player, - int slot, - Item itemHeld, - boolean clickedPlayerInv - ) { + public ClickReturnAction click(PEPlayer player, int slot, boolean clickedPlayerInv) { return clickedPlayerInv ? clickPlayerInv(player, slot) : clickViewInv(player, slot); } From 05afc93dbde5579096ca85e96dabdfb15309a136 Mon Sep 17 00:00:00 2001 From: TiagoFar78 Date: Wed, 12 Jun 2024 16:20:48 +0100 Subject: [PATCH 07/10] fixed bug where items were getting duplicated in vault --- .../java/net/tiagofar78/prisonescape/game/PEPlayer.java | 9 +++++++++ .../prisonescape/game/prisonbuilding/Vault.java | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/src/main/java/net/tiagofar78/prisonescape/game/PEPlayer.java b/src/main/java/net/tiagofar78/prisonescape/game/PEPlayer.java index bacfd4bc..dd48c2d5 100644 --- a/src/main/java/net/tiagofar78/prisonescape/game/PEPlayer.java +++ b/src/main/java/net/tiagofar78/prisonescape/game/PEPlayer.java @@ -394,6 +394,15 @@ private void closeInventoryView() { player.closeInventory(); } + public void setCursorItem(ItemStack item) { + Player player = getBukkitPlayer(); + if (player == null) { + return; + } + + player.setItemOnCursor(item); + } + public void playSound(Sound sound) { Player player = getBukkitPlayer(); if (player == null) { 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 79bb78eb..ea80426f 100644 --- a/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/Vault.java +++ b/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/Vault.java @@ -136,17 +136,22 @@ public ClickReturnAction click(PEPlayer player, int slot, boolean clickedPlayerI @Override public void close(PEPlayer player) { + player.setCursorItem(null); + if (_cursorItem.equals(new NullItem())) { return; } if (player.giveItem(_cursorItem) != -1) { + _cursorItem = new NullItem(); + player.updateInventory(); return; } for (int i = 0; i < _hiddenContents.size(); i++) { if (_hiddenContents.get(i).equals(new NullItem())) { setItem(false, i, _cursorItem); + _cursorItem = new NullItem(); return; } } @@ -154,6 +159,7 @@ public void close(PEPlayer player) { for (int i = 0; i < _nonHiddenContents.size(); i++) { if (_nonHiddenContents.get(i).equals(new NullItem())) { setItem(true, i, _cursorItem); + _cursorItem = new NullItem(); return; } } From 825c91430b18bc89ebbac77cd6f098af0dd2437b Mon Sep 17 00:00:00 2001 From: TiagoFar78 Date: Wed, 12 Jun 2024 16:39:24 +0100 Subject: [PATCH 08/10] fixed paintings being broken --- .../net/tiagofar78/prisonescape/Events.java | 22 ++++++++++++++++++- .../game/prisonbuilding/Vault.java | 2 +- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/tiagofar78/prisonescape/Events.java b/src/main/java/net/tiagofar78/prisonescape/Events.java index 28a2ba0f..96ecc26f 100644 --- a/src/main/java/net/tiagofar78/prisonescape/Events.java +++ b/src/main/java/net/tiagofar78/prisonescape/Events.java @@ -23,6 +23,7 @@ import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntitySpawnEvent; import org.bukkit.event.entity.FoodLevelChangeEvent; +import org.bukkit.event.hanging.HangingBreakEvent; import org.bukkit.event.inventory.InventoryAction; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryCloseEvent; @@ -41,7 +42,7 @@ public class Events implements Listener { private static final EntityType[] ALLOWED_MOBS = - {EntityType.PRIMED_TNT, EntityType.PAINTING, EntityType.ARMOR_STAND}; + {EntityType.PRIMED_TNT, EntityType.PAINTING, EntityType.ARMOR_STAND, EntityType.ITEM_FRAME}; @EventHandler public void playerMove(PlayerMoveEvent e) { @@ -251,6 +252,17 @@ public void onBlockBreak(BlockBreakEvent event) { } } + @EventHandler + public void onBlockHangingBreak(HangingBreakEvent e) { + EntityType type = e.getEntity().getType(); + for (EntityType mobType : ALLOWED_MOBS) { + if (mobType == type) { + e.setCancelled(true); + break; + } + } + } + @EventHandler public void onExplosion(EntityExplodeEvent e) { if (!e.getEntity().getWorld().getName().equals(ConfigManager.getInstance().getWorldName())) { @@ -287,6 +299,14 @@ public void onPlayerCombat(EntityDamageByEntityEvent e) { return; } + EntityType type = e.getEntity().getType(); + for (EntityType mobType : ALLOWED_MOBS) { + if (mobType == type) { + e.setCancelled(true); + break; + } + } + Player pAttacker = (Player) eAttacker; String attackerName = pAttacker.getName(); 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 ea80426f..9183d209 100644 --- a/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/Vault.java +++ b/src/main/java/net/tiagofar78/prisonescape/game/prisonbuilding/Vault.java @@ -220,7 +220,7 @@ public void deleteVaultAndRespectiveSignFromWorld() { Location signLocation = _location.clone().add(0, 1, 0); vaultLocation.getBlock().setType(Material.AIR); - signLocation.clone().add(0, 1, 0).getBlock().setType(Material.AIR); + signLocation.getBlock().setType(Material.AIR); } @Override From d73d96cc1fc23a84fe51b6f05ec01c707fe103d8 Mon Sep 17 00:00:00 2001 From: TiagoFar78 Date: Thu, 13 Jun 2024 17:32:31 +0100 Subject: [PATCH 09/10] ran formatter --- .../java/net/tiagofar78/prisonescape/items/DoorCodeItem.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/tiagofar78/prisonescape/items/DoorCodeItem.java b/src/main/java/net/tiagofar78/prisonescape/items/DoorCodeItem.java index a1d4733e..846a1abe 100644 --- a/src/main/java/net/tiagofar78/prisonescape/items/DoorCodeItem.java +++ b/src/main/java/net/tiagofar78/prisonescape/items/DoorCodeItem.java @@ -43,7 +43,7 @@ public void use(PlayerInteractEvent e) { BukkitMessageSender.sendChatMessage(prisoner, messages.getCodeFoundMessage()); } } - + @Override public List getCratingItems() { List items = new ArrayList<>(); From c2fffb65ade0903003196f70b9643a015021ec37 Mon Sep 17 00:00:00 2001 From: TiagoFar78 Date: Thu, 13 Jun 2024 17:39:01 +0100 Subject: [PATCH 10/10] fixed merge conflict --- .../java/net/tiagofar78/prisonescape/menus/CraftingMenu.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/tiagofar78/prisonescape/menus/CraftingMenu.java b/src/main/java/net/tiagofar78/prisonescape/menus/CraftingMenu.java index ff454c45..dfd3a0d4 100644 --- a/src/main/java/net/tiagofar78/prisonescape/menus/CraftingMenu.java +++ b/src/main/java/net/tiagofar78/prisonescape/menus/CraftingMenu.java @@ -131,7 +131,7 @@ public void updateInventory(Inventory inv, PEPlayer player) { } @Override - public ClickReturnAction click(PEPlayer player, int slot, Item itemHeld, boolean clickedPlayerInv) { + public ClickReturnAction click(PEPlayer player, int slot, boolean clickedPlayerInv) { if (clickedPlayerInv) { return ClickReturnAction.NOTHING; }