From 021bf52c62a5f03bba68c998e7bee7299502df77 Mon Sep 17 00:00:00 2001 From: patrickfreed Date: Thu, 1 Mar 2012 20:16:45 -0500 Subject: [PATCH 1/3] Added Event System --- src/com/massivecraft/factions/Board.java | 13 +++- src/com/massivecraft/factions/FPlayer.java | 15 +++- .../massivecraft/factions/cmd/CmdCreate.java | 12 ++++ .../massivecraft/factions/cmd/CmdDisband.java | 9 +++ .../massivecraft/factions/cmd/CmdJoin.java | 18 +++++ .../massivecraft/factions/cmd/CmdKick.java | 7 ++ .../massivecraft/factions/cmd/CmdLeader.java | 7 ++ .../massivecraft/factions/cmd/CmdUnclaim.java | 9 ++- .../factions/event/FPlayerJoinEvent.java | 60 ++++++++++++++++ .../factions/event/FPlayerLeaveEvent.java | 71 +++++++++++++++++++ .../factions/event/FactionCreateEvent.java | 57 +++++++++++++++ .../factions/event/FactionDisbandEvent.java | 64 +++++++++++++++++ .../factions/event/LandClaimEvent.java | 66 +++++++++++++++++ .../factions/event/LandUnclaimEvent.java | 56 +++++++++++++++ 14 files changed, 458 insertions(+), 6 deletions(-) create mode 100644 src/com/massivecraft/factions/event/FPlayerJoinEvent.java create mode 100644 src/com/massivecraft/factions/event/FPlayerLeaveEvent.java create mode 100644 src/com/massivecraft/factions/event/FactionCreateEvent.java create mode 100644 src/com/massivecraft/factions/event/FactionDisbandEvent.java create mode 100644 src/com/massivecraft/factions/event/LandClaimEvent.java create mode 100644 src/com/massivecraft/factions/event/LandUnclaimEvent.java diff --git a/src/com/massivecraft/factions/Board.java b/src/com/massivecraft/factions/Board.java index 37bb6011..fbefd2f7 100644 --- a/src/com/massivecraft/factions/Board.java +++ b/src/com/massivecraft/factions/Board.java @@ -9,11 +9,13 @@ 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; @@ -82,10 +84,15 @@ public class Board Entry entry = iter.next(); if (entry.getValue().equals(factionId)) { - if(Conf.onUnclaimResetLwcLocks && LWCFeatures.getEnabled()) - LWCFeatures.clearAllChests(entry.getKey()); + 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(); + iter.remove(); + } } } } diff --git a/src/com/massivecraft/factions/FPlayer.java b/src/com/massivecraft/factions/FPlayer.java index e000c5f0..1ddbd6a3 100644 --- a/src/com/massivecraft/factions/FPlayer.java +++ b/src/com/massivecraft/factions/FPlayer.java @@ -3,10 +3,13 @@ package com.massivecraft.factions; import java.util.HashSet; import java.util.Set; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.entity.Player; +import com.massivecraft.factions.event.FPlayerLeaveEvent; +import com.massivecraft.factions.event.LandClaimEvent; import com.massivecraft.factions.iface.EconomyParticipator; import com.massivecraft.factions.iface.RelationParticipator; import com.massivecraft.factions.integration.Econ; @@ -507,7 +510,11 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator double cost = Conf.econCostLeave; if ( ! Econ.modifyMoney(this, -cost, "to leave your faction.", "for leaving your faction.")) return; } - + + FPlayerLeaveEvent leaveEvent = new FPlayerLeaveEvent(this,myFaction,FPlayerLeaveEvent.PlayerLeaveReason.LEAVE); + Bukkit.getServer().getPluginManager().callEvent(leaveEvent); + if (leaveEvent.isCancelled()) return; + // Am I the last one in the faction? if (myFaction.getFPlayers().size() == 1) { @@ -656,7 +663,11 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator } } - + + LandClaimEvent claimEvent = new LandClaimEvent(flocation, forFaction.getId(), this.getId()); + Bukkit.getServer().getPluginManager().callEvent(claimEvent); + if(claimEvent.isCancelled()) return false; + if (LWCFeatures.getEnabled() && forFaction.isNormal() && Conf.onCaptureResetLwcLocks) LWCFeatures.clearOtherChests(flocation, this.getFaction()); diff --git a/src/com/massivecraft/factions/cmd/CmdCreate.java b/src/com/massivecraft/factions/cmd/CmdCreate.java index 36ebfbdb..dd18e005 100644 --- a/src/com/massivecraft/factions/cmd/CmdCreate.java +++ b/src/com/massivecraft/factions/cmd/CmdCreate.java @@ -2,12 +2,16 @@ package com.massivecraft.factions.cmd; import java.util.ArrayList; +import org.bukkit.Bukkit; + import com.massivecraft.factions.Conf; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayers; import com.massivecraft.factions.Faction; import com.massivecraft.factions.Factions; import com.massivecraft.factions.P; +import com.massivecraft.factions.event.FPlayerJoinEvent; +import com.massivecraft.factions.event.FactionCreateEvent; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Rel; @@ -54,6 +58,11 @@ public class CmdCreate extends FCommand return; } + FactionCreateEvent createEvent = new FactionCreateEvent(tag, me); + Bukkit.getServer().getPluginManager().callEvent(createEvent); + + if(createEvent.isCancelled()) return; + // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay if ( ! payForCommand(Conf.econCostCreate, "to create a new faction", "for creating a new faction")) return; @@ -66,6 +75,9 @@ public class CmdCreate extends FCommand return; } + FPlayerJoinEvent joinEvent = new FPlayerJoinEvent(FPlayers.i.get(me),faction,FPlayerJoinEvent.PlayerJoinReason.CREATE); + Bukkit.getServer().getPluginManager().callEvent(joinEvent); + faction.setTag(tag); fme.setRole(Rel.LEADER); fme.setFaction(faction); diff --git a/src/com/massivecraft/factions/cmd/CmdDisband.java b/src/com/massivecraft/factions/cmd/CmdDisband.java index be3ef4ef..a1c4fa52 100644 --- a/src/com/massivecraft/factions/cmd/CmdDisband.java +++ b/src/com/massivecraft/factions/cmd/CmdDisband.java @@ -1,6 +1,10 @@ package com.massivecraft.factions.cmd; +import org.bukkit.Bukkit; + import com.massivecraft.factions.Conf; +import com.massivecraft.factions.event.FPlayerLeaveEvent; +import com.massivecraft.factions.event.FactionDisbandEvent; import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.FPlayers; import com.massivecraft.factions.Faction; @@ -45,12 +49,17 @@ public class CmdDisband extends FCommand return; } + FactionDisbandEvent disbandEvent = new FactionDisbandEvent(me, faction.getId()); + Bukkit.getServer().getPluginManager().callEvent(disbandEvent); + if(disbandEvent.isCancelled()) return; + // Inform all players for (FPlayer fplayer : FPlayers.i.getOnline()) { String who = senderIsConsole ? "A server admin" : fme.describeTo(fplayer); if (fplayer.getFaction() == faction) { + Bukkit.getServer().getPluginManager().callEvent(new FPlayerLeaveEvent(fplayer,faction, FPlayerLeaveEvent.PlayerLeaveReason.DISBAND)); fplayer.msg("%s disbanded your faction.", who); } else diff --git a/src/com/massivecraft/factions/cmd/CmdJoin.java b/src/com/massivecraft/factions/cmd/CmdJoin.java index d9a582ea..79bd1e4c 100644 --- a/src/com/massivecraft/factions/cmd/CmdJoin.java +++ b/src/com/massivecraft/factions/cmd/CmdJoin.java @@ -1,10 +1,16 @@ package com.massivecraft.factions.cmd; +import org.bukkit.Bukkit; + import com.massivecraft.factions.Conf; +import com.massivecraft.factions.FPlayers; import com.massivecraft.factions.Faction; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.P; +import com.massivecraft.factions.event.FPlayerJoinEvent; +import com.massivecraft.factions.event.FPlayerLeaveEvent; import com.massivecraft.factions.struct.Permission; +import com.massivecraft.factions.zcore.persist.EM; public class CmdJoin extends FCommand { @@ -76,6 +82,18 @@ public class CmdJoin extends FCommand if (samePlayer && ! payForCommand(Conf.econCostJoin, "to join a faction", "for joining a faction")) return; fme.msg("%s successfully joined %s.", fplayer.describeTo(fme, true), faction.getTag(fme)); + + if(!EM.detached(myFaction)) + { + FPlayerLeaveEvent leaveEvent = new FPlayerLeaveEvent(FPlayers.i.get(me),faction,FPlayerLeaveEvent.PlayerLeaveReason.JOINOTHER); + Bukkit.getServer().getPluginManager().callEvent(leaveEvent); + if (leaveEvent.isCancelled()) return; + } + + FPlayerJoinEvent joinEvent = new FPlayerJoinEvent(FPlayers.i.get(me),faction,FPlayerJoinEvent.PlayerJoinReason.COMMAND); + Bukkit.getServer().getPluginManager().callEvent(joinEvent); + if (joinEvent.isCancelled()) return; + if (!samePlayer) fplayer.msg("%s moved you into the faction %s.", fme.describeTo(fplayer, true), faction.getTag(fplayer)); faction.msg("%s joined your faction.", fplayer.describeTo(faction, true)); diff --git a/src/com/massivecraft/factions/cmd/CmdKick.java b/src/com/massivecraft/factions/cmd/CmdKick.java index 094b9d66..7c27f683 100644 --- a/src/com/massivecraft/factions/cmd/CmdKick.java +++ b/src/com/massivecraft/factions/cmd/CmdKick.java @@ -1,9 +1,12 @@ package com.massivecraft.factions.cmd; +import org.bukkit.Bukkit; + import com.massivecraft.factions.Conf; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.Faction; import com.massivecraft.factions.P; +import com.massivecraft.factions.event.FPlayerLeaveEvent; import com.massivecraft.factions.struct.FPerm; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Rel; @@ -60,6 +63,10 @@ public class CmdKick extends FCommand // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay if ( ! payForCommand(Conf.econCostKick, "to kick someone from the faction", "for kicking someone from the faction")) return; + FPlayerLeaveEvent event = new FPlayerLeaveEvent(you, you.getFaction(), FPlayerLeaveEvent.PlayerLeaveReason.KICKED); + Bukkit.getServer().getPluginManager().callEvent(event); + if (event.isCancelled()) return; + yourFaction.msg("%s kicked %s from the faction! :O", fme.describeTo(yourFaction, true), you.describeTo(yourFaction, true)); you.msg("%s kicked you from %s! :O", fme.describeTo(you, true), yourFaction.describeTo(you)); if (yourFaction != myFaction) diff --git a/src/com/massivecraft/factions/cmd/CmdLeader.java b/src/com/massivecraft/factions/cmd/CmdLeader.java index 7203907f..3068a9f3 100644 --- a/src/com/massivecraft/factions/cmd/CmdLeader.java +++ b/src/com/massivecraft/factions/cmd/CmdLeader.java @@ -1,8 +1,11 @@ package com.massivecraft.factions.cmd; +import org.bukkit.Bukkit; + import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayers; import com.massivecraft.factions.Faction; +import com.massivecraft.factions.event.FPlayerJoinEvent; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Rel; import com.massivecraft.factions.util.RelationUtil; @@ -64,6 +67,10 @@ public class CmdLeader extends FCommand } } + FPlayerJoinEvent event = new FPlayerJoinEvent(FPlayers.i.get(me),targetFaction,FPlayerJoinEvent.PlayerJoinReason.LEADER); + Bukkit.getServer().getPluginManager().callEvent(event); + if (event.isCancelled()) return; + // if target player is currently leader, demote and replace him if (targetFactionCurrentLeader == newLeader) { diff --git a/src/com/massivecraft/factions/cmd/CmdUnclaim.java b/src/com/massivecraft/factions/cmd/CmdUnclaim.java index 1f3583c9..8a9a1b37 100644 --- a/src/com/massivecraft/factions/cmd/CmdUnclaim.java +++ b/src/com/massivecraft/factions/cmd/CmdUnclaim.java @@ -1,7 +1,10 @@ package com.massivecraft.factions.cmd; +import org.bukkit.Bukkit; + import com.massivecraft.factions.Board; import com.massivecraft.factions.Conf; +import com.massivecraft.factions.event.LandUnclaimEvent; import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.factions.FLocation; @@ -36,7 +39,7 @@ public class CmdUnclaim extends FCommand Faction otherFaction = Board.getFactionAt(flocation); if ( ! FPerm.TERRITORY.has(sender, otherFaction, true)) return; - + //String moneyBack = ""; if (Econ.shouldBeUsed()) { @@ -52,6 +55,10 @@ public class CmdUnclaim extends FCommand } } + LandUnclaimEvent unclaimEvent = new LandUnclaimEvent(flocation, otherFaction.getId()); + Bukkit.getServer().getPluginManager().callEvent(unclaimEvent); + if(unclaimEvent.isCancelled()) return; + Board.removeAt(flocation); SpoutFeatures.updateTerritoryDisplayLoc(flocation); myFaction.msg("%s unclaimed some land.", fme.describeTo(myFaction, true)); diff --git a/src/com/massivecraft/factions/event/FPlayerJoinEvent.java b/src/com/massivecraft/factions/event/FPlayerJoinEvent.java new file mode 100644 index 00000000..8510d00c --- /dev/null +++ b/src/com/massivecraft/factions/event/FPlayerJoinEvent.java @@ -0,0 +1,60 @@ +package com.massivecraft.factions.event; + +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +import com.massivecraft.factions.FPlayer; +import com.massivecraft.factions.Faction; + +public class FPlayerJoinEvent extends Event implements Cancellable +{ + private static final HandlerList handlers = new HandlerList(); + + FPlayer fplayer; + Faction faction; + PlayerJoinReason reason; + boolean cancelled = false; + public enum PlayerJoinReason + { + CREATE, LEADER, COMMAND + } + public FPlayerJoinEvent(FPlayer fp, Faction f, PlayerJoinReason r) + { + fplayer = fp; + faction = f; + reason = r; + } + + public FPlayer getFPlayer() + { + return fplayer; + } + public Faction getFaction() + { + return faction; + } + public PlayerJoinReason getReason() + { + return reason; + } + public HandlerList getHandlers() + { + return handlers; + } + + public static HandlerList getHandlerList() + { + return handlers; + } + @Override + public boolean isCancelled() + { + return cancelled; + } + @Override + public void setCancelled(boolean c) + { + cancelled = c; + } +} \ No newline at end of file diff --git a/src/com/massivecraft/factions/event/FPlayerLeaveEvent.java b/src/com/massivecraft/factions/event/FPlayerLeaveEvent.java new file mode 100644 index 00000000..167933f0 --- /dev/null +++ b/src/com/massivecraft/factions/event/FPlayerLeaveEvent.java @@ -0,0 +1,71 @@ +package com.massivecraft.factions.event; + +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +import com.massivecraft.factions.FPlayer; +import com.massivecraft.factions.Faction; + +public class FPlayerLeaveEvent extends Event implements Cancellable +{ + private static final HandlerList handlers = new HandlerList(); + private PlayerLeaveReason reason; + FPlayer FPlayer; + Faction Faction; + boolean cancelled = false; + + public enum PlayerLeaveReason + { + KICKED, DISBAND, RESET, JOINOTHER, LEAVE + } + + public FPlayerLeaveEvent(FPlayer p, Faction f, PlayerLeaveReason r) + { + FPlayer = p; + Faction = f; + reason = r; + } + + public HandlerList getHandlers() + { + return handlers; + } + + public static HandlerList getHandlerList() + { + return handlers; + } + + public PlayerLeaveReason getReason() + { + return reason; + } + + public FPlayer getFPlayer() + { + return FPlayer; + } + + public Faction getFaction() + { + return Faction; + } + + @Override + public boolean isCancelled() + { + return cancelled; + } + + @Override + public void setCancelled(boolean c) + { + if (reason == PlayerLeaveReason.DISBAND || reason == PlayerLeaveReason.RESET) + { + cancelled = false; + return; + } + cancelled = c; + } +} \ No newline at end of file diff --git a/src/com/massivecraft/factions/event/FactionCreateEvent.java b/src/com/massivecraft/factions/event/FactionCreateEvent.java new file mode 100644 index 00000000..0f9a66bd --- /dev/null +++ b/src/com/massivecraft/factions/event/FactionCreateEvent.java @@ -0,0 +1,57 @@ +package com.massivecraft.factions.event; + +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +import com.massivecraft.factions.FPlayer; +import com.massivecraft.factions.FPlayers; + +public class FactionCreateEvent extends Event implements Cancellable +{ + private static final HandlerList handlers = new HandlerList(); + + private String factionTag; + private Player sender; + private boolean cancelled; + + public FactionCreateEvent(String tag, Player sender) + { + this.factionTag = tag; + this.sender = sender; + this.cancelled = false; + } + + public FPlayer getFPlayer() + { + return FPlayers.i.get(sender); + } + + public String getFactionTag() + { + return factionTag; + } + + public HandlerList getHandlers() + { + return handlers; + } + + public static HandlerList getHandlerList() + { + return handlers; + } + + @Override + public boolean isCancelled() + { + return cancelled; + } + + @Override + public void setCancelled(boolean c) + { + this.cancelled = c; + } +} \ No newline at end of file diff --git a/src/com/massivecraft/factions/event/FactionDisbandEvent.java b/src/com/massivecraft/factions/event/FactionDisbandEvent.java new file mode 100644 index 00000000..ccf155da --- /dev/null +++ b/src/com/massivecraft/factions/event/FactionDisbandEvent.java @@ -0,0 +1,64 @@ +package com.massivecraft.factions.event; + +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +import com.massivecraft.factions.FPlayer; +import com.massivecraft.factions.FPlayers; +import com.massivecraft.factions.Faction; +import com.massivecraft.factions.Factions; + +public class FactionDisbandEvent extends Event implements Cancellable +{ + private static final HandlerList handlers = new HandlerList(); + + private boolean cancelled; + private String id; + private Player sender; + + public FactionDisbandEvent(Player sender, String factionId) + { + cancelled = false; + this.sender = sender; + this.id = factionId; + } + + public HandlerList getHandlers() + { + return handlers; + } + + public static HandlerList getHandlerList() + { + return handlers; + } + + public Faction getFaction() + { + return Factions.i.get(id); + } + + public FPlayer getFPlayer() + { + return FPlayers.i.get(sender); + } + + public Player getPlayer() + { + return sender; + } + + @Override + public boolean isCancelled() + { + return cancelled; + } + + @Override + public void setCancelled(boolean c) + { + cancelled = c; + } +} diff --git a/src/com/massivecraft/factions/event/LandClaimEvent.java b/src/com/massivecraft/factions/event/LandClaimEvent.java new file mode 100644 index 00000000..4d27ce9a --- /dev/null +++ b/src/com/massivecraft/factions/event/LandClaimEvent.java @@ -0,0 +1,66 @@ +package com.massivecraft.factions.event; + +import org.bukkit.event.Cancellable; +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; + +public class LandClaimEvent extends Event implements Cancellable +{ + private static final HandlerList handlers = new HandlerList(); + + private boolean cancelled; + private FLocation location; + private String factionId, playerId; + + public LandClaimEvent(FLocation loc, String id, String pid) + { + cancelled = false; + location = loc; + factionId = id; + playerId = pid; + } + + public HandlerList getHandlers() + { + return handlers; + } + + public static HandlerList getHandlerList() + { + return handlers; + } + + public FPlayer getFPlayer() + { + return FPlayers.i.get(playerId); + } + + public FLocation getLocation() + { + return this.location; + } + + public Faction getFaction() + { + return Factions.i.get(factionId); + } + + @Override + public boolean isCancelled() + { + return cancelled; + } + + @Override + public void setCancelled(boolean c) + { + this.cancelled = c; + } + +} diff --git a/src/com/massivecraft/factions/event/LandUnclaimEvent.java b/src/com/massivecraft/factions/event/LandUnclaimEvent.java new file mode 100644 index 00000000..e1eba2bd --- /dev/null +++ b/src/com/massivecraft/factions/event/LandUnclaimEvent.java @@ -0,0 +1,56 @@ +package com.massivecraft.factions.event; + +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +import com.massivecraft.factions.FLocation; +import com.massivecraft.factions.Faction; +import com.massivecraft.factions.Factions; + +public class LandUnclaimEvent extends Event implements Cancellable +{ + private static final HandlerList handlers = new HandlerList(); + + private boolean cancelled; + private String factionId; + private FLocation location; + + public LandUnclaimEvent(FLocation loc, String id) + { + cancelled = false; + location = loc; + factionId = id; + } + + public HandlerList getHandlers() + { + return handlers; + } + + public static HandlerList getHandlerList() + { + return handlers; + } + + public Faction getFaction() + { + return Factions.i.get(factionId); + } + + public FLocation getLocation() + { + return this.location; + } + + @Override + public boolean isCancelled() + { + return cancelled; + } + + @Override + public void setCancelled(boolean c) { + cancelled = c; + } +} From 6329fd0eaf4e4a406e59c669d66b3741f6235643 Mon Sep 17 00:00:00 2001 From: donington Date: Fri, 9 Mar 2012 17:09:33 -0500 Subject: [PATCH 2/3] updated patrickfreed's custom event system Patrick's Custom Event System Changes: ---------------------------------------- * FPlayerLeaveEvent now fires for all faction players in cmdDisband() * FPlayerLeaveEvent removed from cmdJoin() * FPlayerJoinEvent now only fires when the faction is different in cmdLeade * Added FactionRenameEvent, firing on cmdTag() * Added FactionRelationEvent, firing on FRelationCommand extensions * Fixed FPlayerJoinEvent to fire after tag is set in cmdCreate() * Added getFactionId() to FactionCreateEvent TODO: ------- * cmdLeader() might need a FPlayerLeaveEvent for the same reason it needs a FPlayerJoinEvent? On branch CustomFactionEvents modified: src/com/massivecraft/factions/cmd/CmdCreate.java modified: src/com/massivecraft/factions/cmd/CmdDisband.java modified: src/com/massivecraft/factions/cmd/CmdJoin.java modified: src/com/massivecraft/factions/cmd/CmdKick.java modified: src/com/massivecraft/factions/cmd/CmdLeader.java modified: src/com/massivecraft/factions/cmd/CmdTag.java modified: src/com/massivecraft/factions/cmd/FRelationCommand.java modified: src/com/massivecraft/factions/event/FPlayerLeaveEvent.java modified: src/com/massivecraft/factions/event/FactionCreateEvent.java new file: src/com/massivecraft/factions/event/FactionRelationEvent.java new file: src/com/massivecraft/factions/event/FactionRenameEvent.java modified: src/com/massivecraft/factions/event/LandClaimEvent.java --- .../massivecraft/factions/cmd/CmdCreate.java | 19 +- .../massivecraft/factions/cmd/CmdDisband.java | 187 +++++++++--------- .../massivecraft/factions/cmd/CmdJoin.java | 12 +- .../massivecraft/factions/cmd/CmdKick.java | 1 + .../massivecraft/factions/cmd/CmdLeader.java | 15 +- src/com/massivecraft/factions/cmd/CmdTag.java | 16 +- .../factions/cmd/FRelationCommand.java | 13 ++ .../factions/event/FPlayerLeaveEvent.java | 2 +- .../factions/event/FactionCreateEvent.java | 10 +- .../factions/event/FactionRelationEvent.java | 56 ++++++ .../factions/event/FactionRenameEvent.java | 73 +++++++ .../factions/event/LandClaimEvent.java | 6 +- 12 files changed, 287 insertions(+), 123 deletions(-) create mode 100644 src/com/massivecraft/factions/event/FactionRelationEvent.java create mode 100644 src/com/massivecraft/factions/event/FactionRenameEvent.java diff --git a/src/com/massivecraft/factions/cmd/CmdCreate.java b/src/com/massivecraft/factions/cmd/CmdCreate.java index dd18e005..1babc225 100644 --- a/src/com/massivecraft/factions/cmd/CmdCreate.java +++ b/src/com/massivecraft/factions/cmd/CmdCreate.java @@ -57,10 +57,10 @@ public class CmdCreate extends FCommand sendMessage(tagValidationErrors); return; } - - FactionCreateEvent createEvent = new FactionCreateEvent(tag, me); - Bukkit.getServer().getPluginManager().callEvent(createEvent); + // trigger the faction creation event (cancellable) + FactionCreateEvent createEvent = new FactionCreateEvent(me, tag); + Bukkit.getServer().getPluginManager().callEvent(createEvent); if(createEvent.isCancelled()) return; // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay @@ -75,10 +75,15 @@ public class CmdCreate extends FCommand return; } - FPlayerJoinEvent joinEvent = new FPlayerJoinEvent(FPlayers.i.get(me),faction,FPlayerJoinEvent.PlayerJoinReason.CREATE); - Bukkit.getServer().getPluginManager().callEvent(joinEvent); - - faction.setTag(tag); + // finish setting up the Faction + faction.setTag(tag); + + // trigger the faction join event for the creator + FPlayerJoinEvent joinEvent = new FPlayerJoinEvent(FPlayers.i.get(me),faction,FPlayerJoinEvent.PlayerJoinReason.CREATE); + Bukkit.getServer().getPluginManager().callEvent(joinEvent); + // join event cannot be cancelled or you'll have an empty faction + + // finish setting up the FPlayer fme.setRole(Rel.LEADER); fme.setFaction(faction); diff --git a/src/com/massivecraft/factions/cmd/CmdDisband.java b/src/com/massivecraft/factions/cmd/CmdDisband.java index a1c4fa52..1c59b722 100644 --- a/src/com/massivecraft/factions/cmd/CmdDisband.java +++ b/src/com/massivecraft/factions/cmd/CmdDisband.java @@ -1,91 +1,96 @@ -package com.massivecraft.factions.cmd; - -import org.bukkit.Bukkit; - -import com.massivecraft.factions.Conf; -import com.massivecraft.factions.event.FPlayerLeaveEvent; -import com.massivecraft.factions.event.FactionDisbandEvent; -import com.massivecraft.factions.integration.Econ; -import com.massivecraft.factions.FPlayers; -import com.massivecraft.factions.Faction; -import com.massivecraft.factions.P; -import com.massivecraft.factions.FPlayer; -import com.massivecraft.factions.integration.SpoutFeatures; -import com.massivecraft.factions.struct.FFlag; -import com.massivecraft.factions.struct.FPerm; -import com.massivecraft.factions.struct.Permission; - -public class CmdDisband extends FCommand -{ - public CmdDisband() - { - super(); - this.aliases.add("disband"); - - //this.requiredArgs.add(""); - this.optionalArgs.put("faction", "your"); - - this.permission = Permission.DISBAND.node; - this.disableOnLock = true; - - senderMustBePlayer = false; - senderMustBeMember = false; - senderMustBeOfficer = false; - senderMustBeLeader = false; - } - - @Override - public void perform() - { - // The faction, default to your own.. but null if console sender. - Faction faction = this.argAsFaction(0, fme == null ? null : myFaction); - if (faction == null) return; - - if ( ! FPerm.DISBAND.has(sender, faction, true)) return; - - if (faction.getFlag(FFlag.PERMANENT)) - { - msg("This faction is designated as permanent, so you cannot disband it."); - return; - } - - FactionDisbandEvent disbandEvent = new FactionDisbandEvent(me, faction.getId()); - Bukkit.getServer().getPluginManager().callEvent(disbandEvent); - if(disbandEvent.isCancelled()) return; - - // Inform all players - for (FPlayer fplayer : FPlayers.i.getOnline()) - { - String who = senderIsConsole ? "A server admin" : fme.describeTo(fplayer); - if (fplayer.getFaction() == faction) - { - Bukkit.getServer().getPluginManager().callEvent(new FPlayerLeaveEvent(fplayer,faction, FPlayerLeaveEvent.PlayerLeaveReason.DISBAND)); - fplayer.msg("%s disbanded your faction.", who); - } - else - { - fplayer.msg("%s disbanded the faction %s.", who, faction.getTag(fplayer)); - } - } - if (Conf.logFactionDisband) - P.p.log("The faction "+faction.getTag()+" ("+faction.getId()+") was disbanded by "+(senderIsConsole ? "console command" : fme.getName())+"."); - - if (Econ.shouldBeUsed() && ! senderIsConsole) - { - //Give all the faction's money to the disbander - double amount = Econ.getBalance(faction.getAccountId()); - Econ.transferMoney(fme, faction, fme, amount, false); - - if (amount > 0.0) - { - String amountString = Econ.moneyString(amount); - msg("You have been given the disbanded faction's bank, totaling %s.", amountString); - P.p.log(fme.getName() + " has been given bank holdings of "+amountString+" from disbanding "+faction.getTag()+"."); - } - } - - faction.detach(); - - SpoutFeatures.updateAppearances(); - } -} +package com.massivecraft.factions.cmd; + +import org.bukkit.Bukkit; + +import com.massivecraft.factions.Conf; +import com.massivecraft.factions.event.FPlayerLeaveEvent; +import com.massivecraft.factions.event.FactionDisbandEvent; +import com.massivecraft.factions.integration.Econ; +import com.massivecraft.factions.FPlayers; +import com.massivecraft.factions.Faction; +import com.massivecraft.factions.P; +import com.massivecraft.factions.FPlayer; +import com.massivecraft.factions.integration.SpoutFeatures; +import com.massivecraft.factions.struct.FFlag; +import com.massivecraft.factions.struct.FPerm; +import com.massivecraft.factions.struct.Permission; + +public class CmdDisband extends FCommand +{ + public CmdDisband() + { + super(); + this.aliases.add("disband"); + + //this.requiredArgs.add(""); + this.optionalArgs.put("faction", "your"); + + this.permission = Permission.DISBAND.node; + this.disableOnLock = true; + + senderMustBePlayer = false; + senderMustBeMember = false; + senderMustBeOfficer = false; + senderMustBeLeader = false; + } + + @Override + public void perform() + { + // The faction, default to your own.. but null if console sender. + Faction faction = this.argAsFaction(0, fme == null ? null : myFaction); + if (faction == null) return; + + if ( ! FPerm.DISBAND.has(sender, faction, true)) return; + + if (faction.getFlag(FFlag.PERMANENT)) + { + msg("This faction is designated as permanent, so you cannot disband it."); + return; + } + + FactionDisbandEvent disbandEvent = new FactionDisbandEvent(me, faction.getId()); + Bukkit.getServer().getPluginManager().callEvent(disbandEvent); + if(disbandEvent.isCancelled()) return; + + // Send FPlayerLeaveEvent for each player in the faction + for ( FPlayer fplayer : faction.getFPlayers() ) + { + Bukkit.getServer().getPluginManager().callEvent(new FPlayerLeaveEvent(fplayer, faction, FPlayerLeaveEvent.PlayerLeaveReason.DISBAND)); + } + + // Inform all players + for (FPlayer fplayer : FPlayers.i.getOnline()) + { + String who = senderIsConsole ? "A server admin" : fme.describeTo(fplayer); + if (fplayer.getFaction() == faction) + { + fplayer.msg("%s disbanded your faction.", who); + } + else + { + fplayer.msg("%s disbanded the faction %s.", who, faction.getTag(fplayer)); + } + } + if (Conf.logFactionDisband) + P.p.log("The faction "+faction.getTag()+" ("+faction.getId()+") was disbanded by "+(senderIsConsole ? "console command" : fme.getName())+"."); + + if (Econ.shouldBeUsed() && ! senderIsConsole) + { + //Give all the faction's money to the disbander + double amount = Econ.getBalance(faction.getAccountId()); + Econ.transferMoney(fme, faction, fme, amount, false); + + if (amount > 0.0) + { + String amountString = Econ.moneyString(amount); + msg("You have been given the disbanded faction's bank, totaling %s.", amountString); + P.p.log(fme.getName() + " has been given bank holdings of "+amountString+" from disbanding "+faction.getTag()+"."); + } + } + + faction.detach(); + + SpoutFeatures.updateAppearances(); + } +} diff --git a/src/com/massivecraft/factions/cmd/CmdJoin.java b/src/com/massivecraft/factions/cmd/CmdJoin.java index 79bd1e4c..63cad4b6 100644 --- a/src/com/massivecraft/factions/cmd/CmdJoin.java +++ b/src/com/massivecraft/factions/cmd/CmdJoin.java @@ -8,9 +8,7 @@ import com.massivecraft.factions.Faction; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.P; import com.massivecraft.factions.event.FPlayerJoinEvent; -import com.massivecraft.factions.event.FPlayerLeaveEvent; import com.massivecraft.factions.struct.Permission; -import com.massivecraft.factions.zcore.persist.EM; public class CmdJoin extends FCommand { @@ -82,14 +80,8 @@ public class CmdJoin extends FCommand if (samePlayer && ! payForCommand(Conf.econCostJoin, "to join a faction", "for joining a faction")) return; fme.msg("%s successfully joined %s.", fplayer.describeTo(fme, true), faction.getTag(fme)); - - if(!EM.detached(myFaction)) - { - FPlayerLeaveEvent leaveEvent = new FPlayerLeaveEvent(FPlayers.i.get(me),faction,FPlayerLeaveEvent.PlayerLeaveReason.JOINOTHER); - Bukkit.getServer().getPluginManager().callEvent(leaveEvent); - if (leaveEvent.isCancelled()) return; - } - + + // trigger the join event (cancellable) FPlayerJoinEvent joinEvent = new FPlayerJoinEvent(FPlayers.i.get(me),faction,FPlayerJoinEvent.PlayerJoinReason.COMMAND); Bukkit.getServer().getPluginManager().callEvent(joinEvent); if (joinEvent.isCancelled()) return; diff --git a/src/com/massivecraft/factions/cmd/CmdKick.java b/src/com/massivecraft/factions/cmd/CmdKick.java index 7c27f683..71cb51cf 100644 --- a/src/com/massivecraft/factions/cmd/CmdKick.java +++ b/src/com/massivecraft/factions/cmd/CmdKick.java @@ -63,6 +63,7 @@ public class CmdKick extends FCommand // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay if ( ! payForCommand(Conf.econCostKick, "to kick someone from the faction", "for kicking someone from the faction")) return; + // trigger the leave event (cancellable) [reason:kicked] FPlayerLeaveEvent event = new FPlayerLeaveEvent(you, you.getFaction(), FPlayerLeaveEvent.PlayerLeaveReason.KICKED); Bukkit.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) return; diff --git a/src/com/massivecraft/factions/cmd/CmdLeader.java b/src/com/massivecraft/factions/cmd/CmdLeader.java index 3068a9f3..52b1c4e2 100644 --- a/src/com/massivecraft/factions/cmd/CmdLeader.java +++ b/src/com/massivecraft/factions/cmd/CmdLeader.java @@ -66,11 +66,16 @@ public class CmdLeader extends FCommand return; } } - - FPlayerJoinEvent event = new FPlayerJoinEvent(FPlayers.i.get(me),targetFaction,FPlayerJoinEvent.PlayerJoinReason.LEADER); - Bukkit.getServer().getPluginManager().callEvent(event); - if (event.isCancelled()) return; - + + // only perform a FPlayerJoinEvent when newLeader isn't actually in the faction + // (only possibly triggered by console) + if (newLeader.getFaction() != targetFaction) + { + FPlayerJoinEvent event = new FPlayerJoinEvent(FPlayers.i.get(me),targetFaction,FPlayerJoinEvent.PlayerJoinReason.LEADER); + Bukkit.getServer().getPluginManager().callEvent(event); + if (event.isCancelled()) return; + } + // if target player is currently leader, demote and replace him if (targetFactionCurrentLeader == newLeader) { diff --git a/src/com/massivecraft/factions/cmd/CmdTag.java b/src/com/massivecraft/factions/cmd/CmdTag.java index 9c569fc9..cd3da2a8 100644 --- a/src/com/massivecraft/factions/cmd/CmdTag.java +++ b/src/com/massivecraft/factions/cmd/CmdTag.java @@ -2,9 +2,12 @@ package com.massivecraft.factions.cmd; import java.util.ArrayList; +import org.bukkit.Bukkit; + import com.massivecraft.factions.Conf; import com.massivecraft.factions.Faction; import com.massivecraft.factions.Factions; +import com.massivecraft.factions.event.FactionRenameEvent; import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.util.MiscUtil; @@ -39,7 +42,7 @@ public class CmdTag extends FCommand msg("That tag is already taken"); return; } - + ArrayList errors = new ArrayList(); errors.addAll(Factions.validateTag(tag)); if (errors.size() > 0) @@ -48,12 +51,17 @@ public class CmdTag extends FCommand return; } + // trigger the faction rename event (cancellable) + FactionRenameEvent renameEvent = new FactionRenameEvent(fme, tag); + Bukkit.getServer().getPluginManager().callEvent(renameEvent); + if(renameEvent.isCancelled()) return; + // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay if ( ! payForCommand(Conf.econCostTag, "to change the faction tag", "for changing the faction tag")) return; - - String oldtag = myFaction.getTag(); + + String oldtag = myFaction.getTag(); myFaction.setTag(tag); - + // Inform myFaction.msg("%s changed your faction tag to %s", fme.describeTo(myFaction, true), myFaction.getTag(myFaction)); for (Faction faction : Factions.i.get()) diff --git a/src/com/massivecraft/factions/cmd/FRelationCommand.java b/src/com/massivecraft/factions/cmd/FRelationCommand.java index 234c1669..37efc8af 100644 --- a/src/com/massivecraft/factions/cmd/FRelationCommand.java +++ b/src/com/massivecraft/factions/cmd/FRelationCommand.java @@ -1,7 +1,10 @@ package com.massivecraft.factions.cmd; +import org.bukkit.Bukkit; + import com.massivecraft.factions.Conf; import com.massivecraft.factions.Faction; +import com.massivecraft.factions.event.FactionRelationEvent; import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.factions.struct.FFlag; import com.massivecraft.factions.struct.Permission; @@ -47,13 +50,22 @@ public abstract class FRelationCommand extends FCommand // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay if ( ! payForCommand(targetRelation.getRelationCost(), "to change a relation wish", "for changing a relation wish")) return; + // try to set the new relation + Rel oldRelation = myFaction.getRelationTo(them, true); myFaction.setRelationWish(them, targetRelation); Rel currentRelation = myFaction.getRelationTo(them, true); + + // if the relation change was successful if (targetRelation == currentRelation) { + // trigger the faction relation event + FactionRelationEvent relationEvent = new FactionRelationEvent(myFaction, them, oldRelation, currentRelation); + Bukkit.getServer().getPluginManager().callEvent(relationEvent); + them.msg("%s is now %s.", myFaction.describeTo(them, true), targetRelation.getDescFactionOne()); myFaction.msg("%s is now %s.", them.describeTo(myFaction, true), targetRelation.getDescFactionOne()); } + // inform the other faction of your request else { them.msg("%s wishes to be %s.", myFaction.describeTo(them, true), targetRelation.getColor()+targetRelation.getDescFactionOne()); @@ -62,6 +74,7 @@ public abstract class FRelationCommand extends FCommand } // TODO: The ally case should work!! + // * this might have to be bumped up to make that happen, & allow ALLY,NEUTRAL only if ( targetRelation != Rel.TRUCE && them.getFlag(FFlag.PEACEFUL)) { them.msg("This will have no effect while your faction is peaceful."); diff --git a/src/com/massivecraft/factions/event/FPlayerLeaveEvent.java b/src/com/massivecraft/factions/event/FPlayerLeaveEvent.java index 167933f0..12e951bb 100644 --- a/src/com/massivecraft/factions/event/FPlayerLeaveEvent.java +++ b/src/com/massivecraft/factions/event/FPlayerLeaveEvent.java @@ -15,7 +15,7 @@ public class FPlayerLeaveEvent extends Event implements Cancellable Faction Faction; boolean cancelled = false; - public enum PlayerLeaveReason + public enum PlayerLeaveReason { KICKED, DISBAND, RESET, JOINOTHER, LEAVE } diff --git a/src/com/massivecraft/factions/event/FactionCreateEvent.java b/src/com/massivecraft/factions/event/FactionCreateEvent.java index 0f9a66bd..088e0021 100644 --- a/src/com/massivecraft/factions/event/FactionCreateEvent.java +++ b/src/com/massivecraft/factions/event/FactionCreateEvent.java @@ -7,6 +7,7 @@ import org.bukkit.event.HandlerList; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayers; +import com.massivecraft.factions.Factions; public class FactionCreateEvent extends Event implements Cancellable { @@ -16,7 +17,7 @@ public class FactionCreateEvent extends Event implements Cancellable private Player sender; private boolean cancelled; - public FactionCreateEvent(String tag, Player sender) + public FactionCreateEvent(Player sender, String tag) { this.factionTag = tag; this.sender = sender; @@ -28,11 +29,16 @@ public class FactionCreateEvent extends Event implements Cancellable return FPlayers.i.get(sender); } + public String getFactionId() + { + return Factions.i.getNextId(); + } + public String getFactionTag() { return factionTag; } - + public HandlerList getHandlers() { return handlers; diff --git a/src/com/massivecraft/factions/event/FactionRelationEvent.java b/src/com/massivecraft/factions/event/FactionRelationEvent.java new file mode 100644 index 00000000..7279777a --- /dev/null +++ b/src/com/massivecraft/factions/event/FactionRelationEvent.java @@ -0,0 +1,56 @@ +package com.massivecraft.factions.event; + +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +import com.massivecraft.factions.struct.Rel; +import com.massivecraft.factions.Faction; + + +public class FactionRelationEvent extends Event { + private static final HandlerList handlers = new HandlerList(); + + private Faction fsender; + private Faction ftarget; + private Rel foldrel; + private Rel frel; + + public FactionRelationEvent(Faction sender, Faction target, Rel oldrel, Rel rel) + { + fsender = sender; + ftarget = target; + foldrel = oldrel; + frel = rel; + } + + public HandlerList getHandlers() + { + return handlers; + } + + public static HandlerList getHandlerList() + { + return handlers; + } + + public Rel getOldRelation() + { + return foldrel; + } + + public Rel getRelation() + { + return frel; + } + + public Faction getFaction() + { + return fsender; + } + + public Faction getTargetFaction() + { + return ftarget; + } + +} diff --git a/src/com/massivecraft/factions/event/FactionRenameEvent.java b/src/com/massivecraft/factions/event/FactionRenameEvent.java new file mode 100644 index 00000000..7c111332 --- /dev/null +++ b/src/com/massivecraft/factions/event/FactionRenameEvent.java @@ -0,0 +1,73 @@ +package com.massivecraft.factions.event; + +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +import com.massivecraft.factions.FPlayer; +import com.massivecraft.factions.Faction; + +public class FactionRenameEvent extends Event implements Cancellable { + private static final HandlerList handlers = new HandlerList(); + + private boolean cancelled; + private FPlayer fplayer; + private Faction faction; + private String tag; + + public FactionRenameEvent(FPlayer sender, String newTag) + { + fplayer = sender; + faction = sender.getFaction(); + tag = newTag; + this.cancelled = false; + } + + public Faction getFaction() + { + return(faction); + } + + public FPlayer getFPlayer() + { + return(fplayer); + } + + public Player getPlayer() + { + return(fplayer.getPlayer()); + } + + public String getOldFactionTag() + { + return(faction.getTag()); + } + + public String getFactionTag() + { + return(tag); + } + + public HandlerList getHandlers() + { + return handlers; + } + + public static HandlerList getHandlerList() + { + return handlers; + } + + @Override + public boolean isCancelled() + { + return cancelled; + } + + @Override + public void setCancelled(boolean c) + { + this.cancelled = c; + } +} diff --git a/src/com/massivecraft/factions/event/LandClaimEvent.java b/src/com/massivecraft/factions/event/LandClaimEvent.java index 4d27ce9a..b1216bd8 100644 --- a/src/com/massivecraft/factions/event/LandClaimEvent.java +++ b/src/com/massivecraft/factions/event/LandClaimEvent.java @@ -18,12 +18,12 @@ public class LandClaimEvent extends Event implements Cancellable private FLocation location; private String factionId, playerId; - public LandClaimEvent(FLocation loc, String id, String pid) + public LandClaimEvent(FLocation loc, String fid, String pid) { cancelled = false; location = loc; - factionId = id; - playerId = pid; + this.factionId = fid; + this.playerId = pid; } public HandlerList getHandlers() From 9314b4e298de7526ae6b14f4261b46a492c7ba24 Mon Sep 17 00:00:00 2001 From: donington Date: Sun, 11 Mar 2012 13:28:31 -0400 Subject: [PATCH 3/3] 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() {