From 1faac3854e9bc8d77d05e40b0adc92146cdb7561 Mon Sep 17 00:00:00 2001 From: Eric Date: Mon, 23 Mar 2020 23:44:41 +0100 Subject: [PATCH] Update hologram text on inventory update (Untested) --- .../listeners/ShopUpdateListener.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/main/java/de/epiceric/shopchest/listeners/ShopUpdateListener.java b/src/main/java/de/epiceric/shopchest/listeners/ShopUpdateListener.java index 28bfc49..3e3d6d8 100644 --- a/src/main/java/de/epiceric/shopchest/listeners/ShopUpdateListener.java +++ b/src/main/java/de/epiceric/shopchest/listeners/ShopUpdateListener.java @@ -9,10 +9,13 @@ import java.util.Set; import org.bukkit.Chunk; import org.bukkit.Location; +import org.bukkit.block.Chest; +import org.bukkit.block.DoubleChest; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryMoveItemEvent; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerTeleportEvent; @@ -28,6 +31,28 @@ public class ShopUpdateListener implements Listener { this.plugin = plugin; } + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onInventoryUpdate(InventoryMoveItemEvent e) { + if (!plugin.getHologramFormat().isDynamic()) return; + + Location loc = null; + + if (e.getSource().getHolder() instanceof Chest) { + loc = ((Chest) e.getSource().getHolder()).getLocation(); + } else if (e.getSource().getHolder() instanceof DoubleChest) { + loc = ((DoubleChest) e.getSource().getHolder()).getLocation(); + } else if (e.getDestination().getHolder() instanceof Chest) { + loc = ((Chest) e.getDestination().getHolder()).getLocation(); + } else if (e.getDestination().getHolder() instanceof DoubleChest) { + loc = ((DoubleChest) e.getDestination().getHolder()).getLocation(); + } + + if (loc != null) { + Shop shop = plugin.getShopUtils().getShop(loc); + if (shop != null) shop.updateHologramText(); + } + } + @EventHandler public void onPlayerLeave(PlayerQuitEvent e) { // If done without delay, Bukkit#getOnlinePlayers() would still