From 554a7a42c6ad627eb58a0eef4c02b79b7f5dbed8 Mon Sep 17 00:00:00 2001 From: Brettflan Date: Tue, 13 Mar 2012 07:58:51 -0500 Subject: [PATCH] (patrickfreed) (bladedpenguin) (donington) Custom Event System - custom events are provided for other developers to hook into to create their own plugins based around Factions! Check the factions/event folder for the currently implemented events. --- src/com/massivecraft/factions/FPlayer.java | 13 ++- .../massivecraft/factions/cmd/CmdAdmin.java | 11 +++ .../massivecraft/factions/cmd/CmdCreate.java | 19 ++++- .../massivecraft/factions/cmd/CmdDisband.java | 14 ++++ .../massivecraft/factions/cmd/CmdJoin.java | 10 +++ .../massivecraft/factions/cmd/CmdKick.java | 9 ++- src/com/massivecraft/factions/cmd/CmdTag.java | 10 ++- .../massivecraft/factions/cmd/CmdUnclaim.java | 54 ++----------- .../factions/cmd/CmdUnclaimall.java | 7 ++ .../factions/cmd/FRelationCommand.java | 11 +++ .../factions/event/FPlayerJoinEvent.java | 60 ++++++++++++++ .../factions/event/FPlayerLeaveEvent.java | 71 ++++++++++++++++ .../factions/event/FactionCreateEvent.java | 63 +++++++++++++++ .../factions/event/FactionDisbandEvent.java | 64 +++++++++++++++ .../factions/event/FactionRelationEvent.java | 56 +++++++++++++ .../factions/event/FactionRenameEvent.java | 73 +++++++++++++++++ .../factions/event/LandClaimEvent.java | 81 +++++++++++++++++++ .../factions/event/LandUnclaimAllEvent.java | 68 ++++++++++++++++ .../factions/event/LandUnclaimEvent.java | 79 ++++++++++++++++++ 19 files changed, 722 insertions(+), 51 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/FactionRelationEvent.java create mode 100644 src/com/massivecraft/factions/event/FactionRenameEvent.java create mode 100644 src/com/massivecraft/factions/event/LandClaimEvent.java create mode 100644 src/com/massivecraft/factions/event/LandUnclaimAllEvent.java create mode 100644 src/com/massivecraft/factions/event/LandUnclaimEvent.java diff --git a/src/com/massivecraft/factions/FPlayer.java b/src/com/massivecraft/factions/FPlayer.java index 0191365d..1a7e0bd4 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; @@ -613,6 +616,10 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator 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) { @@ -803,7 +810,11 @@ public class FPlayer extends PlayerEntity implements EconomyParticipator if ( ! Econ.modifyMoney(this, -cost, "to claim this land", "for claiming this land")) return false; } } - + + LandClaimEvent claimEvent = new LandClaimEvent(flocation, forFaction, this); + 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/CmdAdmin.java b/src/com/massivecraft/factions/cmd/CmdAdmin.java index 69d6bd97..769a71c7 100644 --- a/src/com/massivecraft/factions/cmd/CmdAdmin.java +++ b/src/com/massivecraft/factions/cmd/CmdAdmin.java @@ -1,8 +1,11 @@ package com.massivecraft.factions.cmd; +import org.bukkit.Bukkit; + import com.massivecraft.factions.Faction; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayers; +import com.massivecraft.factions.event.FPlayerJoinEvent; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Role; @@ -52,6 +55,14 @@ public class CmdAdmin extends FCommand return; } + // only perform a FPlayerJoinEvent when newLeader isn't actually in the faction + if (fyou.getFaction() != targetFaction) + { + FPlayerJoinEvent event = new FPlayerJoinEvent(FPlayers.i.get(me),targetFaction,FPlayerJoinEvent.PlayerJoinReason.LEADER); + Bukkit.getServer().getPluginManager().callEvent(event); + if (event.isCancelled()) return; + } + FPlayer admin = targetFaction.getFPlayerAdmin(); // if target player is currently admin, demote and replace him diff --git a/src/com/massivecraft/factions/cmd/CmdCreate.java b/src/com/massivecraft/factions/cmd/CmdCreate.java index fd9b0b88..a62e5d1e 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.Role; @@ -54,7 +58,12 @@ public class CmdCreate extends FCommand sendMessage(tagValidationErrors); return; } - + + // 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 if ( ! payForCommand(Conf.econCostCreate, "to create a new faction", "for creating a new faction")) return; @@ -67,7 +76,15 @@ public class CmdCreate extends FCommand return; } + // 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(Role.ADMIN); fme.setFaction(faction); diff --git a/src/com/massivecraft/factions/cmd/CmdDisband.java b/src/com/massivecraft/factions/cmd/CmdDisband.java index 197a2d24..c9e63a32 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; @@ -62,6 +66,16 @@ public class CmdDisband extends FCommand 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()) { diff --git a/src/com/massivecraft/factions/cmd/CmdJoin.java b/src/com/massivecraft/factions/cmd/CmdJoin.java index 231c8bbc..ca4b0416 100644 --- a/src/com/massivecraft/factions/cmd/CmdJoin.java +++ b/src/com/massivecraft/factions/cmd/CmdJoin.java @@ -1,9 +1,13 @@ 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.struct.Permission; public class CmdJoin extends FCommand @@ -81,7 +85,13 @@ public class CmdJoin extends FCommand // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay if (samePlayer && ! payForCommand(Conf.econCostJoin, "to join a faction", "for joining a faction")) 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; + fme.msg("%s successfully joined %s.", fplayer.describeTo(fme, true), faction.getTag(fme)); + 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 7e32701d..32081230 100644 --- a/src/com/massivecraft/factions/cmd/CmdKick.java +++ b/src/com/massivecraft/factions/cmd/CmdKick.java @@ -1,10 +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.FPlayers; import com.massivecraft.factions.Faction; import com.massivecraft.factions.P; +import com.massivecraft.factions.event.FPlayerLeaveEvent; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Role; @@ -69,6 +71,11 @@ 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; + 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/CmdTag.java b/src/com/massivecraft/factions/cmd/CmdTag.java index 47c37e43..4c29b042 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; @@ -50,7 +53,12 @@ public class CmdTag 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.econCostTag, "to change the faction tag", "for changing the faction tag")) return; - + + // trigger the faction rename event (cancellable) + FactionRenameEvent renameEvent = new FactionRenameEvent(fme, tag); + Bukkit.getServer().getPluginManager().callEvent(renameEvent); + if(renameEvent.isCancelled()) return; + String oldtag = myFaction.getTag(); myFaction.setTag(tag); diff --git a/src/com/massivecraft/factions/cmd/CmdUnclaim.java b/src/com/massivecraft/factions/cmd/CmdUnclaim.java index 7c28b237..6d3becde 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; @@ -101,7 +104,6 @@ public class CmdUnclaim extends FCommand return; } - //String moneyBack = ""; if (Econ.shouldBeUsed()) { double refund = Econ.calculateClaimRefund(myFaction.getLandRounded()); @@ -114,54 +116,12 @@ public class CmdUnclaim extends FCommand { if ( ! Econ.modifyMoney(fme , refund, "to unclaim this land", "for unclaiming this land")) return; } - - /* - // a real refund - if (refund > 0.0) - { - if(Conf.bankFactionPaysLandCosts) - { - Faction faction = myFaction; - faction.addMoney(refund); - moneyBack = " "+faction.getTag()+" received a refund of "+Econ.moneyString(refund)+"."; - } - else - { - Econ.addMoney(fme.getName(), refund); - moneyBack = " They received a refund of "+Econ.moneyString(refund)+"."; - } - } - // wait, you're charging people to unclaim land? outrageous - else if (refund < 0.0) - { - if(Conf.bankFactionPaysLandCosts) - { - Faction faction = myFaction; - if(!faction.removeMoney(-refund)) - { - msg("Unclaiming this land will cost %s which your faction can't currently afford.", Econ.moneyString(-refund)); - return; - } - moneyBack = " It cost "+faction.getTag()+" "+Econ.moneyString(refund)+"."; - } - else - { - if (!Econ.deductMoney(fme.getName(), -refund)) - { - msg("Unclaiming this land will cost %s which you can't currently afford.", Econ.moneyString(-refund)); - return; - } - moneyBack = " It cost them "+Econ.moneyString(refund)+"."; - } - } - // no refund - else - { - moneyBack = ""; - } - */ } + LandUnclaimEvent unclaimEvent = new LandUnclaimEvent(flocation, otherFaction, fme); + 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/cmd/CmdUnclaimall.java b/src/com/massivecraft/factions/cmd/CmdUnclaimall.java index 4cb8ffd4..21370219 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/cmd/FRelationCommand.java b/src/com/massivecraft/factions/cmd/FRelationCommand.java index b18b6b14..71a2f106 100644 --- a/src/com/massivecraft/factions/cmd/FRelationCommand.java +++ b/src/com/massivecraft/factions/cmd/FRelationCommand.java @@ -1,9 +1,11 @@ package com.massivecraft.factions.cmd; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; 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.Permission; import com.massivecraft.factions.struct.Relation; @@ -48,14 +50,23 @@ 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 + Relation oldRelation = myFaction.getRelationTo(them, true); myFaction.setRelationWish(them, targetRelation); Relation currentRelation = myFaction.getRelationTo(them, true); ChatColor currentRelationColor = currentRelation.getColor(); + + // if the relation change was successful if (targetRelation.value == currentRelation.value) { + // trigger the faction relation event + FactionRelationEvent relationEvent = new FactionRelationEvent(myFaction, them, oldRelation, currentRelation); + Bukkit.getServer().getPluginManager().callEvent(relationEvent); + them.msg("Your faction is now "+currentRelationColor+targetRelation.toString()+" to "+currentRelationColor+myFaction.getTag()); myFaction.msg("Your faction is now "+currentRelationColor+targetRelation.toString()+" to "+currentRelationColor+them.getTag()); } + // inform the other faction of your request else { them.msg(currentRelationColor+myFaction.getTag()+" wishes to be your "+targetRelation.getColor()+targetRelation.toString()); 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..12e951bb --- /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..088e0021 --- /dev/null +++ b/src/com/massivecraft/factions/event/FactionCreateEvent.java @@ -0,0 +1,63 @@ +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.Factions; + +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(Player sender, String tag) + { + this.factionTag = tag; + this.sender = sender; + this.cancelled = false; + } + + public FPlayer getFPlayer() + { + return FPlayers.i.get(sender); + } + + public String getFactionId() + { + return Factions.i.getNextId(); + } + + 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/FactionRelationEvent.java b/src/com/massivecraft/factions/event/FactionRelationEvent.java new file mode 100644 index 00000000..97a33864 --- /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.Relation; +import com.massivecraft.factions.Faction; + + +public class FactionRelationEvent extends Event { + private static final HandlerList handlers = new HandlerList(); + + private Faction fsender; + private Faction ftarget; + private Relation foldrel; + private Relation frel; + + public FactionRelationEvent(Faction sender, Faction target, Relation oldrel, Relation rel) + { + fsender = sender; + ftarget = target; + foldrel = oldrel; + frel = rel; + } + + public HandlerList getHandlers() + { + return handlers; + } + + public static HandlerList getHandlerList() + { + return handlers; + } + + public Relation getOldRelation() + { + return foldrel; + } + + public Relation 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 new file mode 100644 index 00000000..041e5cad --- /dev/null +++ b/src/com/massivecraft/factions/event/LandClaimEvent.java @@ -0,0 +1,81 @@ +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.FPlayer; +import org.bukkit.entity.Player; + +public class LandClaimEvent extends Event implements Cancellable +{ + private static final HandlerList handlers = new HandlerList(); + + private boolean cancelled; + private FLocation location; + private Faction faction; + private FPlayer fplayer; + + public LandClaimEvent(FLocation loc, Faction f, FPlayer p) + { + cancelled = false; + location = loc; + 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(); + } + + @Override + public boolean isCancelled() + { + return cancelled; + } + + @Override + public void setCancelled(boolean c) + { + this.cancelled = c; + } + +} diff --git a/src/com/massivecraft/factions/event/LandUnclaimAllEvent.java b/src/com/massivecraft/factions/event/LandUnclaimAllEvent.java new file mode 100644 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 new file mode 100644 index 00000000..fb7bc1fd --- /dev/null +++ b/src/com/massivecraft/factions/event/LandUnclaimEvent.java @@ -0,0 +1,79 @@ +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.FPlayer; +import org.bukkit.entity.Player; + +public class LandUnclaimEvent extends Event implements Cancellable +{ + private static final HandlerList handlers = new HandlerList(); + + private boolean cancelled; + private FLocation location; + private Faction faction; + private FPlayer fplayer; + + public LandUnclaimEvent(FLocation loc, Faction f, FPlayer p) + { + cancelled = false; + location = loc; + 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(); + } + + @Override + public boolean isCancelled() + { + return cancelled; + } + + @Override + public void setCancelled(boolean c) { + cancelled = c; + } +}