From ea91d85b604ff1e582bcbb18cdab872d7cbe6598 Mon Sep 17 00:00:00 2001 From: rlf Date: Fri, 13 Jul 2018 13:10:43 +0200 Subject: [PATCH] Fix issue #1064 - challenge chests --- .../ultimateskyblock/signs/SignEvents.java | 40 +++++++++++++------ .../ultimateskyblock/util/LocationUtil.java | 5 ++- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/uSkyBlock-Core/src/main/java/us/talabrek/ultimateskyblock/signs/SignEvents.java b/uSkyBlock-Core/src/main/java/us/talabrek/ultimateskyblock/signs/SignEvents.java index 81bae3f07..5a080c820 100644 --- a/uSkyBlock-Core/src/main/java/us/talabrek/ultimateskyblock/signs/SignEvents.java +++ b/uSkyBlock-Core/src/main/java/us/talabrek/ultimateskyblock/signs/SignEvents.java @@ -13,6 +13,7 @@ import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.SignChangeEvent; import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.event.inventory.InventoryEvent; import org.bukkit.event.inventory.InventoryMoveItemEvent; import org.bukkit.event.player.PlayerInteractEvent; import us.talabrek.ultimateskyblock.uSkyBlock; @@ -41,7 +42,7 @@ public void onPlayerHitSign(PlayerInteractEvent e) { || (e.getAction() != Action.RIGHT_CLICK_BLOCK && e.getAction() != Action.LEFT_CLICK_BLOCK) || e.getClickedBlock() == null || e.getClickedBlock().getType() != Material.WALL_SIGN || !(e.getClickedBlock().getState() instanceof Sign) - || !hasPermission(e.getPlayer(), "usb.island.signs.use") + || !e.getPlayer().hasPermission("usb.island.signs.use") || e.getPlayer() == null || !plugin.isSkyAssociatedWorld(e.getPlayer().getWorld()) || !(plugin.playerIsOnOwnIsland(e.getPlayer())) ) { @@ -80,18 +81,31 @@ private boolean isChest(Block wallBlock) { && wallBlock.getState() instanceof Chest; } - //@EventHandler(priority = EventPriority.MONITOR) - //public void onChestClosed(InventoryCloseEvent e) { - // if (e.getPlayer() == null || e.getPlayer().getLocation() == null - // || !plugin.isSkyAssociatedWorld(e.getPlayer().getLocation().getWorld()) - // ) { - // return; - // } - // Location loc = ReflectionUtil.exec(e.getInventory(), "getLocation"); - // if (loc != null) { - // logic.updateSignsOnContainer(loc); - // } - //} + @EventHandler(priority = EventPriority.MONITOR) + public void onInventoryMovedEvent(InventoryMoveItemEvent e) { + if (e.getDestination() == null || e.getDestination().getLocation() == null || !plugin.isSkyAssociatedWorld(e.getDestination().getLocation().getWorld())) { + return; + } + Location loc = e.getDestination().getLocation(); + if (loc != null) { + logic.updateSignsOnContainer(loc); + } + loc = e.getSource().getLocation(); + if (loc != null) { + logic.updateSignsOnContainer(loc); + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onChestClosed(InventoryCloseEvent e) { + if (e.getPlayer() == null || e.getPlayer().getLocation() == null || !plugin.isSkyAssociatedWorld(e.getPlayer().getLocation().getWorld())) { + return; + } + Location loc = e.getInventory().getLocation(); + if (loc != null) { + logic.updateSignsOnContainer(loc); + } + } @EventHandler(priority = EventPriority.MONITOR) public void onSignOrChestBreak(BlockBreakEvent e) { diff --git a/uSkyBlock-Core/src/main/java/us/talabrek/ultimateskyblock/util/LocationUtil.java b/uSkyBlock-Core/src/main/java/us/talabrek/ultimateskyblock/util/LocationUtil.java index 6615a2103..2adad9b68 100644 --- a/uSkyBlock-Core/src/main/java/us/talabrek/ultimateskyblock/util/LocationUtil.java +++ b/uSkyBlock-Core/src/main/java/us/talabrek/ultimateskyblock/util/LocationUtil.java @@ -14,6 +14,7 @@ import us.talabrek.ultimateskyblock.Settings; import us.talabrek.ultimateskyblock.api.async.Callback; +import java.util.Locale; import java.util.logging.Level; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -46,9 +47,9 @@ public static String asString(Location loc) { if (loc.getWorld() != null && loc.getWorld().getName() != null) { s += loc.getWorld().getName() + ":"; } - s += String.format("%.2f,%.2f,%.2f", loc.getX(), loc.getY(), loc.getZ()); + s += String.format(Locale.ENGLISH, "%.2f,%.2f,%.2f", loc.getX(), loc.getY(), loc.getZ()); if (loc.getYaw() != 0f || loc.getPitch() != 0f) { - s += String.format(":%.2f:%.2f", loc.getYaw(), loc.getPitch()); + s += String.format(Locale.ENGLISH, ":%.2f:%.2f", loc.getYaw(), loc.getPitch()); } return s; }