From e1f0938f59af482363062fecfe6a6f434732a3a0 Mon Sep 17 00:00:00 2001 From: utarwyn Date: Thu, 17 May 2018 01:38:59 +0200 Subject: [PATCH] Fix item frame/armor stand protection --- .../listeners/FactionsEntityListener.java | 28 +++++++++++++++++ .../listeners/FactionsPlayerListener.java | 30 +++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsEntityListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsEntityListener.java index 3a80dc09..a8edb958 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsEntityListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsEntityListener.java @@ -131,6 +131,34 @@ public class FactionsEntityListener implements Listener { } } } else { + // Protect armor stands/item frames from being damaged in protected territories + if (damagee.getType() == EntityType.ITEM_FRAME || damagee.getType() == EntityType.ARMOR_STAND) { + // Run the check for a player + if (damager instanceof Player) { + // Generate the action message. + String entityAction; + + if (damagee.getType() == EntityType.ITEM_FRAME) { + entityAction = "item frames"; + } else { + entityAction = "armor stands"; + } + + if (!FactionsBlockListener.playerCanBuildDestroyBlock((Player) damager, damagee.getLocation(), "destroy " + entityAction, false)) { + event.setCancelled(true); + } + } else { + // we don't want to let mobs/arrows destroy item frames/armor stands + // so we only have to run the check as if there had been an explosion at the damager location + if (!this.checkExplosionForBlock(damager, damagee.getLocation().getBlock())) { + event.setCancelled(true); + } + } + + // we don't need to go after + return; + } + //this one should trigger if something other than a player takes damage if (damager instanceof Player) { // now itll only go here if the damage is dealt by a player diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java index 8a03536b..5178a04d 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java @@ -658,6 +658,36 @@ public class FactionsPlayerListener implements Listener { } } + // For disabling interactions with item frames in another faction's territory + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { + // only need to check for item frames + if (event.getRightClicked().getType() != EntityType.ITEM_FRAME) { + return; + } + + Player player = event.getPlayer(); + Entity entity = event.getRightClicked(); + + if (!FactionsBlockListener.playerCanBuildDestroyBlock(player, entity.getLocation(), "use item frames", false)) { + event.setCancelled(true); + } + } + + // For disabling interactions with armor stands in another faction's territory + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onPlayerInteractAtEntity(PlayerInteractAtEntityEvent event) { + Entity entity = event.getRightClicked(); + + // only need to check for armor stand and item frames + if (entity.getType() != EntityType.ARMOR_STAND) { + return; + } + + if (!FactionsBlockListener.playerCanBuildDestroyBlock(event.getPlayer(), entity.getLocation(), "use armor stands", false)) { + event.setCancelled(true); + } + } // for handling people who repeatedly spam attempts to open a door (or similar) in another faction's territory private Map interactSpammers = new HashMap<>();