From 9314b4e298de7526ae6b14f4261b46a492c7ba24 Mon Sep 17 00:00:00 2001 From: donington Date: Sun, 11 Mar 2012 13:28:31 -0400 Subject: [PATCH] Updated Faction Event System -- Land Events Changes: ---------- * changed internal storage of faction from String Id to Faction for LandClaimEvent and LandUnclaimEvent * added getFactionId(), getFactionTag(), getPlayer() to LandClaimEvent * added getFactionId(), getFactionTag(), getFPlayer(), getPlayer() to LandUnclaimEvent * removed LandUnclaimEvent from unclaimAll() in Board.java * created LandUnclaimAllEvent (uncancellable) and hooked into cmdUnclaimall Notes: -------- * LandUnclaimAllEvent currently only returns calling faction and fplayer information. Location data is unavailable as it is determined in Board.java's unclaimAll(). Realistically this should be enough information for anyone hooking this event to determine what is being altered. On branch CustomFactionEvents modified: src/com/massivecraft/factions/Board.java modified: src/com/massivecraft/factions/FPlayer.java modified: src/com/massivecraft/factions/cmd/CmdUnclaim.java modified: src/com/massivecraft/factions/cmd/CmdUnclaimall.java modified: src/com/massivecraft/factions/event/LandClaimEvent.java new file: src/com/massivecraft/factions/event/LandUnclaimAllEvent.java modified: src/com/massivecraft/factions/event/LandUnclaimEvent.java --- src/com/massivecraft/factions/Board.java | 7 -- src/com/massivecraft/factions/FPlayer.java | 2 +- .../massivecraft/factions/cmd/CmdUnclaim.java | 4 +- .../factions/cmd/CmdUnclaimall.java | 7 ++ .../factions/event/LandClaimEvent.java | 47 ++++++++----- .../factions/event/LandUnclaimAllEvent.java | 68 +++++++++++++++++++ .../factions/event/LandUnclaimEvent.java | 45 +++++++++--- 7 files changed, 143 insertions(+), 37 deletions(-) create mode 100755 src/com/massivecraft/factions/event/LandUnclaimAllEvent.java diff --git a/src/com/massivecraft/factions/Board.java b/src/com/massivecraft/factions/Board.java index fbefd2f7..f10eaf18 100644 --- a/src/com/massivecraft/factions/Board.java +++ b/src/com/massivecraft/factions/Board.java @@ -9,13 +9,11 @@ import java.util.Map; import java.util.Map.Entry; import java.util.TreeMap; -import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.block.Block; import com.google.gson.reflect.TypeToken; -import com.massivecraft.factions.event.LandUnclaimEvent; import com.massivecraft.factions.integration.LWCFeatures; import com.massivecraft.factions.iface.RelationParticipator; import com.massivecraft.factions.util.AsciiCompass; @@ -84,15 +82,10 @@ public class Board Entry entry = iter.next(); if (entry.getValue().equals(factionId)) { - LandUnclaimEvent unclaimEvent = new LandUnclaimEvent(entry.getKey(), entry.getValue()); - Bukkit.getServer().getPluginManager().callEvent(unclaimEvent); - if(!unclaimEvent.isCancelled()) - { if(Conf.onUnclaimResetLwcLocks && LWCFeatures.getEnabled()) LWCFeatures.clearAllChests(entry.getKey()); iter.remove(); - } } } } diff --git a/src/com/massivecraft/factions/FPlayer.java b/src/com/massivecraft/factions/FPlayer.java index 1ddbd6a3..fd239cd1 100644 --- a/src/com/massivecraft/factions/FPlayer.java +++ b/src/com/massivecraft/factions/FPlayer.java @@ -664,7 +664,7 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator } } - LandClaimEvent claimEvent = new LandClaimEvent(flocation, forFaction.getId(), this.getId()); + LandClaimEvent claimEvent = new LandClaimEvent(flocation, forFaction, this); Bukkit.getServer().getPluginManager().callEvent(claimEvent); if(claimEvent.isCancelled()) return false; diff --git a/src/com/massivecraft/factions/cmd/CmdUnclaim.java b/src/com/massivecraft/factions/cmd/CmdUnclaim.java index 8a9a1b37..1f008c10 100644 --- a/src/com/massivecraft/factions/cmd/CmdUnclaim.java +++ b/src/com/massivecraft/factions/cmd/CmdUnclaim.java @@ -55,8 +55,8 @@ public class CmdUnclaim extends FCommand } } - LandUnclaimEvent unclaimEvent = new LandUnclaimEvent(flocation, otherFaction.getId()); - Bukkit.getServer().getPluginManager().callEvent(unclaimEvent); + LandUnclaimEvent unclaimEvent = new LandUnclaimEvent(flocation, otherFaction, fme); + Bukkit.getServer().getPluginManager().callEvent(unclaimEvent); if(unclaimEvent.isCancelled()) return; Board.removeAt(flocation); diff --git a/src/com/massivecraft/factions/cmd/CmdUnclaimall.java b/src/com/massivecraft/factions/cmd/CmdUnclaimall.java index c469190a..850ca5e2 100644 --- a/src/com/massivecraft/factions/cmd/CmdUnclaimall.java +++ b/src/com/massivecraft/factions/cmd/CmdUnclaimall.java @@ -1,8 +1,11 @@ package com.massivecraft.factions.cmd; +import org.bukkit.Bukkit; + import com.massivecraft.factions.Board; import com.massivecraft.factions.Conf; import com.massivecraft.factions.P; +import com.massivecraft.factions.event.LandUnclaimAllEvent; import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.factions.struct.Permission; @@ -42,6 +45,10 @@ public class CmdUnclaimall extends FCommand } } + LandUnclaimAllEvent unclaimAllEvent = new LandUnclaimAllEvent(myFaction, fme); + Bukkit.getServer().getPluginManager().callEvent(unclaimAllEvent); + // this event cannot be cancelled + Board.unclaimAll(myFaction.getId()); myFaction.msg("%s unclaimed ALL of your faction's land.", fme.describeTo(myFaction, true)); SpoutFeatures.updateTerritoryDisplayLoc(null); diff --git a/src/com/massivecraft/factions/event/LandClaimEvent.java b/src/com/massivecraft/factions/event/LandClaimEvent.java index b1216bd8..041e5cad 100644 --- a/src/com/massivecraft/factions/event/LandClaimEvent.java +++ b/src/com/massivecraft/factions/event/LandClaimEvent.java @@ -5,10 +5,9 @@ import org.bukkit.event.Event; import org.bukkit.event.HandlerList; import com.massivecraft.factions.FLocation; -import com.massivecraft.factions.FPlayer; -import com.massivecraft.factions.FPlayers; import com.massivecraft.factions.Faction; -import com.massivecraft.factions.Factions; +import com.massivecraft.factions.FPlayer; +import org.bukkit.entity.Player; public class LandClaimEvent extends Event implements Cancellable { @@ -16,14 +15,15 @@ public class LandClaimEvent extends Event implements Cancellable private boolean cancelled; private FLocation location; - private String factionId, playerId; + private Faction faction; + private FPlayer fplayer; - public LandClaimEvent(FLocation loc, String fid, String pid) + public LandClaimEvent(FLocation loc, Faction f, FPlayer p) { cancelled = false; location = loc; - this.factionId = fid; - this.playerId = pid; + faction = f; + fplayer = p; } public HandlerList getHandlers() @@ -36,19 +36,34 @@ public class LandClaimEvent extends Event implements Cancellable return handlers; } - public FPlayer getFPlayer() - { - return FPlayers.i.get(playerId); - } - public FLocation getLocation() - { - return this.location; - } + { + return this.location; + } public Faction getFaction() { - return Factions.i.get(factionId); + return faction; + } + + public String getFactionId() + { + return faction.getId(); + } + + public String getFactionTag() + { + return faction.getTag(); + } + + public FPlayer getFPlayer() + { + return fplayer; + } + + public Player getPlayer() + { + return fplayer.getPlayer(); } @Override diff --git a/src/com/massivecraft/factions/event/LandUnclaimAllEvent.java b/src/com/massivecraft/factions/event/LandUnclaimAllEvent.java new file mode 100755 index 00000000..d6d115d4 --- /dev/null +++ b/src/com/massivecraft/factions/event/LandUnclaimAllEvent.java @@ -0,0 +1,68 @@ +package com.massivecraft.factions.event; + +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +//import com.massivecraft.factions.FLocation; +import com.massivecraft.factions.Faction; +import com.massivecraft.factions.FPlayer; +import org.bukkit.entity.Player; + +public class LandUnclaimAllEvent extends Event +{ + private static final HandlerList handlers = new HandlerList(); + + // Location is commented out because there is no clean way to hook currently. + // faction and fplayer should be enough to filter needed information. + // private FLocation[] location; + private Faction faction; + private FPlayer fplayer; + + public LandUnclaimAllEvent(Faction f, FPlayer p) + { + faction = f; + fplayer = p; + } + + public HandlerList getHandlers() + { + return handlers; + } + + public static HandlerList getHandlerList() + { + return handlers; + } + +/* + public FLocation getLocation() + { + return this.location; + } + */ + + public Faction getFaction() + { + return faction; + } + + public String getFactionId() + { + return faction.getId(); + } + + public String getFactionTag() + { + return faction.getTag(); + } + + public FPlayer getFPlayer() + { + return fplayer; + } + + public Player getPlayer() + { + return fplayer.getPlayer(); + } +} diff --git a/src/com/massivecraft/factions/event/LandUnclaimEvent.java b/src/com/massivecraft/factions/event/LandUnclaimEvent.java index e1eba2bd..fb7bc1fd 100644 --- a/src/com/massivecraft/factions/event/LandUnclaimEvent.java +++ b/src/com/massivecraft/factions/event/LandUnclaimEvent.java @@ -6,21 +6,24 @@ import org.bukkit.event.HandlerList; import com.massivecraft.factions.FLocation; import com.massivecraft.factions.Faction; -import com.massivecraft.factions.Factions; +import com.massivecraft.factions.FPlayer; +import org.bukkit.entity.Player; public class LandUnclaimEvent extends Event implements Cancellable { private static final HandlerList handlers = new HandlerList(); private boolean cancelled; - private String factionId; - private FLocation location; + private FLocation location; + private Faction faction; + private FPlayer fplayer; - public LandUnclaimEvent(FLocation loc, String id) + public LandUnclaimEvent(FLocation loc, Faction f, FPlayer p) { cancelled = false; location = loc; - factionId = id; + faction = f; + fplayer = p; } public HandlerList getHandlers() @@ -33,16 +36,36 @@ public class LandUnclaimEvent extends Event implements Cancellable return handlers; } - public Faction getFaction() - { - return Factions.i.get(factionId); - } - public FLocation getLocation() { - return this.location; + return this.location; } + public Faction getFaction() + { + return faction; + } + + public String getFactionId() + { + return faction.getId(); + } + + public String getFactionTag() + { + return faction.getTag(); + } + + public FPlayer getFPlayer() + { + return fplayer; + } + + public Player getPlayer() + { + return fplayer.getPlayer(); + } + @Override public boolean isCancelled() {