diff --git a/src/main/java/com/massivecraft/factions/engine/EngineMain.java b/src/main/java/com/massivecraft/factions/engine/EngineMain.java index e00cd91e..ecc4ba28 100644 --- a/src/main/java/com/massivecraft/factions/engine/EngineMain.java +++ b/src/main/java/com/massivecraft/factions/engine/EngineMain.java @@ -22,7 +22,6 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Enderman; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; -import org.bukkit.entity.ItemFrame; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.entity.Wither; @@ -85,7 +84,6 @@ import com.massivecraft.factions.event.EventFactionsPvpDisallowed; import com.massivecraft.factions.event.EventFactionsPowerChange; import com.massivecraft.factions.event.EventFactionsPowerChange.PowerChangeReason; import com.massivecraft.factions.integration.Econ; -import com.massivecraft.factions.spigot.SpigotFeatures; import com.massivecraft.factions.util.VisualizeUtil; import com.massivecraft.massivecore.EngineAbstract; import com.massivecraft.massivecore.PriorityLines; @@ -1312,49 +1310,6 @@ public class EngineMain extends EngineAbstract return MPerm.getPermBuild().has(mplayer, ps, verboose); } - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void blockBuild(HangingPlaceEvent event) - { - if (canPlayerBuildAt(event.getPlayer(), PS.valueOf(event.getEntity().getLocation()), true)) return; - - event.setCancelled(true); - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void blockBuild(HangingBreakEvent event) - { - if (! (event instanceof HangingBreakByEntityEvent)) return; - HangingBreakByEntityEvent entityEvent = (HangingBreakByEntityEvent)event; - - Entity breaker = entityEvent.getRemover(); - if (! (breaker instanceof Player)) return; - - if ( ! canPlayerBuildAt(breaker, PS.valueOf(event.getEntity().getLocation()), true)) - { - event.setCancelled(true); - } - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void itemFrameDamage(EntityDamageByEntityEvent event) - { - // If the damagee is an ItemFrame ... - Entity edamagee = event.getEntity(); - if (!(edamagee instanceof ItemFrame)) return; - ItemFrame itemFrame = (ItemFrame)edamagee; - - // ... and the liable damager is a player ... - Entity edamager = MUtil.getLiableDamager(event); - if (!(edamager instanceof Player)) return; - Player player = (Player)edamager; - - // ... and the player can't build there ... - if (canPlayerBuildAt(player, PS.valueOf(itemFrame.getLocation()), true)) return; - - // ... then cancel the event. - event.setCancelled(true); - } - @EventHandler(priority = EventPriority.NORMAL) public void blockBuild(BlockPlaceEvent event) { @@ -1435,10 +1390,53 @@ public class EngineMain extends EngineAbstract } } + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void blockBuild(HangingPlaceEvent event) + { + if (canPlayerBuildAt(event.getPlayer(), PS.valueOf(event.getEntity().getLocation()), true)) return; + + event.setCancelled(true); + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void blockBuild(HangingBreakEvent event) + { + if (! (event instanceof HangingBreakByEntityEvent)) return; + HangingBreakByEntityEvent entityEvent = (HangingBreakByEntityEvent)event; + + Entity breaker = entityEvent.getRemover(); + if (! (breaker instanceof Player)) return; + + if ( ! canPlayerBuildAt(breaker, PS.valueOf(event.getEntity().getLocation()), true)) + { + event.setCancelled(true); + } + } + // -------------------------------------------- // // ASSORTED BUILD AND INTERACT // -------------------------------------------- // + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onPlayerDamageEntity(EntityDamageByEntityEvent event) + { + // If a player ... + Entity edamager = MUtil.getLiableDamager(event); + if (!(edamager instanceof Player)) return; + Player player = (Player)edamager; + + // ... damages an entity which is edited on damage ... + Entity edamagee = event.getEntity(); + if (edamagee == null) return; + if ( ! MConf.get().entityTypesEditOnDamage.contains(edamagee.getType())) return; + + // ... and the player can't build there ... + if (canPlayerBuildAt(player, PS.valueOf(edamagee.getLocation()), true)) return; + + // ... then cancel the event. + event.setCancelled(true); + } + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onPlayerInteract(PlayerInteractEvent event) { @@ -1521,6 +1519,8 @@ public class EngineMain extends EngineAbstract // ... interacts with an entity ... if (entity == null) return true; + EntityType type = entity.getType(); + PS ps = PS.valueOf(entity.getLocation()); // ... and the player does not bypass all protections ... String name = player.getName(); @@ -1530,16 +1530,14 @@ public class EngineMain extends EngineAbstract MPlayer me = MPlayer.get(player); if (me.isUsingAdminMode()) return true; - // ... and the entity is of a container type ... - EntityType type = entity.getType(); - if ( ! MConf.get().entityTypesContainer.contains(type)) return true; + // ... check container entity rights ... + if (MConf.get().entityTypesContainer.contains(type) && ! MPerm.getPermContainer().has(me, ps, verboose)) return false; - // ... and the player lacks the container perm ... - PS ps = PS.valueOf(entity.getLocation()); - if (MPerm.getPermContainer().has(me, ps, verboose)) return true; + // ... check build entity rights ... + if (MConf.get().entityTypesEditOnInteract.contains(type) && ! MPerm.getPermBuild().has(me, ps, verboose)) return false; - // ... then we can't use the entity. - return false; + // ... otherwise we may use the entity. + return true; } // For some reason onPlayerInteract() sometimes misses bucket events depending on distance (something like 2-3 blocks away isn't detected), diff --git a/src/main/java/com/massivecraft/factions/entity/MConf.java b/src/main/java/com/massivecraft/factions/entity/MConf.java index b0ba717a..df827a89 100644 --- a/src/main/java/com/massivecraft/factions/entity/MConf.java +++ b/src/main/java/com/massivecraft/factions/entity/MConf.java @@ -467,6 +467,7 @@ public class MConf extends Entity // If you however are using Forge with mods that add new container types you might want to add them here. // This way they can be protected in Faction territory. + // Interacting with these materials when they are already placed in the terrain results in an edit. public BackstringEnumSet materialsEditOnInteract = new BackstringEnumSet(Material.class, "DIODE_BLOCK_OFF", // Minecraft 1.? "DIODE_BLOCK_ON", // Minecraft 1.? @@ -475,12 +476,15 @@ public class MConf extends Entity "SOIL" // Minecraft 1.? ); + // Interacting with the the terrain holding this item in hand results in an edit. + // There's no need to add all block materials here. Only special items other than blocks. public BackstringEnumSet materialsEditTools = new BackstringEnumSet(Material.class, "FIREBALL", // Minecraft 1.? "FLINT_AND_STEEL", // Minecraft 1.? "BUCKET", // Minecraft 1.? "WATER_BUCKET", // Minecraft 1.? - "LAVA_BUCKET" // Minecraft 1.? + "LAVA_BUCKET", // Minecraft 1.? + "ARMOR_STAND" // Minecraft 1.8 ); // The duplication bug found in Spigot 1.8 protocol patch @@ -494,6 +498,7 @@ public class MConf extends Entity "IRON_DOOR" // Minecraft 1.? ); + // Interacting with these materials placed in the terrain results in door toggling. public BackstringEnumSet materialsDoor = new BackstringEnumSet(Material.class, "WOODEN_DOOR", // Minecraft 1.? "ACACIA_DOOR", // Minecraft 1.8 @@ -510,6 +515,7 @@ public class MConf extends Entity "SPRUCE_FENCE_GATE" // Minecraft 1.8 ); + // Interacting with these materials placed in the terrain results in opening a container. public BackstringEnumSet materialsContainer = new BackstringEnumSet(Material.class, "DISPENSER", // Minecraft 1.? "CHEST", // Minecraft 1.? @@ -525,12 +531,25 @@ public class MConf extends Entity "DROPPER" // Minecraft 1.? ); - public BackstringEnumSet entityTypesContainer = new BackstringEnumSet(EntityType.class, - "MINECART_CHEST", // Minecraft 1.? - "MINECART_HOPPER", // Minecraft 1.? + // Interacting with these entities results in an edit. + public BackstringEnumSet entityTypesEditOnInteract = new BackstringEnumSet(EntityType.class, + "ITEM_FRAME", // Minecraft 1.? "ARMOR_STAND" // Minecraft 1.8 ); + // Damaging these entities results in an edit. + public BackstringEnumSet entityTypesEditOnDamage = new BackstringEnumSet(EntityType.class, + "ITEM_FRAME", // Minecraft 1.? + "ARMOR_STAND" // Minecraft 1.8 + ); + + // Interacting with these entities results in opening a container. + public BackstringEnumSet entityTypesContainer = new BackstringEnumSet(EntityType.class, + "MINECART_CHEST", // Minecraft 1.? + "MINECART_HOPPER" // Minecraft 1.? + ); + + // The complete list of entities considered to be monsters. public BackstringEnumSet entityTypesMonsters = new BackstringEnumSet(EntityType.class, "BLAZE", // Minecraft 1.? "CAVE_SPIDER", // Minecraft 1.?