From 61baf70ed1dd7b6450e704df3de90c888b07429e Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Fri, 19 Apr 2013 12:27:39 +0200 Subject: [PATCH] Major messaround with the internal events and payForCommand logic. Not done just yet though. --- plugin.yml | 4 +- src/com/massivecraft/factions/ConfServer.java | 3 +- src/com/massivecraft/factions/FPlayer.java | 13 ++-- src/com/massivecraft/factions/Faction.java | 33 +++----- src/com/massivecraft/factions/Factions.java | 7 +- src/com/massivecraft/factions/Perm.java | 1 - .../factions/cmd/CmdFactions.java | 2 - .../factions/cmd/CmdFactionsCreate.java | 24 ++---- .../factions/cmd/CmdFactionsDeinvite.java | 44 ----------- .../factions/cmd/CmdFactionsDescription.java | 14 +++- .../factions/cmd/CmdFactionsDisband.java | 9 ++- .../factions/cmd/CmdFactionsInvite.java | 47 +++++++---- .../factions/cmd/CmdFactionsJoin.java | 4 +- .../factions/cmd/CmdFactionsKick.java | 4 +- .../factions/cmd/CmdFactionsLeader.java | 8 +- .../factions/cmd/CmdFactionsOpen.java | 20 +++-- .../cmd/CmdFactionsRelationAbstract.java | 61 ++++++++------- .../factions/cmd/CmdFactionsSethome.java | 7 +- .../factions/cmd/CmdFactionsTag.java | 22 +++--- .../factions/cmd/CmdFactionsTitle.java | 17 ++-- .../factions/cmd/CmdFactionsUnclaim.java | 4 +- .../factions/cmd/CmdFactionsUnclaimall.java | 4 +- .../massivecraft/factions/cmd/FCommand.java | 5 +- .../factions/event/FactionDisbandEvent.java | 68 ---------------- .../factions/event/FactionRenameEvent.java | 60 -------------- .../factions/event/FactionsEventAbstract.java | 8 ++ .../event/FactionsEventAbstractSender.java | 26 +++++++ ...ateEvent.java => FactionsEventCreate.java} | 15 +--- .../event/FactionsEventDescriptionChange.java | 40 ++++++++++ .../factions/event/FactionsEventDisband.java | 46 +++++++++++ ...vent.java => FactionsEventHomeChange.java} | 24 +----- ...t.java => FactionsEventInvitedChange.java} | 34 ++++---- ...rJoinEvent.java => FactionsEventJoin.java} | 36 +++------ ...Event.java => FactionsEventLandClaim.java} | 33 ++------ ...ent.java => FactionsEventLandUnclaim.java} | 31 ++------ .../event/FactionsEventLandUnclaimAll.java | 35 +++++++++ ...eaveEvent.java => FactionsEventLeave.java} | 24 +++--- .../event/FactionsEventOpenChange.java | 40 ++++++++++ .../event/FactionsEventPowerLoss.java | 27 +++++++ ....java => FactionsEventRelationChange.java} | 30 +++---- .../event/FactionsEventTagChange.java | 40 ++++++++++ .../event/FactionsEventTitleChange.java | 40 ++++++++++ .../factions/event/PowerLossEvent.java | 58 -------------- .../listeners/FactionsListenerEcon.java | 74 +++++++++++++++--- .../listeners/FactionsListenerMain.java | 40 ++++++++++ .../listeners/TodoFactionsEntityListener.java | 78 ------------------- 46 files changed, 638 insertions(+), 626 deletions(-) delete mode 100644 src/com/massivecraft/factions/cmd/CmdFactionsDeinvite.java delete mode 100644 src/com/massivecraft/factions/event/FactionDisbandEvent.java delete mode 100644 src/com/massivecraft/factions/event/FactionRenameEvent.java create mode 100644 src/com/massivecraft/factions/event/FactionsEventAbstract.java create mode 100644 src/com/massivecraft/factions/event/FactionsEventAbstractSender.java rename src/com/massivecraft/factions/event/{FactionCreateEvent.java => FactionsEventCreate.java} (65%) create mode 100644 src/com/massivecraft/factions/event/FactionsEventDescriptionChange.java create mode 100644 src/com/massivecraft/factions/event/FactionsEventDisband.java rename src/com/massivecraft/factions/event/{FactionsHomeChangeEvent.java => FactionsEventHomeChange.java} (54%) rename src/com/massivecraft/factions/event/{LandUnclaimAllEvent.java => FactionsEventInvitedChange.java} (67%) mode change 100755 => 100644 rename src/com/massivecraft/factions/event/{FPlayerJoinEvent.java => FactionsEventJoin.java} (58%) rename src/com/massivecraft/factions/event/{LandUnclaimEvent.java => FactionsEventLandClaim.java} (52%) rename src/com/massivecraft/factions/event/{LandClaimEvent.java => FactionsEventLandUnclaim.java} (52%) create mode 100644 src/com/massivecraft/factions/event/FactionsEventLandUnclaimAll.java rename src/com/massivecraft/factions/event/{FPlayerLeaveEvent.java => FactionsEventLeave.java} (73%) create mode 100644 src/com/massivecraft/factions/event/FactionsEventOpenChange.java create mode 100644 src/com/massivecraft/factions/event/FactionsEventPowerLoss.java rename src/com/massivecraft/factions/event/{FactionRelationEvent.java => FactionsEventRelationChange.java} (56%) create mode 100644 src/com/massivecraft/factions/event/FactionsEventTagChange.java create mode 100644 src/com/massivecraft/factions/event/FactionsEventTitleChange.java delete mode 100644 src/com/massivecraft/factions/event/PowerLossEvent.java delete mode 100644 src/com/massivecraft/factions/listeners/TodoFactionsEntityListener.java diff --git a/plugin.yml b/plugin.yml index 5e364882..7110825a 100644 --- a/plugin.yml +++ b/plugin.yml @@ -26,7 +26,6 @@ permissions: factions.claim.radius: {description: claim land in a large radius} factions.config: {description: change a conf.json setting} factions.create: {description: create a new faction} - factions.deinvite: {description: remove a pending invitation} factions.demote: {description: demote lesser members in your faction} factions.description: {description: change the faction description} factions.disband: {description: disband a faction} @@ -34,7 +33,7 @@ permissions: factions.flag.set: {description: set faction flags} factions.help: {description: display a help page} factions.home: {description: teleport to the faction home} - factions.invite: {description: invite a player to your faction} + factions.invite: {description: set if a player is invited} factions.join: {description: join a faction} factions.join.any: {description: join any faction, bypassing invitation process for closed factions} factions.join.others: {description: specify another player in the join command, to move them to the specified faction} @@ -134,7 +133,6 @@ permissions: factions.cape.*: true factions.claim: true factions.claim.radius: true - factions.deinvite: true factions.demote: true factions.description: true factions.disband: true diff --git a/src/com/massivecraft/factions/ConfServer.java b/src/com/massivecraft/factions/ConfServer.java index 95404a9c..a92189c3 100644 --- a/src/com/massivecraft/factions/ConfServer.java +++ b/src/com/massivecraft/factions/ConfServer.java @@ -283,9 +283,10 @@ public class ConfServer extends SimpleConfig public static double econCostLeave = 0.0; public static double econCostKick = 0.0; public static double econCostInvite = 0.0; + public static double econCostDeinvite = 0.0; public static double econCostHome = 0.0; public static double econCostTag = 0.0; - public static double econCostDesc = 0.0; + public static double econCostDescription = 0.0; public static double econCostTitle = 0.0; public static double econCostOpen = 0.0; public static double econCostAlly = 0.0; diff --git a/src/com/massivecraft/factions/FPlayer.java b/src/com/massivecraft/factions/FPlayer.java index 41cc6118..17176d51 100644 --- a/src/com/massivecraft/factions/FPlayer.java +++ b/src/com/massivecraft/factions/FPlayer.java @@ -3,13 +3,12 @@ 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.event.FactionsEventLeave; +import com.massivecraft.factions.event.FactionsEventLandClaim; import com.massivecraft.factions.iface.EconomyParticipator; import com.massivecraft.factions.iface.RelationParticipator; import com.massivecraft.factions.integration.Econ; @@ -700,8 +699,8 @@ public class FPlayer extends SenderEntity implements EconomyParticipato // if economy is enabled and they're not on the bypass list, make sure they can pay if (makePay && ! Econ.hasAtLeast(this, ConfServer.econCostLeave, "to leave your faction.")) return; - FPlayerLeaveEvent leaveEvent = new FPlayerLeaveEvent(this,myFaction,FPlayerLeaveEvent.PlayerLeaveReason.LEAVE); - Bukkit.getServer().getPluginManager().callEvent(leaveEvent); + FactionsEventLeave leaveEvent = new FactionsEventLeave(sender, this, myFaction, FactionsEventLeave.PlayerLeaveReason.LEAVE); + leaveEvent.run(); if (leaveEvent.isCancelled()) return; // then make 'em pay (if applicable) @@ -858,8 +857,8 @@ public class FPlayer extends SenderEntity implements EconomyParticipato if ( ! Econ.hasAtLeast(payee, cost, "to claim this land")) return false; } - LandClaimEvent claimEvent = new LandClaimEvent(flocation, forFaction, this); - Bukkit.getServer().getPluginManager().callEvent(claimEvent); + FactionsEventLandClaim claimEvent = new FactionsEventLandClaim(sender, forFaction, flocation); + claimEvent.run(); if (claimEvent.isCancelled()) return false; // then make 'em pay (if applicable) diff --git a/src/com/massivecraft/factions/Faction.java b/src/com/massivecraft/factions/Faction.java index 226a25b7..07e1e4f9 100644 --- a/src/com/massivecraft/factions/Faction.java +++ b/src/com/massivecraft/factions/Faction.java @@ -354,39 +354,28 @@ public class Faction extends Entity implements EconomyParticipator return this.isInvited(fplayer.getId()); } - public boolean invite(String playerId) + public boolean setInvited(String playerId, boolean invited) { TreeSet invitedPlayerIds = this.getInvitedPlayerIds(); - if (invitedPlayerIds.add(playerId.toLowerCase())) + boolean ret; + if (invited) { - this.setInvitedPlayerIds(invitedPlayerIds); - return true; + ret = invitedPlayerIds.add(playerId.toLowerCase()); } - return false; - } - - public void invite(FPlayer fplayer) - { - this.invite(fplayer.getId()); - } - - public boolean deinvite(String playerId) - { - TreeSet invitedPlayerIds = this.getInvitedPlayerIds(); - if (invitedPlayerIds.remove(playerId.toLowerCase())) + else { - this.setInvitedPlayerIds(invitedPlayerIds); - return true; + ret = invitedPlayerIds.remove(playerId.toLowerCase()); } - return false; + this.setInvitedPlayerIds(invitedPlayerIds); + return ret; + } - public void deinvite(FPlayer fplayer) + public void setInvited(FPlayer fplayer, boolean invited) { - this.deinvite(fplayer.getId()); + this.setInvited(fplayer.getId(), invited); } - // -------------------------------------------- // // FIELD: relationWish // -------------------------------------------- // diff --git a/src/com/massivecraft/factions/Factions.java b/src/com/massivecraft/factions/Factions.java index f058c691..06d21109 100644 --- a/src/com/massivecraft/factions/Factions.java +++ b/src/com/massivecraft/factions/Factions.java @@ -26,7 +26,6 @@ import com.massivecraft.factions.integration.Worldguard; import com.massivecraft.factions.integration.herochat.HerochatFeatures; import com.massivecraft.factions.listeners.FactionsListenerChat; import com.massivecraft.factions.listeners.FactionsListenerEcon; -import com.massivecraft.factions.listeners.TodoFactionsEntityListener; import com.massivecraft.factions.listeners.FactionsListenerExploit; import com.massivecraft.factions.listeners.FactionsListenerMain; import com.massivecraft.factions.listeners.TodoFactionsPlayerListener; @@ -57,7 +56,6 @@ public class Factions extends MPlugin // Listeners public TodoFactionsPlayerListener playerListener; - public TodoFactionsEntityListener entityListener; // -------------------------------------------- // // OVERRIDE @@ -90,13 +88,10 @@ public class Factions extends MPlugin // Right now only a few situations are handled through this listener. FactionsListenerEcon.get().setup(); - // TODO: Get rid of these + // TODO: Get rid of this one this.playerListener = new TodoFactionsPlayerListener(); getServer().getPluginManager().registerEvents(this.playerListener, this); - this.entityListener = new TodoFactionsEntityListener(); - getServer().getPluginManager().registerEvents(this.entityListener, this); - // Schedule recurring non-tps-dependent tasks AutoLeaveTask.get().schedule(this); EconLandRewardTask.get().schedule(this); diff --git a/src/com/massivecraft/factions/Perm.java b/src/com/massivecraft/factions/Perm.java index d04249de..f41c096a 100644 --- a/src/com/massivecraft/factions/Perm.java +++ b/src/com/massivecraft/factions/Perm.java @@ -23,7 +23,6 @@ public enum Perm CLAIM_RADIUS("claim.radius"), CONFIG("config"), CREATE("create"), - DEINVITE("deinvite"), DEMOTE("demote"), DESCRIPTION("description"), DISBAND("disband"), diff --git a/src/com/massivecraft/factions/cmd/CmdFactions.java b/src/com/massivecraft/factions/cmd/CmdFactions.java index 88037a07..399656c8 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactions.java +++ b/src/com/massivecraft/factions/cmd/CmdFactions.java @@ -17,7 +17,6 @@ public class CmdFactions extends FCommand public CmdFactionsCape cmdFactionsCape = new CmdFactionsCape(); public CmdFactionsClaim cmdFactionsClaim = new CmdFactionsClaim(); public CmdFactionsCreate cmdFactionsCreate = new CmdFactionsCreate(); - public CmdFactionsDeinvite cmdFactionsDeinvite = new CmdFactionsDeinvite(); public CmdFactionsDemote cmdFactionsDemote = new CmdFactionsDemote(); public CmdFactionsDescription cmdFactionsDescription = new CmdFactionsDescription(); public CmdFactionsDisband cmdFactionsDisband = new CmdFactionsDisband(); @@ -77,7 +76,6 @@ public class CmdFactions extends FCommand this.addSubCommand(this.cmdFactionsPerm); this.addSubCommand(this.cmdFactionsFlag); this.addSubCommand(this.cmdFactionsInvite); - this.addSubCommand(this.cmdFactionsDeinvite); this.addSubCommand(this.cmdFactionsOpen); this.addSubCommand(this.cmdFactionsMoney); this.addSubCommand(this.cmdFactionsClaim); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsCreate.java b/src/com/massivecraft/factions/cmd/CmdFactionsCreate.java index 53109814..87db2c2e 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsCreate.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsCreate.java @@ -12,8 +12,8 @@ import com.massivecraft.factions.FactionColl; import com.massivecraft.factions.Factions; import com.massivecraft.factions.Perm; import com.massivecraft.factions.Rel; -import com.massivecraft.factions.event.FPlayerJoinEvent; -import com.massivecraft.factions.event.FactionCreateEvent; +import com.massivecraft.factions.event.FactionsEventJoin; +import com.massivecraft.factions.event.FactionsEventCreate; import com.massivecraft.mcore.cmd.req.ReqHasPerm; public class CmdFactionsCreate extends FCommand @@ -54,29 +54,19 @@ public class CmdFactionsCreate extends FCommand // trigger the faction creation event (cancellable) String factionId = FactionColl.get().getIdStrategy().generate(FactionColl.get()); - FactionCreateEvent createEvent = new FactionCreateEvent(sender, tag, factionId); + FactionsEventCreate createEvent = new FactionsEventCreate(sender, tag, factionId); Bukkit.getServer().getPluginManager().callEvent(createEvent); - if(createEvent.isCancelled()) return; - - // then make 'em pay (if applicable) - if (!payForCommand(ConfServer.econCostCreate)) return; + if (createEvent.isCancelled()) return; Faction faction = FactionColl.get().create(factionId); - // TODO: Why would this even happen??? Auto increment clash?? - if (faction == null) - { - msg("There was an internal error while trying to create your faction. Please try again."); - return; - } - // finish setting up the Faction faction.setTag(tag); // trigger the faction join event for the creator - FPlayerJoinEvent joinEvent = new FPlayerJoinEvent(FPlayerColl.get().get(sender),faction,FPlayerJoinEvent.PlayerJoinReason.CREATE); - Bukkit.getServer().getPluginManager().callEvent(joinEvent); - // join event cannot be cancelled or you'll have an empty faction + FactionsEventJoin joinEvent = new FactionsEventJoin(sender, fme, faction, FactionsEventJoin.PlayerJoinReason.CREATE); + joinEvent.run(); + // NOTE: join event cannot be cancelled or you'll have an empty faction // finish setting up the FPlayer fme.setRole(Rel.LEADER); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsDeinvite.java b/src/com/massivecraft/factions/cmd/CmdFactionsDeinvite.java deleted file mode 100644 index 19ab214c..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsDeinvite.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.FPerm; -import com.massivecraft.factions.FPlayer; -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.Perm; -import com.massivecraft.factions.cmd.arg.ARFPlayer; -import com.massivecraft.mcore.cmd.req.ReqHasPerm; - -public class CmdFactionsDeinvite extends FCommand -{ - - public CmdFactionsDeinvite() - { - this.addAliases("deinvite", "deinv"); - - this.addRequiredArg("player"); - - this.addRequirements(ReqHasPerm.get(Perm.DEINVITE.node)); - } - - @Override - public void perform() - { - if ( ! FPerm.INVITE.has(sender, myFaction, true)) return; - - FPlayer you = this.arg(0, ARFPlayer.getStartAny()); - if (you == null) return; - - if (you.getFaction() == myFaction) - { - msg("%s is already a member of %s", you.getName(), myFaction.getTag()); - msg("You might want to: %s", Factions.get().getOuterCmdFactions().cmdFactionsKick.getUseageTemplate(false)); - return; - } - - myFaction.deinvite(you); - - you.msg("%s revoked your invitation to %s.", fme.describeTo(you), myFaction.describeTo(you)); - - myFaction.msg("%s revoked %s's invitation.", fme.describeTo(myFaction), you.describeTo(myFaction)); - } - -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsDescription.java b/src/com/massivecraft/factions/cmd/CmdFactionsDescription.java index 6b830559..6a6abdee 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsDescription.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsDescription.java @@ -1,9 +1,9 @@ package com.massivecraft.factions.cmd; -import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.Perm; import com.massivecraft.factions.Rel; import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast; +import com.massivecraft.factions.event.FactionsEventDescriptionChange; import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.mixin.Mixin; @@ -23,11 +23,19 @@ public class CmdFactionsDescription extends FCommand @Override public void perform() { - // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay - if (!payForCommand(ConfServer.econCostDesc)) return; + // Args + String newDescription = this.argConcatFrom(1); + + // Event + FactionsEventDescriptionChange event = new FactionsEventDescriptionChange(sender, myFaction, newDescription); + event.run(); + if (event.isCancelled()) return; + newDescription = event.getNewDescription(); + // Apply myFaction.setDescription(this.argConcatFrom(1)); + // Inform myFaction.msg("%s set your faction description to:\n%s", Mixin.getDisplayName(sender), myFaction.getDescription()); } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsDisband.java b/src/com/massivecraft/factions/cmd/CmdFactionsDisband.java index c0f511ff..4d80a7a2 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsDisband.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsDisband.java @@ -4,8 +4,8 @@ import org.bukkit.Bukkit; import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.cmd.arg.ARFaction; -import com.massivecraft.factions.event.FPlayerLeaveEvent; -import com.massivecraft.factions.event.FactionDisbandEvent; +import com.massivecraft.factions.event.FactionsEventLeave; +import com.massivecraft.factions.event.FactionsEventDisband; import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.FFlag; import com.massivecraft.factions.FPerm; @@ -42,14 +42,15 @@ public class CmdFactionsDisband extends FCommand return; } - FactionDisbandEvent disbandEvent = new FactionDisbandEvent(me, faction.getId()); + FactionsEventDisband disbandEvent = new FactionsEventDisband(me, faction); 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)); + FactionsEventLeave leaveEvent = new FactionsEventLeave(sender, fplayer, faction, FactionsEventLeave.PlayerLeaveReason.DISBAND); + leaveEvent.run(); } // Inform all players diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsInvite.java b/src/com/massivecraft/factions/cmd/CmdFactionsInvite.java index 62ed0705..56bda1b1 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsInvite.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsInvite.java @@ -1,11 +1,12 @@ package com.massivecraft.factions.cmd; -import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.FPerm; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.Factions; import com.massivecraft.factions.Perm; import com.massivecraft.factions.cmd.arg.ARFPlayer; +import com.massivecraft.factions.event.FactionsEventInvitedChange; +import com.massivecraft.mcore.cmd.arg.ARBoolean; import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqIsPlayer; @@ -16,6 +17,7 @@ public class CmdFactionsInvite extends FCommand this.addAliases("inv", "invite"); this.addRequiredArg("player"); + this.addOptionalArg("yes/no", "toggle"); this.addRequirements(ReqHasPerm.get(Perm.INVITE.node)); this.addRequirements(ReqIsPlayer.get()); @@ -24,27 +26,44 @@ public class CmdFactionsInvite extends FCommand @Override public void perform() { - if ( ! FPerm.INVITE.has(sender, myFaction, true)) return; + // Args + FPlayer fplayer = this.arg(0, ARFPlayer.getStartAny()); + if (fplayer == null) return; - FPlayer you = this.arg(0, ARFPlayer.getStartAny()); - if (you == null) return; + Boolean newInvited = this.arg(1, ARBoolean.get(), !myFaction.isInvited(fplayer)); + if (newInvited == null) return; - if (you.getFaction() == myFaction) + // Allready member? + if (fplayer.getFaction() == myFaction) { - msg("%s is already a member of %s", you.getName(), myFaction.getTag()); + msg("%s is already a member of %s", fplayer.getName(), myFaction.getTag()); msg("You might want to: " + Factions.get().getOuterCmdFactions().cmdFactionsKick.getUseageTemplate(false)); return; } - - if (fme != null && ! FPerm.INVITE.has(fme, myFaction)) return; - // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay - if (!payForCommand(ConfServer.econCostInvite)) return; - - myFaction.invite(you); + // FPerm + if ( ! FPerm.INVITE.has(sender, myFaction, true)) return; - you.msg("%s invited you to %s", fme.describeTo(you, true), myFaction.describeTo(you)); - myFaction.msg("%s invited %s to your faction.", fme.describeTo(myFaction, true), you.describeTo(myFaction)); + // Event + FactionsEventInvitedChange event = new FactionsEventInvitedChange(sender, fplayer, myFaction, newInvited); + event.run(); + if (event.isCancelled()) return; + newInvited = event.isNewInvited(); + + // Apply + myFaction.setInvited(fplayer, newInvited); + + // Inform + if (newInvited) + { + fplayer.msg("%s invited you to %s", fme.describeTo(fplayer, true), myFaction.describeTo(fplayer)); + myFaction.msg("%s invited %s to your faction.", fme.describeTo(myFaction, true), fplayer.describeTo(myFaction)); + } + else + { + fplayer.msg("%s revoked your invitation to %s.", fme.describeTo(fplayer), myFaction.describeTo(fplayer)); + myFaction.msg("%s revoked %s's invitation.", fme.describeTo(myFaction), fplayer.describeTo(myFaction)); + } } } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsJoin.java b/src/com/massivecraft/factions/cmd/CmdFactionsJoin.java index d7099c18..dfc77775 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsJoin.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsJoin.java @@ -10,7 +10,7 @@ import com.massivecraft.factions.Factions; import com.massivecraft.factions.Perm; import com.massivecraft.factions.cmd.arg.ARFPlayer; import com.massivecraft.factions.cmd.arg.ARFaction; -import com.massivecraft.factions.event.FPlayerJoinEvent; +import com.massivecraft.factions.event.FactionsEventJoin; import com.massivecraft.mcore.cmd.req.ReqHasPerm; public class CmdFactionsJoin extends FCommand @@ -75,7 +75,7 @@ public class CmdFactionsJoin extends FCommand } // trigger the join event (cancellable) - FPlayerJoinEvent joinEvent = new FPlayerJoinEvent(FPlayerColl.get().get(me),faction,FPlayerJoinEvent.PlayerJoinReason.COMMAND); + FactionsEventJoin joinEvent = new FactionsEventJoin(FPlayerColl.get().get(me),faction,FactionsEventJoin.PlayerJoinReason.JOIN); Bukkit.getServer().getPluginManager().callEvent(joinEvent); if (joinEvent.isCancelled()) return; diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsKick.java b/src/com/massivecraft/factions/cmd/CmdFactionsKick.java index 89cb40a8..3ff09743 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsKick.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsKick.java @@ -10,7 +10,7 @@ import com.massivecraft.factions.Factions; import com.massivecraft.factions.Perm; import com.massivecraft.factions.Rel; import com.massivecraft.factions.cmd.arg.ARFPlayer; -import com.massivecraft.factions.event.FPlayerLeaveEvent; +import com.massivecraft.factions.event.FactionsEventLeave; import com.massivecraft.mcore.cmd.req.ReqHasPerm; public class CmdFactionsKick extends FCommand @@ -55,7 +55,7 @@ public class CmdFactionsKick extends FCommand if (fme != null && ! FPerm.KICK.has(fme, yourFaction)) return; // trigger the leave event (cancellable) [reason:kicked] - FPlayerLeaveEvent event = new FPlayerLeaveEvent(you, you.getFaction(), FPlayerLeaveEvent.PlayerLeaveReason.KICKED); + FactionsEventLeave event = new FactionsEventLeave(you, you.getFaction(), FactionsEventLeave.PlayerLeaveReason.KICKED); Bukkit.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) return; diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsLeader.java b/src/com/massivecraft/factions/cmd/CmdFactionsLeader.java index 4614aa53..bc6b43ef 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsLeader.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsLeader.java @@ -1,7 +1,5 @@ package com.massivecraft.factions.cmd; -import org.bukkit.Bukkit; - import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayerColl; import com.massivecraft.factions.Faction; @@ -9,7 +7,7 @@ import com.massivecraft.factions.Perm; import com.massivecraft.factions.Rel; import com.massivecraft.factions.cmd.arg.ARFPlayer; import com.massivecraft.factions.cmd.arg.ARFaction; -import com.massivecraft.factions.event.FPlayerJoinEvent; +import com.massivecraft.factions.event.FactionsEventJoin; import com.massivecraft.factions.util.RelationUtil; import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.util.Txt; @@ -67,8 +65,8 @@ public class CmdFactionsLeader extends FCommand // only perform a FPlayerJoinEvent when newLeader isn't actually in the faction if (newLeader.getFaction() != targetFaction) { - FPlayerJoinEvent event = new FPlayerJoinEvent(FPlayerColl.get().get(me),targetFaction,FPlayerJoinEvent.PlayerJoinReason.LEADER); - Bukkit.getServer().getPluginManager().callEvent(event); + FactionsEventJoin event = new FactionsEventJoin(sender, newLeader, targetFaction, FactionsEventJoin.PlayerJoinReason.LEADER); + event.run(); if (event.isCancelled()) return; } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsOpen.java b/src/com/massivecraft/factions/cmd/CmdFactionsOpen.java index 21f13885..5a99b016 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsOpen.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsOpen.java @@ -1,11 +1,11 @@ package com.massivecraft.factions.cmd; -import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.Faction; import com.massivecraft.factions.FactionColl; import com.massivecraft.factions.Perm; import com.massivecraft.factions.Rel; import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast; +import com.massivecraft.factions.event.FactionsEventOpenChange; import com.massivecraft.mcore.cmd.arg.ARBoolean; import com.massivecraft.mcore.cmd.req.ReqHasPerm; @@ -24,17 +24,21 @@ public class CmdFactionsOpen extends FCommand @Override public void perform() { - Boolean target = this.arg(0, ARBoolean.get(), !myFaction.isOpen()); - if (target == null) return; + // Args + Boolean newOpen = this.arg(0, ARBoolean.get(), !myFaction.isOpen()); + if (newOpen == null) return; - // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay - if (!payForCommand(ConfServer.econCostOpen)) return; + // Event + FactionsEventOpenChange event = new FactionsEventOpenChange(sender, myFaction, newOpen); + event.run(); + if (event.isCancelled()) return; + newOpen = event.isNewOpen(); - myFaction.setOpen(target); - - String descTarget = myFaction.isOpen() ? "open" : "closed"; + // Apply + myFaction.setOpen(newOpen); // Inform + String descTarget = myFaction.isOpen() ? "open" : "closed"; myFaction.msg("%s changed the faction to %s.", fme.describeTo(myFaction, true), descTarget); for (Faction faction : FactionColl.get().getAll()) { diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsRelationAbstract.java b/src/com/massivecraft/factions/cmd/CmdFactionsRelationAbstract.java index 28ae0889..487102b0 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsRelationAbstract.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsRelationAbstract.java @@ -1,7 +1,5 @@ package com.massivecraft.factions.cmd; -import org.bukkit.Bukkit; - import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.FFlag; import com.massivecraft.factions.Faction; @@ -9,7 +7,7 @@ import com.massivecraft.factions.Perm; import com.massivecraft.factions.Rel; import com.massivecraft.factions.cmd.arg.ARFaction; import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast; -import com.massivecraft.factions.event.FactionRelationEvent; +import com.massivecraft.factions.event.FactionsEventRelationChange; import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.mcore.cmd.req.ReqHasPerm; @@ -28,8 +26,11 @@ public abstract class CmdFactionsRelationAbstract extends FCommand @Override public void perform() { - Faction them = this.arg(0, ARFaction.get()); - if (them == null) return; + // Args + Faction otherFaction = this.arg(0, ARFaction.get()); + if (otherFaction == null) return; + + Rel newRelation = targetRelation; /*if ( ! them.isNormal()) { @@ -37,60 +38,60 @@ public abstract class CmdFactionsRelationAbstract extends FCommand return; }*/ - if (them == myFaction) + // Verify + + if (otherFaction == myFaction) { msg("Nope! You can't declare a relation to yourself :)"); return; } - if (myFaction.getRelationWish(them) == targetRelation) + if (myFaction.getRelationWish(otherFaction) == newRelation) { - msg("You already have that relation wish set with %s.", them.getTag()); + msg("You already have that relation wish set with %s.", otherFaction.getTag()); return; } - - // 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())) return; + + // Event + FactionsEventRelationChange event = new FactionsEventRelationChange(sender, myFaction, otherFaction, newRelation); + event.run(); + if (event.isCancelled()) return; + newRelation = event.getNewRelation(); // try to set the new relation - Rel oldRelation = myFaction.getRelationTo(them, true); - myFaction.setRelationWish(them, targetRelation); - Rel currentRelation = myFaction.getRelationTo(them, true); + myFaction.setRelationWish(otherFaction, newRelation); + Rel currentRelation = myFaction.getRelationTo(otherFaction, true); // if the relation change was successful - if (targetRelation == currentRelation) + if (newRelation == 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()); + otherFaction.msg("%s is now %s.", myFaction.describeTo(otherFaction, true), newRelation.getDescFactionOne()); + myFaction.msg("%s is now %s.", otherFaction.describeTo(myFaction, true), newRelation.getDescFactionOne()); } // inform the other faction of your request else { - them.msg("%s wishes to be %s.", myFaction.describeTo(them, true), targetRelation.getColor()+targetRelation.getDescFactionOne()); - them.msg("Type /"+ConfServer.baseCommandAliases.get(0)+" "+targetRelation+" "+myFaction.getTag()+" to accept."); - myFaction.msg("%s were informed that you wish to be %s.", them.describeTo(myFaction, true), targetRelation.getColor()+targetRelation.getDescFactionOne()); + otherFaction.msg("%s wishes to be %s.", myFaction.describeTo(otherFaction, true), newRelation.getColor()+newRelation.getDescFactionOne()); + otherFaction.msg("Type /"+ConfServer.baseCommandAliases.get(0)+" "+newRelation+" "+myFaction.getTag()+" to accept."); + myFaction.msg("%s were informed that you wish to be %s.", otherFaction.describeTo(myFaction, true), newRelation.getColor()+newRelation.getDescFactionOne()); } // 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)) + if ( newRelation != Rel.TRUCE && otherFaction.getFlag(FFlag.PEACEFUL)) { - them.msg("This will have no effect while your faction is peaceful."); + otherFaction.msg("This will have no effect while your faction is peaceful."); myFaction.msg("This will have no effect while their faction is peaceful."); } - if ( targetRelation != Rel.TRUCE && myFaction.getFlag(FFlag.PEACEFUL)) + if ( newRelation != Rel.TRUCE && myFaction.getFlag(FFlag.PEACEFUL)) { - them.msg("This will have no effect while their faction is peaceful."); + otherFaction.msg("This will have no effect while their faction is peaceful."); myFaction.msg("This will have no effect while your faction is peaceful."); } - SpoutFeatures.updateTitle(myFaction, them); - SpoutFeatures.updateTitle(them, myFaction); + SpoutFeatures.updateTitle(myFaction, otherFaction); + SpoutFeatures.updateTitle(otherFaction, myFaction); SpoutFeatures.updateTerritoryDisplayLoc(null); } } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsSethome.java b/src/com/massivecraft/factions/cmd/CmdFactionsSethome.java index 4a8d12b4..74480f27 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsSethome.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsSethome.java @@ -6,7 +6,7 @@ import com.massivecraft.factions.Faction; import com.massivecraft.factions.Factions; import com.massivecraft.factions.Perm; import com.massivecraft.factions.cmd.arg.ARFaction; -import com.massivecraft.factions.event.FactionsHomeChangeEvent; +import com.massivecraft.factions.event.FactionsEventHomeChange; import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqIsPlayer; import com.massivecraft.mcore.ps.PS; @@ -48,14 +48,11 @@ public class CmdFactionsSethome extends FCommand return; } - FactionsHomeChangeEvent event = new FactionsHomeChangeEvent(sender, FactionsHomeChangeEvent.REASON_COMMAND_SETHOME, faction, newHome); + FactionsEventHomeChange event = new FactionsEventHomeChange(sender, faction, newHome); event.run(); if (event.isCancelled()) return; newHome = event.getNewHome(); - // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay - if (!payForCommand(ConfServer.econCostSethome)) return; - faction.setHome(newHome); faction.msg("%s set the home for your faction. You can now use:", fme.describeTo(myFaction, true)); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsTag.java b/src/com/massivecraft/factions/cmd/CmdFactionsTag.java index 7652e60c..a3fc683c 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsTag.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsTag.java @@ -10,7 +10,7 @@ import com.massivecraft.factions.FactionColl; import com.massivecraft.factions.Perm; import com.massivecraft.factions.Rel; import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast; -import com.massivecraft.factions.event.FactionRenameEvent; +import com.massivecraft.factions.event.FactionsEventTagChange; import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.factions.util.MiscUtil; import com.massivecraft.mcore.cmd.req.ReqHasPerm; @@ -31,33 +31,33 @@ public class CmdFactionsTag extends FCommand @Override public void perform() { - String tag = this.arg(0); + // Arg + String newTag = this.arg(0); // TODO does not first test cover selfcase? - if (FactionColl.get().isTagTaken(tag) && ! MiscUtil.getComparisonString(tag).equals(myFaction.getComparisonTag())) + if (FactionColl.get().isTagTaken(newTag) && ! MiscUtil.getComparisonString(newTag).equals(myFaction.getComparisonTag())) { msg("That tag is already taken"); return; } ArrayList errors = new ArrayList(); - errors.addAll(FactionColl.validateTag(tag)); + errors.addAll(FactionColl.validateTag(newTag)); if (errors.size() > 0) { sendMessage(errors); return; } - // trigger the faction rename event (cancellable) - FactionRenameEvent renameEvent = new FactionRenameEvent(fme, tag); + // Event + FactionsEventTagChange renameEvent = new FactionsEventTagChange(sender, myFaction, newTag); Bukkit.getServer().getPluginManager().callEvent(renameEvent); - if(renameEvent.isCancelled()) return; - - // then make 'em pay (if applicable) - if (!payForCommand(ConfServer.econCostTag)) return; + if (renameEvent.isCancelled()) return; + newTag = renameEvent.getNewTag(); + // Apply String oldtag = myFaction.getTag(); - myFaction.setTag(tag); + myFaction.setTag(newTag); // Inform myFaction.msg("%s changed your faction tag to %s", fme.describeTo(myFaction, true), myFaction.getTag(myFaction)); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsTitle.java b/src/com/massivecraft/factions/cmd/CmdFactionsTitle.java index e422ad56..d47b0175 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsTitle.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsTitle.java @@ -6,6 +6,7 @@ import com.massivecraft.factions.Perm; import com.massivecraft.factions.Rel; import com.massivecraft.factions.cmd.arg.ARFPlayer; import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast; +import com.massivecraft.factions.event.FactionsEventTitleChange; import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.mcore.cmd.arg.ARString; import com.massivecraft.mcore.cmd.req.ReqHasPerm; @@ -26,18 +27,24 @@ public class CmdFactionsTitle extends FCommand @Override public void perform() { + // Args FPlayer you = this.arg(0, ARFPlayer.getStartAny()); if (you == null) return; - String title = this.argConcatFrom(1, ARString.get(), ""); - if (title == null) return; + String newTitle = this.argConcatFrom(1, ARString.get(), ""); + if (newTitle == null) return; + // Verify if ( ! canIAdministerYou(fme, you)) return; - // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay - if (!payForCommand(ConfServer.econCostTitle)) return; + // Event + FactionsEventTitleChange event = new FactionsEventTitleChange(sender, you, newTitle); + event.run(); + if (event.isCancelled()) return; + newTitle = event.getNewTitle(); - you.setTitle(title); + // Apply + you.setTitle(newTitle); // Inform myFaction.msg("%s changed a title: %s", fme.describeTo(myFaction, true), you.describeTo(myFaction, true)); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsUnclaim.java b/src/com/massivecraft/factions/cmd/CmdFactionsUnclaim.java index af0a7030..46e1df6e 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsUnclaim.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsUnclaim.java @@ -3,7 +3,7 @@ package com.massivecraft.factions.cmd; import org.bukkit.Bukkit; import com.massivecraft.factions.ConfServer; -import com.massivecraft.factions.event.LandUnclaimEvent; +import com.massivecraft.factions.event.FactionsEventLandUnclaim; import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.factions.BoardColl; @@ -33,7 +33,7 @@ public class CmdFactionsUnclaim extends FCommand if ( ! FPerm.TERRITORY.has(sender, otherFaction, true)) return; - LandUnclaimEvent unclaimEvent = new LandUnclaimEvent(chunk, otherFaction, fme); + FactionsEventLandUnclaim unclaimEvent = new FactionsEventLandUnclaim(sender, otherFaction, chunk); Bukkit.getServer().getPluginManager().callEvent(unclaimEvent); if(unclaimEvent.isCancelled()) return; diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsUnclaimall.java b/src/com/massivecraft/factions/cmd/CmdFactionsUnclaimall.java index efc27ae9..51ec7c38 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsUnclaimall.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsUnclaimall.java @@ -8,7 +8,7 @@ import com.massivecraft.factions.Factions; import com.massivecraft.factions.Perm; import com.massivecraft.factions.Rel; import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast; -import com.massivecraft.factions.event.LandUnclaimAllEvent; +import com.massivecraft.factions.event.FactionsEventLandUnclaimAll; import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.mcore.cmd.req.ReqHasPerm; @@ -39,7 +39,7 @@ public class CmdFactionsUnclaimall extends FCommand } } - LandUnclaimAllEvent unclaimAllEvent = new LandUnclaimAllEvent(myFaction, fme); + FactionsEventLandUnclaimAll unclaimAllEvent = new FactionsEventLandUnclaimAll(sender, myFaction); Bukkit.getServer().getPluginManager().callEvent(unclaimAllEvent); // this event cannot be cancelled diff --git a/src/com/massivecraft/factions/cmd/FCommand.java b/src/com/massivecraft/factions/cmd/FCommand.java index e167dc6b..47506b60 100644 --- a/src/com/massivecraft/factions/cmd/FCommand.java +++ b/src/com/massivecraft/factions/cmd/FCommand.java @@ -4,7 +4,6 @@ import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayerColl; import com.massivecraft.factions.Faction; import com.massivecraft.factions.Rel; -import com.massivecraft.factions.integration.Econ; import com.massivecraft.mcore.cmd.MCommand; import com.massivecraft.mcore.util.Txt; @@ -61,8 +60,8 @@ public abstract class FCommand extends MCommand } // if economy is enabled and they're not on the bypass list, make 'em pay; returns true unless person can't afford the cost - public boolean payForCommand(double cost) + /*public boolean payForCommand(double cost) { return Econ.payForAction(cost, sender, this.getDesc()); - } + }*/ } diff --git a/src/com/massivecraft/factions/event/FactionDisbandEvent.java b/src/com/massivecraft/factions/event/FactionDisbandEvent.java deleted file mode 100644 index 67404dbf..00000000 --- a/src/com/massivecraft/factions/event/FactionDisbandEvent.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.massivecraft.factions.event; - -import org.bukkit.command.CommandSender; -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; -import com.massivecraft.factions.FactionColl; - -public class FactionDisbandEvent extends Event implements Cancellable -{ - // -------------------------------------------- // - // REQUIRED EVENT CODE - // -------------------------------------------- // - - private static final HandlerList handlers = new HandlerList(); - @Override public HandlerList getHandlers() { return handlers; } - public static HandlerList getHandlerList() { return handlers; } - - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - private boolean cancelled; - @Override public boolean isCancelled() { return this.cancelled; } - @Override public void setCancelled(boolean cancelled) { this.cancelled = cancelled; } - - // TODO: Could the fields be reorganized to achieve symmetry? - - private String id; - private CommandSender sender; - - public Faction getFaction() - { - return FactionColl.get().get(id); - } - - public FPlayer getFPlayer() - { - return FPlayer.get(sender); - } - - public CommandSender getPlayer() - { - return this.sender; - } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public FactionDisbandEvent(CommandSender sender, String factionId) - { - this.cancelled = false; - this.sender = sender; - this.id = factionId; - } - - // -------------------------------------------- // - // ASSORTED - // -------------------------------------------- // - - - - -} diff --git a/src/com/massivecraft/factions/event/FactionRenameEvent.java b/src/com/massivecraft/factions/event/FactionRenameEvent.java deleted file mode 100644 index 2839d738..00000000 --- a/src/com/massivecraft/factions/event/FactionRenameEvent.java +++ /dev/null @@ -1,60 +0,0 @@ -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 -{ - // -------------------------------------------- // - // REQUIRED EVENT CODE - // -------------------------------------------- // - - private static final HandlerList handlers = new HandlerList(); - @Override public HandlerList getHandlers() { return handlers; } - public static HandlerList getHandlerList() { return handlers; } - - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - private boolean cancelled; - @Override public boolean isCancelled() { return this.cancelled; } - @Override public void setCancelled(boolean cancelled) { this.cancelled = cancelled; } - - private final FPlayer fplayer; - public FPlayer getFPlayer() { return this.fplayer; } - - private final Faction faction; - public Faction getFaction() { return this.faction; } - - private String tag; - - - // TODO: fix these - public Player getPlayer() { return this.fplayer.getPlayer(); } - public String getOldFactionTag() { return this.faction.getTag(); } - public String getFactionTag() { return this.tag; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public FactionRenameEvent(FPlayer sender, String newTag) - { - this.cancelled = false; - this.fplayer = sender; - this.faction = sender.getFaction(); // TODO: Players can only rename their own faction? A field and constructor rewrite is probably pending for this class... - this.tag = newTag; - } - - - - - - -} diff --git a/src/com/massivecraft/factions/event/FactionsEventAbstract.java b/src/com/massivecraft/factions/event/FactionsEventAbstract.java new file mode 100644 index 00000000..cbed080e --- /dev/null +++ b/src/com/massivecraft/factions/event/FactionsEventAbstract.java @@ -0,0 +1,8 @@ +package com.massivecraft.factions.event; + +import com.massivecraft.mcore.event.MCoreEvent; + +public abstract class FactionsEventAbstract extends MCoreEvent +{ + +} diff --git a/src/com/massivecraft/factions/event/FactionsEventAbstractSender.java b/src/com/massivecraft/factions/event/FactionsEventAbstractSender.java new file mode 100644 index 00000000..b00665c5 --- /dev/null +++ b/src/com/massivecraft/factions/event/FactionsEventAbstractSender.java @@ -0,0 +1,26 @@ +package com.massivecraft.factions.event; + +import org.bukkit.command.CommandSender; + +import com.massivecraft.factions.FPlayer; +import com.massivecraft.mcore.event.MCoreEvent; + +public abstract class FactionsEventAbstractSender extends MCoreEvent +{ + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private final CommandSender sender; + public CommandSender getSender() { return this.sender; } + public FPlayer getFSender() { return FPlayer.get(this.sender); } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public FactionsEventAbstractSender(CommandSender sender) + { + this.sender = sender; + } +} diff --git a/src/com/massivecraft/factions/event/FactionCreateEvent.java b/src/com/massivecraft/factions/event/FactionsEventCreate.java similarity index 65% rename from src/com/massivecraft/factions/event/FactionCreateEvent.java rename to src/com/massivecraft/factions/event/FactionsEventCreate.java index 5f9e2505..6f667257 100644 --- a/src/com/massivecraft/factions/event/FactionCreateEvent.java +++ b/src/com/massivecraft/factions/event/FactionsEventCreate.java @@ -1,11 +1,9 @@ package com.massivecraft.factions.event; import org.bukkit.command.CommandSender; -import org.bukkit.event.Cancellable; -import org.bukkit.event.Event; import org.bukkit.event.HandlerList; -public class FactionCreateEvent extends Event implements Cancellable +public class FactionsEventCreate extends FactionsEventAbstractSender { // -------------------------------------------- // // REQUIRED EVENT CODE @@ -18,13 +16,6 @@ public class FactionCreateEvent extends Event implements Cancellable // -------------------------------------------- // // FIELDS // -------------------------------------------- // - - private boolean cancelled = false; - @Override public boolean isCancelled() { return this.cancelled; } - @Override public void setCancelled(boolean cancelled) { this.cancelled = cancelled; } - - private final CommandSender sender; - public CommandSender getSender() { return this.sender; } // TODO: How do we know what universe? Should we perhaps actually create the faction? @@ -38,9 +29,9 @@ public class FactionCreateEvent extends Event implements Cancellable // CONSTRUCT // -------------------------------------------- // - public FactionCreateEvent(CommandSender sender, String factionTag, String factionId) + public FactionsEventCreate(CommandSender sender, String factionTag, String factionId) { - this.sender = sender; + super(sender); this.factionTag = factionTag; this.factionId = factionId; } diff --git a/src/com/massivecraft/factions/event/FactionsEventDescriptionChange.java b/src/com/massivecraft/factions/event/FactionsEventDescriptionChange.java new file mode 100644 index 00000000..fd141804 --- /dev/null +++ b/src/com/massivecraft/factions/event/FactionsEventDescriptionChange.java @@ -0,0 +1,40 @@ +package com.massivecraft.factions.event; + +import org.bukkit.command.CommandSender; +import org.bukkit.event.HandlerList; + +import com.massivecraft.factions.Faction; + +public class FactionsEventDescriptionChange extends FactionsEventAbstractSender +{ + // -------------------------------------------- // + // REQUIRED EVENT CODE + // -------------------------------------------- // + + private static final HandlerList handlers = new HandlerList(); + @Override public HandlerList getHandlers() { return handlers; } + public static HandlerList getHandlerList() { return handlers; } + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private final Faction faction; + public Faction getFaction() { return this.faction; } + + private String newDescription; + public String getNewDescription() { return this.newDescription; } + public void setNewDescription(String newDescription) { this.newDescription = newDescription; } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public FactionsEventDescriptionChange(CommandSender sender, Faction faction, String newDescription) + { + super(sender); + this.faction = faction; + this.newDescription = newDescription; + } + +} diff --git a/src/com/massivecraft/factions/event/FactionsEventDisband.java b/src/com/massivecraft/factions/event/FactionsEventDisband.java new file mode 100644 index 00000000..7d881a22 --- /dev/null +++ b/src/com/massivecraft/factions/event/FactionsEventDisband.java @@ -0,0 +1,46 @@ +package com.massivecraft.factions.event; + +import org.bukkit.command.CommandSender; +import org.bukkit.event.HandlerList; + +import com.massivecraft.factions.Faction; + +public class FactionsEventDisband extends FactionsEventAbstractSender +{ + // -------------------------------------------- // + // REQUIRED EVENT CODE + // -------------------------------------------- // + + private static final HandlerList handlers = new HandlerList(); + @Override public HandlerList getHandlers() { return handlers; } + public static HandlerList getHandlerList() { return handlers; } + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private final Faction faction; + public Faction getFaction() { return this.faction; } + + private final String factionId; + public String getFactionId() { return this.factionId; } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public FactionsEventDisband(CommandSender sender, Faction faction) + { + super(sender); + this.faction = faction; + this.factionId = faction.getId(); + } + + // -------------------------------------------- // + // ASSORTED + // -------------------------------------------- // + + + + +} diff --git a/src/com/massivecraft/factions/event/FactionsHomeChangeEvent.java b/src/com/massivecraft/factions/event/FactionsEventHomeChange.java similarity index 54% rename from src/com/massivecraft/factions/event/FactionsHomeChangeEvent.java rename to src/com/massivecraft/factions/event/FactionsEventHomeChange.java index 7cda7710..40d51406 100644 --- a/src/com/massivecraft/factions/event/FactionsHomeChangeEvent.java +++ b/src/com/massivecraft/factions/event/FactionsEventHomeChange.java @@ -4,19 +4,10 @@ import org.bukkit.command.CommandSender; import org.bukkit.event.HandlerList; import com.massivecraft.factions.Faction; -import com.massivecraft.mcore.event.MCoreCancellableEvent; import com.massivecraft.mcore.ps.PS; -public class FactionsHomeChangeEvent extends MCoreCancellableEvent -{ - // -------------------------------------------- // - // CONSTANTS - // -------------------------------------------- // - - public final static String REASON_COMMAND_SETHOME = "FACTIONS_COMMAND_SETHOME"; - public final static String REASON_VERIFY_FAILED = "FACTIONS_VERIFY_FAILED"; - public final static String REASON_UNDEFINED = "FACTIONS_UNDEFINED"; - +public class FactionsEventHomeChange extends FactionsEventAbstractSender +{ // -------------------------------------------- // // REQUIRED EVENT CODE // -------------------------------------------- // @@ -29,12 +20,6 @@ public class FactionsHomeChangeEvent extends MCoreCancellableEvent // FIELDS // -------------------------------------------- // - private final CommandSender sender; - public CommandSender getSender() { return this.sender; } - - private final String reason; - public String getReason() { return this.reason; } - private final Faction faction; public Faction getFaction() { return this.faction; } @@ -46,10 +31,9 @@ public class FactionsHomeChangeEvent extends MCoreCancellableEvent // CONSTRUCT // -------------------------------------------- // - public FactionsHomeChangeEvent(CommandSender sender, String reason, Faction faction, PS newHome) + public FactionsEventHomeChange(CommandSender sender, Faction faction, PS newHome) { - this.sender = sender; - this.reason = reason; + super(sender); this.faction = faction; this.newHome = newHome; } diff --git a/src/com/massivecraft/factions/event/LandUnclaimAllEvent.java b/src/com/massivecraft/factions/event/FactionsEventInvitedChange.java old mode 100755 new mode 100644 similarity index 67% rename from src/com/massivecraft/factions/event/LandUnclaimAllEvent.java rename to src/com/massivecraft/factions/event/FactionsEventInvitedChange.java index 54b2b46f..c89302a3 --- a/src/com/massivecraft/factions/event/LandUnclaimAllEvent.java +++ b/src/com/massivecraft/factions/event/FactionsEventInvitedChange.java @@ -1,14 +1,13 @@ package com.massivecraft.factions.event; -import org.bukkit.event.Event; +import org.bukkit.command.CommandSender; import org.bukkit.event.HandlerList; -import com.massivecraft.factions.Faction; import com.massivecraft.factions.FPlayer; -import org.bukkit.entity.Player; +import com.massivecraft.factions.Faction; -public class LandUnclaimAllEvent extends Event -{ +public class FactionsEventInvitedChange extends FactionsEventAbstractSender +{ // -------------------------------------------- // // REQUIRED EVENT CODE // -------------------------------------------- // @@ -16,30 +15,31 @@ public class LandUnclaimAllEvent extends Event private static final HandlerList handlers = new HandlerList(); @Override public HandlerList getHandlers() { return handlers; } public static HandlerList getHandlerList() { return handlers; } - + // -------------------------------------------- // // FIELDS // -------------------------------------------- // - - private final Faction faction; - public Faction getFaction() { return this.faction; } private final FPlayer fplayer; public FPlayer getFPlayer() { return this.fplayer; } - // TODO: These methods seem redundant? Why were they added? Can I remove them? - public String getFactionId() { return this.faction.getId(); } - public String getFactionTag() { return this.faction.getTag(); } - public Player getPlayer() { return this.fplayer.getPlayer(); } + private final Faction faction; + public Faction getFaction() { return this.faction; } + + private boolean newInvited; + public boolean isNewInvited() { return this.newInvited; } + public void setNewInvited(boolean newInvited) { this.newInvited = newInvited; } // -------------------------------------------- // // CONSTRUCT // -------------------------------------------- // - - public LandUnclaimAllEvent(Faction faction, FPlayer fplayer) + + public FactionsEventInvitedChange(CommandSender sender, FPlayer fplayer, Faction faction, boolean newInvited) { - this.faction = faction; + super(sender); this.fplayer = fplayer; + this.faction = faction; + this.newInvited = newInvited; } -} +} \ No newline at end of file diff --git a/src/com/massivecraft/factions/event/FPlayerJoinEvent.java b/src/com/massivecraft/factions/event/FactionsEventJoin.java similarity index 58% rename from src/com/massivecraft/factions/event/FPlayerJoinEvent.java rename to src/com/massivecraft/factions/event/FactionsEventJoin.java index 12e34089..fe29e17b 100644 --- a/src/com/massivecraft/factions/event/FPlayerJoinEvent.java +++ b/src/com/massivecraft/factions/event/FactionsEventJoin.java @@ -1,13 +1,12 @@ package com.massivecraft.factions.event; -import org.bukkit.event.Cancellable; -import org.bukkit.event.Event; +import org.bukkit.command.CommandSender; import org.bukkit.event.HandlerList; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.Faction; -public class FPlayerJoinEvent extends Event implements Cancellable +public class FactionsEventJoin extends FactionsEventAbstractSender { // -------------------------------------------- // // REQUIRED EVENT CODE @@ -21,37 +20,26 @@ public class FPlayerJoinEvent extends Event implements Cancellable // FIELDS // -------------------------------------------- // - private FPlayer fplayer; - private Faction faction; - private PlayerJoinReason reason; + private final FPlayer fplayer; + public FPlayer getFPlayer() { return this.fplayer; } - private boolean cancelled = false; - @Override public boolean isCancelled() { return this.cancelled; } - @Override public void setCancelled(boolean cancelled) { this.cancelled = cancelled; } + private final Faction faction; + public Faction getFaction() { return this.faction; } + + private final PlayerJoinReason reason; + public PlayerJoinReason getReason() { return reason; } // -------------------------------------------- // // CONSTRUCT // -------------------------------------------- // - public FPlayerJoinEvent(FPlayer fplayer, Faction faction, PlayerJoinReason reason) + public FactionsEventJoin(CommandSender sender, FPlayer fplayer, Faction faction, PlayerJoinReason reason) { + super(sender); this.fplayer = fplayer; this.faction = faction; this.reason = reason; } - - public FPlayer getFPlayer() - { - return fplayer; - } - public Faction getFaction() - { - return faction; - } - public PlayerJoinReason getReason() - { - return reason; - } // -------------------------------------------- // // INTERNAL ENUM @@ -59,7 +47,7 @@ public class FPlayerJoinEvent extends Event implements Cancellable public enum PlayerJoinReason { - CREATE, LEADER, COMMAND + CREATE, LEADER, JOIN } } \ No newline at end of file diff --git a/src/com/massivecraft/factions/event/LandUnclaimEvent.java b/src/com/massivecraft/factions/event/FactionsEventLandClaim.java similarity index 52% rename from src/com/massivecraft/factions/event/LandUnclaimEvent.java rename to src/com/massivecraft/factions/event/FactionsEventLandClaim.java index 95009f1b..9702c8ea 100644 --- a/src/com/massivecraft/factions/event/LandUnclaimEvent.java +++ b/src/com/massivecraft/factions/event/FactionsEventLandClaim.java @@ -1,16 +1,12 @@ package com.massivecraft.factions.event; -import org.bukkit.event.Cancellable; -import org.bukkit.event.Event; +import org.bukkit.command.CommandSender; import org.bukkit.event.HandlerList; import com.massivecraft.factions.Faction; -import com.massivecraft.factions.FPlayer; import com.massivecraft.mcore.ps.PS; -import org.bukkit.entity.Player; - -public class LandUnclaimEvent extends Event implements Cancellable +public class FactionsEventLandClaim extends FactionsEventAbstractSender { // -------------------------------------------- // // REQUIRED EVENT CODE @@ -19,39 +15,26 @@ public class LandUnclaimEvent extends Event implements Cancellable private static final HandlerList handlers = new HandlerList(); @Override public HandlerList getHandlers() { return handlers; } public static HandlerList getHandlerList() { return handlers; } - + // -------------------------------------------- // // FIELDS // -------------------------------------------- // - private boolean cancelled; - @Override public boolean isCancelled() { return this.cancelled; } - @Override public void setCancelled(boolean cancelled) { this.cancelled = cancelled; } - - private final PS chunk; - public PS getChunk() { return this.chunk; } - private final Faction faction; public Faction getFaction() { return this.faction; } - private final FPlayer fplayer; - public FPlayer getFPlayer() { return this.fplayer; } - - // TODO: These methods seem redundant? Why were they added? Can I remove them? - public String getFactionId() { return this.faction.getId(); } - public String getFactionTag() { return this.faction.getTag(); } - public Player getPlayer() { return this.fplayer.getPlayer(); } + private final PS chunk; + public PS getChunk() { return this.chunk; } // -------------------------------------------- // // CONSTRUCT // -------------------------------------------- // - public LandUnclaimEvent(PS chunk, Faction faction, FPlayer fplayer) + public FactionsEventLandClaim(CommandSender sender, Faction faction, PS chunk) { - this.cancelled = false; - this.chunk = chunk.getChunk(true); + super(sender); this.faction = faction; - this.fplayer = fplayer; + this.chunk = chunk.getChunk(true); } } diff --git a/src/com/massivecraft/factions/event/LandClaimEvent.java b/src/com/massivecraft/factions/event/FactionsEventLandUnclaim.java similarity index 52% rename from src/com/massivecraft/factions/event/LandClaimEvent.java rename to src/com/massivecraft/factions/event/FactionsEventLandUnclaim.java index 439c8068..bd1c0465 100644 --- a/src/com/massivecraft/factions/event/LandClaimEvent.java +++ b/src/com/massivecraft/factions/event/FactionsEventLandUnclaim.java @@ -1,16 +1,12 @@ package com.massivecraft.factions.event; -import org.bukkit.event.Cancellable; -import org.bukkit.event.Event; +import org.bukkit.command.CommandSender; import org.bukkit.event.HandlerList; import com.massivecraft.factions.Faction; -import com.massivecraft.factions.FPlayer; import com.massivecraft.mcore.ps.PS; -import org.bukkit.entity.Player; - -public class LandClaimEvent extends Event implements Cancellable +public class FactionsEventLandUnclaim extends FactionsEventAbstractSender { // -------------------------------------------- // // REQUIRED EVENT CODE @@ -19,39 +15,26 @@ public class LandClaimEvent extends Event implements Cancellable private static final HandlerList handlers = new HandlerList(); @Override public HandlerList getHandlers() { return handlers; } public static HandlerList getHandlerList() { return handlers; } - + // -------------------------------------------- // // FIELDS // -------------------------------------------- // - private boolean cancelled = false; - @Override public boolean isCancelled() { return this.cancelled; } - @Override public void setCancelled(boolean cancelled) { this.cancelled = cancelled; } + private final Faction faction; + public Faction getFaction() { return this.faction; } private final PS chunk; public PS getChunk() { return this.chunk; } - private final Faction faction; - public Faction getFaction() { return this.faction; } - - private final FPlayer fplayer; - public FPlayer getFPlayer() { return this.fplayer; } - - // TODO: These methods seem redundant? Why were they added? Can I remove them? - public String getFactionId() { return faction.getId(); } - public String getFactionTag() { return this.faction.getTag(); } - public Player getPlayer() { return this.fplayer.getPlayer(); } - // -------------------------------------------- // // CONSTRUCT // -------------------------------------------- // - public LandClaimEvent(PS chunk, Faction faction, FPlayer fplayer) + public FactionsEventLandUnclaim(CommandSender sender, Faction faction, PS chunk) { - this.cancelled = false; + super(sender); this.chunk = chunk.getChunk(true); this.faction = faction; - this.fplayer = fplayer; } } diff --git a/src/com/massivecraft/factions/event/FactionsEventLandUnclaimAll.java b/src/com/massivecraft/factions/event/FactionsEventLandUnclaimAll.java new file mode 100644 index 00000000..d3257966 --- /dev/null +++ b/src/com/massivecraft/factions/event/FactionsEventLandUnclaimAll.java @@ -0,0 +1,35 @@ +package com.massivecraft.factions.event; + +import org.bukkit.command.CommandSender; +import org.bukkit.event.HandlerList; + +import com.massivecraft.factions.Faction; + +public class FactionsEventLandUnclaimAll extends FactionsEventAbstractSender +{ + // -------------------------------------------- // + // REQUIRED EVENT CODE + // -------------------------------------------- // + + private static final HandlerList handlers = new HandlerList(); + @Override public HandlerList getHandlers() { return handlers; } + public static HandlerList getHandlerList() { return handlers; } + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private final Faction faction; + public Faction getFaction() { return this.faction; } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public FactionsEventLandUnclaimAll(CommandSender sender, Faction faction) + { + super(sender); + this.faction = faction; + } + +} diff --git a/src/com/massivecraft/factions/event/FPlayerLeaveEvent.java b/src/com/massivecraft/factions/event/FactionsEventLeave.java similarity index 73% rename from src/com/massivecraft/factions/event/FPlayerLeaveEvent.java rename to src/com/massivecraft/factions/event/FactionsEventLeave.java index ef35958a..e345f3db 100644 --- a/src/com/massivecraft/factions/event/FPlayerLeaveEvent.java +++ b/src/com/massivecraft/factions/event/FactionsEventLeave.java @@ -1,13 +1,12 @@ package com.massivecraft.factions.event; -import org.bukkit.event.Cancellable; -import org.bukkit.event.Event; +import org.bukkit.command.CommandSender; import org.bukkit.event.HandlerList; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.Faction; -public class FPlayerLeaveEvent extends Event implements Cancellable +public class FactionsEventLeave extends FactionsEventAbstractSender { // -------------------------------------------- // // REQUIRED EVENT CODE @@ -21,35 +20,32 @@ public class FPlayerLeaveEvent extends Event implements Cancellable // FIELDS // -------------------------------------------- // - private boolean cancelled; - @Override public boolean isCancelled() { return this.cancelled; } @Override - public void setCancelled(boolean c) + public void setCancelled(boolean cancelled) { - if (reason == PlayerLeaveReason.DISBAND || reason == PlayerLeaveReason.RESET) + if (this.reason == PlayerLeaveReason.DISBAND || this.reason == PlayerLeaveReason.RESET) { cancelled = false; - return; } - cancelled = c; + super.setCancelled(cancelled); } - private final PlayerLeaveReason reason; - public PlayerLeaveReason getReason() { return this.reason; } - private final FPlayer fplayer; public FPlayer getFPlayer() { return this.fplayer; } private final Faction faction; public Faction getFaction() { return this.faction; } + + private final PlayerLeaveReason reason; + public PlayerLeaveReason getReason() { return this.reason; } // -------------------------------------------- // // CONSTRUCT // -------------------------------------------- // - public FPlayerLeaveEvent(FPlayer fplayer, Faction faction, PlayerLeaveReason reason) + public FactionsEventLeave(CommandSender sender, FPlayer fplayer, Faction faction, PlayerLeaveReason reason) { - this.cancelled = false; + super(sender); this.fplayer = fplayer; this.faction = faction; this.reason = reason; diff --git a/src/com/massivecraft/factions/event/FactionsEventOpenChange.java b/src/com/massivecraft/factions/event/FactionsEventOpenChange.java new file mode 100644 index 00000000..b26eba4a --- /dev/null +++ b/src/com/massivecraft/factions/event/FactionsEventOpenChange.java @@ -0,0 +1,40 @@ +package com.massivecraft.factions.event; + +import org.bukkit.command.CommandSender; +import org.bukkit.event.HandlerList; + +import com.massivecraft.factions.Faction; + +public class FactionsEventOpenChange extends FactionsEventAbstractSender +{ + // -------------------------------------------- // + // REQUIRED EVENT CODE + // -------------------------------------------- // + + private static final HandlerList handlers = new HandlerList(); + @Override public HandlerList getHandlers() { return handlers; } + public static HandlerList getHandlerList() { return handlers; } + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private final Faction faction; + public Faction getFaction() { return this.faction; } + + private boolean newOpen; + public boolean isNewOpen() { return this.newOpen; } + public void setNewOpen(boolean newOpen) { this.newOpen = newOpen; } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public FactionsEventOpenChange(CommandSender sender, Faction faction, boolean newOpen) + { + super(sender); + this.faction = faction; + this.newOpen = newOpen; + } + +} diff --git a/src/com/massivecraft/factions/event/FactionsEventPowerLoss.java b/src/com/massivecraft/factions/event/FactionsEventPowerLoss.java new file mode 100644 index 00000000..f817ca13 --- /dev/null +++ b/src/com/massivecraft/factions/event/FactionsEventPowerLoss.java @@ -0,0 +1,27 @@ +package com.massivecraft.factions.event; + +import org.bukkit.command.CommandSender; +import org.bukkit.event.HandlerList; + +public class FactionsEventPowerLoss extends FactionsEventAbstractSender +{ + // -------------------------------------------- // + // REQUIRED EVENT CODE + // -------------------------------------------- // + + private static final HandlerList handlers = new HandlerList(); + @Override public HandlerList getHandlers() { return handlers; } + public static HandlerList getHandlerList() { return handlers; } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + // TODO: Replace this event with a power change event? + + public FactionsEventPowerLoss(CommandSender sender) + { + super(sender); + } + +} diff --git a/src/com/massivecraft/factions/event/FactionRelationEvent.java b/src/com/massivecraft/factions/event/FactionsEventRelationChange.java similarity index 56% rename from src/com/massivecraft/factions/event/FactionRelationEvent.java rename to src/com/massivecraft/factions/event/FactionsEventRelationChange.java index 6256eb08..0e3b4af9 100644 --- a/src/com/massivecraft/factions/event/FactionRelationEvent.java +++ b/src/com/massivecraft/factions/event/FactionsEventRelationChange.java @@ -1,13 +1,13 @@ package com.massivecraft.factions.event; -import org.bukkit.event.Event; +import org.bukkit.command.CommandSender; import org.bukkit.event.HandlerList; import com.massivecraft.factions.Faction; import com.massivecraft.factions.Rel; -public class FactionRelationEvent extends Event +public class FactionsEventRelationChange extends FactionsEventAbstractSender { // -------------------------------------------- // // REQUIRED EVENT CODE @@ -21,32 +21,26 @@ public class FactionRelationEvent extends Event // FIELDS // -------------------------------------------- // - // TODO: Should this one be informative only? - // TODO: How about making it Cancellable? - // TODO: How about making the target relation non-final? - private final Faction faction; public Faction getFaction() { return this.faction; } - private final Faction targetFaction; - public Faction getTargetFaction() { return this.targetFaction; } + private final Faction otherFaction; + public Faction getOtherFaction() { return this.otherFaction; } - private final Rel oldRel; - public Rel getOldRel() { return this.oldRel; } - - private final Rel newRel; - public Rel getNewRel() { return this.newRel; } + private Rel newRelation; + public Rel getNewRelation() { return this.newRelation; } + public void setNewRelation(Rel newRelation) { this.newRelation = newRelation; } // -------------------------------------------- // // CONSTRUCT // -------------------------------------------- // - public FactionRelationEvent(Faction faction, Faction targetFaction, Rel oldRel, Rel newRel) + public FactionsEventRelationChange(CommandSender sender, Faction faction, Faction otherFaction, Rel newRelation) { + super(sender); this.faction = faction; - this.targetFaction = targetFaction; - this.oldRel = oldRel; - this.newRel = newRel; + this.otherFaction = otherFaction; + this.newRelation = newRelation; } -} +} \ No newline at end of file diff --git a/src/com/massivecraft/factions/event/FactionsEventTagChange.java b/src/com/massivecraft/factions/event/FactionsEventTagChange.java new file mode 100644 index 00000000..214c74e0 --- /dev/null +++ b/src/com/massivecraft/factions/event/FactionsEventTagChange.java @@ -0,0 +1,40 @@ +package com.massivecraft.factions.event; + +import org.bukkit.command.CommandSender; +import org.bukkit.event.HandlerList; + +import com.massivecraft.factions.Faction; + +public class FactionsEventTagChange extends FactionsEventAbstractSender +{ + // -------------------------------------------- // + // REQUIRED EVENT CODE + // -------------------------------------------- // + + private static final HandlerList handlers = new HandlerList(); + @Override public HandlerList getHandlers() { return handlers; } + public static HandlerList getHandlerList() { return handlers; } + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private final Faction faction; + public Faction getFaction() { return this.faction; } + + private String newTag; + public String getNewTag() { return this.newTag; } + public void setNewTag(String newTag) { this.newTag = newTag; } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public FactionsEventTagChange(CommandSender sender, Faction faction, String newTag) + { + super(sender); + this.faction = faction; + this.newTag = newTag; + } + +} diff --git a/src/com/massivecraft/factions/event/FactionsEventTitleChange.java b/src/com/massivecraft/factions/event/FactionsEventTitleChange.java new file mode 100644 index 00000000..6a6f3b69 --- /dev/null +++ b/src/com/massivecraft/factions/event/FactionsEventTitleChange.java @@ -0,0 +1,40 @@ +package com.massivecraft.factions.event; + +import org.bukkit.command.CommandSender; +import org.bukkit.event.HandlerList; + +import com.massivecraft.factions.FPlayer; + +public class FactionsEventTitleChange extends FactionsEventAbstractSender +{ + // -------------------------------------------- // + // REQUIRED EVENT CODE + // -------------------------------------------- // + + private static final HandlerList handlers = new HandlerList(); + @Override public HandlerList getHandlers() { return handlers; } + public static HandlerList getHandlerList() { return handlers; } + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private final FPlayer fplayer; + public FPlayer getFPlayer() { return this.fplayer; } + + private String newTitle; + public String getNewTitle() { return this.newTitle; } + public void setNewTitle(String newTitle) { this.newTitle = newTitle; } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public FactionsEventTitleChange(CommandSender sender, FPlayer fplayer, String newTitle) + { + super(sender); + this.fplayer = fplayer; + this.newTitle = newTitle; + } + +} diff --git a/src/com/massivecraft/factions/event/PowerLossEvent.java b/src/com/massivecraft/factions/event/PowerLossEvent.java deleted file mode 100644 index 5f0570df..00000000 --- a/src/com/massivecraft/factions/event/PowerLossEvent.java +++ /dev/null @@ -1,58 +0,0 @@ -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; - -import org.bukkit.entity.Player; - - -public class PowerLossEvent extends Event implements Cancellable -{ - // -------------------------------------------- // - // REQUIRED EVENT CODE - // -------------------------------------------- // - - private static final HandlerList handlers = new HandlerList(); - @Override public HandlerList getHandlers() { return handlers; } - public static HandlerList getHandlerList() { return handlers; } - - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - private boolean cancelled; - @Override public boolean isCancelled() { return this.cancelled; } - @Override public void setCancelled(boolean cancelled) { this.cancelled = cancelled; } - - private final Faction faction; - public Faction getFaction() { return this.faction; } - - private final FPlayer fplayer; - public FPlayer getFPlayer() { return this.fplayer; } - - // TODO: Should message really be set here? Or should it be sent by the plugin that cancells directly? - private String message; - public String getMessage() { return this.message; } - public void setMessage(String message) { this.message = message; } - - // TODO: These methods seem redundant? Why were they added? Can I remove them? - public String getFactionId() { return this.faction.getId(); } - public String getFactionTag() { return this.faction.getTag(); } - public Player getPlayer() { return this.fplayer.getPlayer(); } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public PowerLossEvent(Faction faction, FPlayer fplayer) - { - this.cancelled = false; - this.faction = faction; - this.fplayer = fplayer; - } - -} diff --git a/src/com/massivecraft/factions/listeners/FactionsListenerEcon.java b/src/com/massivecraft/factions/listeners/FactionsListenerEcon.java index e0470a67..3c10b4c1 100644 --- a/src/com/massivecraft/factions/listeners/FactionsListenerEcon.java +++ b/src/com/massivecraft/factions/listeners/FactionsListenerEcon.java @@ -7,8 +7,17 @@ import org.bukkit.event.Listener; import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.Factions; -import com.massivecraft.factions.event.FactionsHomeChangeEvent; +import com.massivecraft.factions.event.FactionsEventAbstractSender; +import com.massivecraft.factions.event.FactionsEventCreate; +import com.massivecraft.factions.event.FactionsEventDescriptionChange; +import com.massivecraft.factions.event.FactionsEventHomeChange; +import com.massivecraft.factions.event.FactionsEventInvitedChange; +import com.massivecraft.factions.event.FactionsEventOpenChange; +import com.massivecraft.factions.event.FactionsEventRelationChange; +import com.massivecraft.factions.event.FactionsEventTagChange; +import com.massivecraft.factions.event.FactionsEventTitleChange; import com.massivecraft.factions.integration.Econ; +import com.massivecraft.mcore.cmd.MCommand; public class FactionsListenerEcon implements Listener { @@ -30,20 +39,67 @@ public class FactionsListenerEcon implements Listener } // -------------------------------------------- // - // LISTENER + // PAY FOR COMMAND // -------------------------------------------- // - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void onFactionsHomeChangeEvent(FactionsHomeChangeEvent event) + public void payForCommand(FactionsEventAbstractSender event, double cost, MCommand command) { - // If the faction home is being changed through a command ... - if (!event.getReason().equals(FactionsHomeChangeEvent.REASON_COMMAND_SETHOME)) return; + // If there is a sender ... + if (event.getSender() == null) return; - // ... and the sender can not afford the command ... - if (Econ.payForAction(ConfServer.econCostSethome, event.getSender(), Factions.get().getOuterCmdFactions().cmdFactionsSethome.getDesc())) return; + // ... and the sender can't afford ... + if (Econ.payForAction(cost, event.getSender(), command.getDesc())) return; - // ... then cancel the change. + // ... then cancel. event.setCancelled(true); } + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void payForCommand(FactionsEventHomeChange event) + { + payForCommand(event, ConfServer.econCostSethome, Factions.get().getOuterCmdFactions().cmdFactionsSethome); + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void payForCommand(FactionsEventCreate event) + { + payForCommand(event, ConfServer.econCostCreate, Factions.get().getOuterCmdFactions().cmdFactionsCreate); + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void payForCommand(FactionsEventDescriptionChange event) + { + payForCommand(event, ConfServer.econCostDescription, Factions.get().getOuterCmdFactions().cmdFactionsDescription); + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void payForCommand(FactionsEventTagChange event) + { + payForCommand(event, ConfServer.econCostTag, Factions.get().getOuterCmdFactions().cmdFactionsTag); + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void payForCommand(FactionsEventTitleChange event) + { + payForCommand(event, ConfServer.econCostTitle, Factions.get().getOuterCmdFactions().cmdFactionsTitle); + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void payForCommand(FactionsEventRelationChange event) + { + payForCommand(event, event.getNewRelation().getRelationCost(), Factions.get().getOuterCmdFactions().cmdFactionsRelationNeutral); + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void payForCommand(FactionsEventOpenChange event) + { + payForCommand(event, ConfServer.econCostOpen, Factions.get().getOuterCmdFactions().cmdFactionsOpen); + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void payForCommand(FactionsEventInvitedChange event) + { + double cost = event.isNewInvited() ? ConfServer.econCostInvite : ConfServer.econCostDeinvite; + payForCommand(event, cost, Factions.get().getOuterCmdFactions().cmdFactionsInvite); + } } diff --git a/src/com/massivecraft/factions/listeners/FactionsListenerMain.java b/src/com/massivecraft/factions/listeners/FactionsListenerMain.java index f94f0273..01465254 100644 --- a/src/com/massivecraft/factions/listeners/FactionsListenerMain.java +++ b/src/com/massivecraft/factions/listeners/FactionsListenerMain.java @@ -35,6 +35,7 @@ import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntityRegainHealthEvent; import org.bukkit.event.entity.EntityTargetEvent; +import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.entity.PotionSplashEvent; import org.bukkit.event.hanging.HangingBreakByEntityEvent; import org.bukkit.event.hanging.HangingBreakEvent; @@ -59,6 +60,7 @@ import com.massivecraft.factions.FPlayerColl; import com.massivecraft.factions.Faction; import com.massivecraft.factions.Factions; import com.massivecraft.factions.Rel; +import com.massivecraft.factions.event.FactionsEventPowerLoss; import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.factions.util.VisualizeUtil; import com.massivecraft.mcore.ps.PS; @@ -84,6 +86,44 @@ public class FactionsListenerMain implements Listener Bukkit.getPluginManager().registerEvents(this, Factions.get()); } + // -------------------------------------------- // + // POWER LOSS ON DEATH + // -------------------------------------------- // + + @EventHandler(priority = EventPriority.NORMAL) + public void powerLossOnDeath(PlayerDeathEvent event) + { + // If a player dies ... + Player player = event.getEntity(); + FPlayer fplayer = FPlayerColl.get().get(player); + + // ... and powerloss can happen here ... + Faction faction = BoardColl.get().getFactionAt(PS.valueOf(player)); + + if (!faction.getFlag(FFlag.POWERLOSS)) + { + fplayer.msg("You didn't lose any power since the territory you died in works that way."); + return; + } + + if (ConfServer.worldsNoPowerLoss.contains(player.getWorld().getName())) + { + fplayer.msg("You didn't lose any power due to the world you died in."); + return; + } + + // ... and our special event doesn't get cancelled ... + FactionsEventPowerLoss powerLossEvent = new FactionsEventPowerLoss(player); + powerLossEvent.run(); + if (powerLossEvent.isCancelled()) return; + + // ... alter the power ... + fplayer.setPower(fplayer.getPower() + ConfServer.powerPerDeath); + + // ... and inform the player. + fplayer.msg("Your power is now %d / %d", fplayer.getPowerRounded(), fplayer.getPowerMaxRounded()); + } + // -------------------------------------------- // // CAN COMBAT DAMAGE HAPPEN // -------------------------------------------- // diff --git a/src/com/massivecraft/factions/listeners/TodoFactionsEntityListener.java b/src/com/massivecraft/factions/listeners/TodoFactionsEntityListener.java deleted file mode 100644 index 6b382018..00000000 --- a/src/com/massivecraft/factions/listeners/TodoFactionsEntityListener.java +++ /dev/null @@ -1,78 +0,0 @@ -package com.massivecraft.factions.listeners; - -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.PlayerDeathEvent; - -import com.massivecraft.factions.BoardColl; -import com.massivecraft.factions.ConfServer; -import com.massivecraft.factions.FFlag; -import com.massivecraft.factions.FPlayer; -import com.massivecraft.factions.FPlayerColl; -import com.massivecraft.factions.Faction; -import com.massivecraft.factions.event.PowerLossEvent; -import com.massivecraft.mcore.ps.PS; - - -public class TodoFactionsEntityListener implements Listener -{ - - // -------------------------------------------- // - // POWER LOSS ON DEATH - // -------------------------------------------- // - - @EventHandler(priority = EventPriority.NORMAL) - public void powerLossOnDeath(PlayerDeathEvent event) - { - // If a player dies ... - Player player = event.getEntity(); - FPlayer fplayer = FPlayerColl.get().get(player); - - // ... TODO: Sending the message through the event is not the best way of doing it. - // TODO: We should listen to our own events and send message from there if we cancel. - // - Faction faction = BoardColl.get().getFactionAt(PS.valueOf(player)); - - PowerLossEvent powerLossEvent = new PowerLossEvent(faction, fplayer); - - // Check for no power loss conditions - if ( ! faction.getFlag(FFlag.POWERLOSS)) - { - powerLossEvent.setMessage("You didn't lose any power since the territory you died in works that way."); - powerLossEvent.setCancelled(true); - } - else if (ConfServer.worldsNoPowerLoss.contains(player.getWorld().getName())) - { - powerLossEvent.setMessage("You didn't lose any power due to the world you died in."); - powerLossEvent.setCancelled(true); - } - else - { - powerLossEvent.setMessage("Your power is now %d / %d"); - } - - // call Event - Bukkit.getPluginManager().callEvent(powerLossEvent); - - // Call player onDeath if the event is not cancelled - if ( ! powerLossEvent.isCancelled()) - { - fplayer.setPower(fplayer.getPower() + ConfServer.powerPerDeath); - } - - // Send the message from the powerLossEvent - final String msg = powerLossEvent.getMessage(); - if (msg != null && !msg.isEmpty()) - { - fplayer.msg(msg, fplayer.getPowerRounded(), fplayer.getPowerMaxRounded()); - } - } - - - - - -}