From e3c154ba7a1cdc7e0044ec30b66d2451a6f42084 Mon Sep 17 00:00:00 2001 From: Connor Monahan Date: Wed, 8 Jun 2016 18:23:30 -0400 Subject: [PATCH] Prevent breaking paintings in unbreakable zones Closes #815 --- .../war/event/WarEntityListener.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/war/src/main/java/com/tommytony/war/event/WarEntityListener.java b/war/src/main/java/com/tommytony/war/event/WarEntityListener.java index 182293e..4d39a66 100644 --- a/war/src/main/java/com/tommytony/war/event/WarEntityListener.java +++ b/war/src/main/java/com/tommytony/war/event/WarEntityListener.java @@ -30,6 +30,8 @@ import org.bukkit.event.entity.FoodLevelChangeEvent; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.entity.ProjectileHitEvent; import org.bukkit.event.entity.ProjectileLaunchEvent; +import org.bukkit.event.hanging.HangingPlaceEvent; +import org.bukkit.event.hanging.HangingBreakByEntityEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.projectiles.ProjectileSource; @@ -496,4 +498,43 @@ public class WarEntityListener implements Listener { } } + @EventHandler + public void onPaintingBreakByEntity(final HangingBreakByEntityEvent event) { + if (!War.war.isLoaded()) { + return; + } + if (!(event.getRemover() instanceof Player)) { + return; + } + Player player = (Player) event.getRemover(); + Warzone zone = Warzone.getZoneByLocation(event.getEntity().getLocation()); + Team team = Team.getTeamByPlayerName(player.getName()); + boolean isZoneMaker = War.war.isZoneMaker(player); + if (team == null && isZoneMaker) { + return; + } + if (zone != null && zone.getWarzoneConfig().getBoolean(WarzoneConfig.UNBREAKABLE)) { + event.setCancelled(true); + War.war.badMsg(player, "build.denied.zone.break"); + } + } + + @EventHandler + public void onPaintingPlaceByEntity(final HangingPlaceEvent event) { + if (!War.war.isLoaded()) { + return; + } + Player player = event.getPlayer(); + Warzone zone = Warzone.getZoneByLocation(event.getBlock().getLocation()); + Team team = Team.getTeamByPlayerName(player.getName()); + boolean isZoneMaker = War.war.isZoneMaker(player); + if (team == null && isZoneMaker) { + return; + } + if (zone != null && (zone.getWarzoneConfig().getBoolean(WarzoneConfig.UNBREAKABLE) + || (team != null && !team.getTeamConfig().resolveBoolean(TeamConfig.PLACEBLOCK)))) { + event.setCancelled(true); + War.war.badMsg(player, "build.denied.zone.place"); + } + } }