From a02fcca54d97907e7884378fb01c3069f51029ac Mon Sep 17 00:00:00 2001 From: Brettflan Date: Thu, 28 Apr 2011 15:45:43 -0500 Subject: [PATCH] Updates in preparation for 1.1.7 release: * /f map has been updated to fit inside the new Bukkit line-width limits (39 tiles wide instead of 49) * Players who aren't currently in a faction should no longer get "Person left your faction" messages when others join a faction * Attempt at simple workaround for error related to NPCs from Citizens plugin * Placement and removal of paintings is now prevented if you're in another faction's territory --- src/org/mcteam/factions/Conf.java | 2 +- src/org/mcteam/factions/FPlayer.java | 11 ++- src/org/mcteam/factions/Factions.java | 2 + .../listeners/FactionsEntityListener.java | 73 ++++++++++++++++++- 4 files changed, 82 insertions(+), 6 deletions(-) diff --git a/src/org/mcteam/factions/Conf.java b/src/org/mcteam/factions/Conf.java index 48c76661..ec5ee21a 100644 --- a/src/org/mcteam/factions/Conf.java +++ b/src/org/mcteam/factions/Conf.java @@ -64,7 +64,7 @@ public class Conf { public static transient Set safeZoneNerfedCreatureTypes = new HashSet(); public static transient int mapHeight = 8; - public static transient int mapWidth = 49; + public static transient int mapWidth = 39; static { territoryProtectedMaterials.add(Material.WOODEN_DOOR); diff --git a/src/org/mcteam/factions/FPlayer.java b/src/org/mcteam/factions/FPlayer.java index 76ac13e3..1f3598a1 100644 --- a/src/org/mcteam/factions/FPlayer.java +++ b/src/org/mcteam/factions/FPlayer.java @@ -370,11 +370,14 @@ public class FPlayer { sendMessage("You must give the admin role to someone else first."); return; } - - myFaction.sendMessage(this.getNameAndRelevant(myFaction) + Conf.colorSystem + " left your faction."); + + if (myFaction.isNormal()) { + myFaction.sendMessage(this.getNameAndRelevant(myFaction) + Conf.colorSystem + " left your faction."); + } + this.resetFactionData(); - - if (myFaction.getFPlayers().size() == 0) { + + if (myFaction.isNormal() && myFaction.getFPlayers().size() == 0) { // Remove this faction for (FPlayer fplayer : FPlayer.getAllOnline()) { fplayer.sendMessage("The faction "+myFaction.getTag(fplayer)+Conf.colorSystem+" was disbanded."); diff --git a/src/org/mcteam/factions/Factions.java b/src/org/mcteam/factions/Factions.java index 9c07e0c1..0120685a 100644 --- a/src/org/mcteam/factions/Factions.java +++ b/src/org/mcteam/factions/Factions.java @@ -151,6 +151,8 @@ public class Factions extends JavaPlugin { pm.registerEvent(Event.Type.ENTITY_EXPLODE, this.entityListener, Event.Priority.Normal, this); pm.registerEvent(Event.Type.CREATURE_SPAWN, this.entityListener, Event.Priority.Normal, this); pm.registerEvent(Event.Type.ENTITY_TARGET, this.entityListener, Event.Priority.Normal, this); + pm.registerEvent(Event.Type.PAINTING_BREAK, this.entityListener, Event.Priority.Normal, this); + pm.registerEvent(Event.Type.PAINTING_PLACE, this.entityListener, Event.Priority.Normal, this); pm.registerEvent(Event.Type.BLOCK_BREAK, this.blockListener, Event.Priority.Normal, this); pm.registerEvent(Event.Type.BLOCK_DAMAGE, this.blockListener, Event.Priority.Normal, this); pm.registerEvent(Event.Type.BLOCK_PLACE, this.blockListener, Event.Priority.Normal, this); diff --git a/src/org/mcteam/factions/listeners/FactionsEntityListener.java b/src/org/mcteam/factions/listeners/FactionsEntityListener.java index 74d199d0..7599d67b 100644 --- a/src/org/mcteam/factions/listeners/FactionsEntityListener.java +++ b/src/org/mcteam/factions/listeners/FactionsEntityListener.java @@ -15,8 +15,12 @@ import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityListener; import org.bukkit.event.entity.EntityTargetEvent; +import org.bukkit.event.painting.PaintingBreakByEntityEvent; +import org.bukkit.event.painting.PaintingBreakEvent; +import org.bukkit.event.painting.PaintingPlaceEvent; import org.mcteam.factions.Board; import org.mcteam.factions.Conf; +import org.mcteam.factions.Factions; import org.mcteam.factions.FLocation; import org.mcteam.factions.FPlayer; import org.mcteam.factions.Faction; @@ -96,7 +100,7 @@ public class FactionsEntityListener extends EntityListener { Entity damagee = sub.getEntity(); int damage = sub.getDamage(); - if ( ! (damagee instanceof Player)) { + if ( ! (damagee instanceof Player) || damagee.getLocation() == null) { return true; } @@ -182,4 +186,71 @@ public class FactionsEntityListener extends EntityListener { event.setCancelled(true); } } + + @Override + public void onPaintingBreak(PaintingBreakEvent event) + { + if (event.isCancelled()) { + return; + } + if (! (event instanceof PaintingBreakByEntityEvent)) { + return; + } + + Entity breaker = ((PaintingBreakByEntityEvent)event).getRemover(); + if (! (breaker instanceof Player)) { + return; + } + + FLocation loc = new FLocation(event.getPainting().getLocation()); + + if ( ! this.playerCanDoPaintings((Player)breaker, loc, "remove")) { + event.setCancelled(true); + } + } + + @Override + public void onPaintingPlace(PaintingPlaceEvent event) + { + if (event.isCancelled()) { + return; + } + + if ( ! this.playerCanDoPaintings(event.getPlayer(), new FLocation(event.getBlock()), "place")) { + event.setCancelled(true); + } + } + + public boolean playerCanDoPaintings(Player player, FLocation loc, String action) { + + if (Conf.adminBypassPlayers.contains(player.getName())) { + return true; + } + + Faction otherFaction = Board.getFactionAt(loc); + + if (otherFaction.isNone()) { + return true; + } + + FPlayer me = FPlayer.get(player); + + if (otherFaction.isSafeZone()) { + if (Factions.hasPermManageSafeZone(player) || !Conf.safeZoneDenyBuild) { + return true; + } + me.sendMessage("You can't "+action+" paintings in a safe zone."); + return false; + } + + Faction myFaction = me.getFaction(); + + // Cancel if we are not in our own territory + if (myFaction != otherFaction) { + me.sendMessage("You can't "+action+" paintings in the territory of "+otherFaction.getTag(myFaction)); + return false; + } + + return true; + } }