diff --git a/src/com/gmail/St3venAU/plugins/ArmorStandTools/ArmorStandGUI.java b/src/com/gmail/St3venAU/plugins/ArmorStandTools/ArmorStandGUI.java index 32aa69d..5f44eba 100644 --- a/src/com/gmail/St3venAU/plugins/ArmorStandTools/ArmorStandGUI.java +++ b/src/com/gmail/St3venAU/plugins/ArmorStandTools/ArmorStandGUI.java @@ -32,7 +32,7 @@ class ArmorStandGUI implements Listener { private Main plugin; ArmorStandGUI(Main plugin, ArmorStand as, Player p) { - if(inUse.contains(as.getEntityId())) { + if(isInUse(as)) { p.sendMessage(ChatColor.RED + Config.guiInUse); return; } @@ -81,6 +81,10 @@ class ArmorStandGUI implements Listener { p.openInventory(i); } + public static boolean isInUse(ArmorStand as) { + return inUse.contains(as.getEntityId()); + } + private ItemStack updateLore(ArmorStandTool tool) { ItemStack item = tool.getItem(); switch (tool) { @@ -117,7 +121,7 @@ class ArmorStandGUI implements Listener { } @EventHandler - public void inInventoryClose(InventoryCloseEvent event) { + public void onInventoryClose(InventoryCloseEvent event) { if(!event.getInventory().equals(i)) return; HandlerList.unregisterAll(this); inUse.remove(as.getEntityId()); diff --git a/src/com/gmail/St3venAU/plugins/ArmorStandTools/MainListener.java b/src/com/gmail/St3venAU/plugins/ArmorStandTools/MainListener.java index a61ad0d..6091679 100644 --- a/src/com/gmail/St3venAU/plugins/ArmorStandTools/MainListener.java +++ b/src/com/gmail/St3venAU/plugins/ArmorStandTools/MainListener.java @@ -18,6 +18,7 @@ import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.SignChangeEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.inventory.CraftItemEvent; import org.bukkit.event.inventory.InventoryAction; @@ -56,6 +57,11 @@ public class MainListener implements Listener { if (event.getRightClicked() instanceof ArmorStand) { Player p = event.getPlayer(); ArmorStand as = (ArmorStand) event.getRightClicked(); + if(ArmorStandGUI.isInUse(as)) { + Main.nms.actionBarMsg(p, Config.guiInUse); + event.setCancelled(true); + return; + } if(plugin.carryingArmorStand.containsKey(p.getUniqueId())) { if (plugin.playerHasPermission(p, plugin.carryingArmorStand.get(p.getUniqueId()).getLocation().getBlock(), null)) { plugin.carryingArmorStand.remove(p.getUniqueId()); @@ -359,7 +365,8 @@ public class MainListener implements Listener { @EventHandler public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { if(event.getEntity() instanceof ArmorStand) { - if(Main.nms.isInvulnerable((ArmorStand) event.getEntity())) { + ArmorStand as = (ArmorStand) event.getEntity(); + if(ArmorStandGUI.isInUse(as) || Main.nms.isInvulnerable(as)) { event.setCancelled(true); } if(event.getDamager() instanceof Player && ArmorStandTool.isHoldingTool((Player) event.getDamager())) { @@ -371,6 +378,16 @@ public class MainListener implements Listener { } } + @EventHandler + public void onEntityDamage(EntityDamageEvent event) { + if(event.getEntity() instanceof ArmorStand) { + ArmorStand as = (ArmorStand) event.getEntity(); + if(ArmorStandGUI.isInUse(as) || Main.nms.isInvulnerable(as)) { + event.setCancelled(true); + } + } + } + private boolean noCooldown(Entity e) { for(MetadataValue meta : e.getMetadata("lastDrop")) { if(meta.getOwningPlugin() == plugin) { diff --git a/src/config.yml b/src/config.yml index 4870bdc..03bc124 100644 --- a/src/config.yml +++ b/src/config.yml @@ -4,7 +4,7 @@ # # Main Config # -# File generated by: v2.4.2 +# File generated by: v2.4.3 # (If this is not the version you are running, consider deleting this # config to allow it to be re-created. There may be new config options) # diff --git a/src/language.yml b/src/language.yml index 87e242b..4cd1acd 100644 --- a/src/language.yml +++ b/src/language.yml @@ -4,7 +4,7 @@ # # Language Config # -# File generated by: v2.4.2 +# File generated by: v2.4.3 # (If this is not the version you are running, consider deleting this # config to allow it to be re-created. There may be new config options) # diff --git a/src/plugin.yml b/src/plugin.yml index edc2ae6..939a7be 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,6 +1,6 @@ main: com.gmail.St3venAU.plugins.ArmorStandTools.Main name: ArmorStandTools -version: 2.4.2 +version: 2.4.3 author: St3venAU description: Armor stand manipulation tools softdepend: [WorldGuard, PlotSquared]