diff --git a/src/com/massivecraft/factions/FPlayer.java b/src/com/massivecraft/factions/FPlayer.java index 17176d51..dd20b280 100644 --- a/src/com/massivecraft/factions/FPlayer.java +++ b/src/com/massivecraft/factions/FPlayer.java @@ -857,9 +857,10 @@ public class FPlayer extends SenderEntity implements EconomyParticipato if ( ! Econ.hasAtLeast(payee, cost, "to claim this land")) return false; } - FactionsEventLandClaim claimEvent = new FactionsEventLandClaim(sender, forFaction, flocation); - claimEvent.run(); - if (claimEvent.isCancelled()) return false; + // Event + FactionsEventLandClaim event = new FactionsEventLandClaim(sender, forFaction, flocation); + event.run(); + if (event.isCancelled()) return false; // then make 'em pay (if applicable) // TODO: The economy integration should cancel the event above! diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsCreate.java b/src/com/massivecraft/factions/cmd/CmdFactionsCreate.java index 87db2c2e..9018b296 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsCreate.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsCreate.java @@ -2,8 +2,6 @@ package com.massivecraft.factions.cmd; import java.util.ArrayList; -import org.bukkit.Bukkit; - import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayerColl; @@ -30,48 +28,49 @@ public class CmdFactionsCreate extends FCommand @Override public void perform() { - String tag = this.arg(0); + // Args + String newTag = this.arg(0); + // Verify if (fme.hasFaction()) { msg("You must leave your current faction first."); return; } - if (FactionColl.get().isTagTaken(tag)) + if (FactionColl.get().isTagTaken(newTag)) { msg("That tag is already in use."); return; } - ArrayList tagValidationErrors = FactionColl.validateTag(tag); + ArrayList tagValidationErrors = FactionColl.validateTag(newTag); if (tagValidationErrors.size() > 0) { sendMessage(tagValidationErrors); return; } - // trigger the faction creation event (cancellable) + // Pre-Generate Id String factionId = FactionColl.get().getIdStrategy().generate(FactionColl.get()); - FactionsEventCreate createEvent = new FactionsEventCreate(sender, tag, factionId); - Bukkit.getServer().getPluginManager().callEvent(createEvent); + // Event + FactionsEventCreate createEvent = new FactionsEventCreate(sender, newTag, factionId); + createEvent.run(); if (createEvent.isCancelled()) return; + // Apply Faction faction = FactionColl.get().create(factionId); - - // finish setting up the Faction - faction.setTag(tag); + faction.setTag(newTag); + + fme.setRole(Rel.LEADER); + fme.setFaction(faction); - // trigger the faction join event for the creator 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); - fme.setFaction(faction); - + // Inform for (FPlayer follower : FPlayerColl.get().getAllOnline()) { follower.msg("%s created a new faction %s", fme.describeTo(follower, true), faction.getTag(follower)); @@ -80,7 +79,9 @@ public class CmdFactionsCreate extends FCommand msg("You should now: %s", Factions.get().getOuterCmdFactions().cmdFactionsDescription.getUseageTemplate()); if (ConfServer.logFactionCreate) - Factions.get().log(fme.getName()+" created a new faction: "+tag); + { + Factions.get().log(fme.getName()+" created a new faction: "+newTag); + } } } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsDisband.java b/src/com/massivecraft/factions/cmd/CmdFactionsDisband.java index 4d80a7a2..6a45bd03 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsDisband.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsDisband.java @@ -1,7 +1,5 @@ package com.massivecraft.factions.cmd; -import org.bukkit.Bukkit; - import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.cmd.arg.ARFaction; import com.massivecraft.factions.event.FactionsEventLeave; @@ -31,21 +29,27 @@ public class CmdFactionsDisband extends FCommand @Override public void perform() { + // Args Faction faction = this.arg(0, ARFaction.get(), myFaction); if (faction == null) return; + // FPerm if ( ! FPerm.DISBAND.has(sender, faction, true)) return; + // Verify if (faction.getFlag(FFlag.PERMANENT)) { msg("This faction is designated as permanent, so you cannot disband it."); return; } - FactionsEventDisband disbandEvent = new FactionsEventDisband(me, faction); - Bukkit.getServer().getPluginManager().callEvent(disbandEvent); - if(disbandEvent.isCancelled()) return; + // Event + FactionsEventDisband event = new FactionsEventDisband(me, faction); + event.run(); + if (event.isCancelled()) return; + // Merged Apply and Inform + // Send FPlayerLeaveEvent for each player in the faction for ( FPlayer fplayer : faction.getFPlayers() ) { diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsHome.java b/src/com/massivecraft/factions/cmd/CmdFactionsHome.java index ceb305a1..8d791348 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsHome.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsHome.java @@ -14,6 +14,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.FactionsEventHomeTeleport; import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqIsPlayer; import com.massivecraft.mcore.mixin.Mixin; @@ -118,12 +119,15 @@ public class CmdFactionsHome extends FCommand } } + // Event + FactionsEventHomeTeleport event = new FactionsEventHomeTeleport(sender); + event.run(); + if (event.isCancelled()) return; + + // Apply try { Mixin.teleport(me, myFaction.getHome(), "your faction home", sender); - - // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay - if (!payForCommand(ConfServer.econCostHome)) return; } catch (TeleporterException e) { diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsSethome.java b/src/com/massivecraft/factions/cmd/CmdFactionsSethome.java index 74480f27..1721f6da 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsSethome.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsSethome.java @@ -33,28 +33,32 @@ public class CmdFactionsSethome extends FCommand return; } + // Args Faction faction = this.arg(0, ARFaction.get(), myFaction); if (faction == null) return; - // Has faction permission? - if ( ! FPerm.SETHOME.has(sender, faction, true)) return; - PS newHome = PS.valueOf(me.getLocation()); - // Can the player set the faction home HERE? + // FPerm + if ( ! FPerm.SETHOME.has(sender, faction, true)) return; + + // Verify if (!fme.isUsingAdminMode() && !faction.isValidHome(newHome)) { fme.msg("Sorry, your faction home can only be set inside your own claimed territory."); return; } + // Event FactionsEventHomeChange event = new FactionsEventHomeChange(sender, faction, newHome); event.run(); if (event.isCancelled()) return; newHome = event.getNewHome(); + // Apply faction.setHome(newHome); + // Inform faction.msg("%s set the home for your faction. You can now use:", fme.describeTo(myFaction, true)); faction.sendMessage(Factions.get().getOuterCmdFactions().cmdFactionsHome.getUseageTemplate()); if (faction != myFaction) diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsTag.java b/src/com/massivecraft/factions/cmd/CmdFactionsTag.java index a3fc683c..84318622 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsTag.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsTag.java @@ -2,8 +2,6 @@ package com.massivecraft.factions.cmd; import java.util.ArrayList; -import org.bukkit.Bukkit; - import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.Faction; import com.massivecraft.factions.FactionColl; @@ -50,10 +48,10 @@ public class CmdFactionsTag extends FCommand } // Event - FactionsEventTagChange renameEvent = new FactionsEventTagChange(sender, myFaction, newTag); - Bukkit.getServer().getPluginManager().callEvent(renameEvent); - if (renameEvent.isCancelled()) return; - newTag = renameEvent.getNewTag(); + FactionsEventTagChange event = new FactionsEventTagChange(sender, myFaction, newTag); + event.run(); + if (event.isCancelled()) return; + newTag = event.getNewTag(); // Apply String oldtag = myFaction.getTag(); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsUnclaim.java b/src/com/massivecraft/factions/cmd/CmdFactionsUnclaim.java index 46e1df6e..a3f303c9 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsUnclaim.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsUnclaim.java @@ -1,7 +1,5 @@ package com.massivecraft.factions.cmd; -import org.bukkit.Bukkit; - import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.event.FactionsEventLandUnclaim; import com.massivecraft.factions.integration.Econ; @@ -28,14 +26,17 @@ public class CmdFactionsUnclaim extends FCommand @Override public void perform() { + // Args PS chunk = PS.valueOf(me).getChunk(true); Faction otherFaction = BoardColl.get().getFactionAt(chunk); + // FPerm if ( ! FPerm.TERRITORY.has(sender, otherFaction, true)) return; - FactionsEventLandUnclaim unclaimEvent = new FactionsEventLandUnclaim(sender, otherFaction, chunk); - Bukkit.getServer().getPluginManager().callEvent(unclaimEvent); - if(unclaimEvent.isCancelled()) return; + // Event + FactionsEventLandUnclaim event = new FactionsEventLandUnclaim(sender, otherFaction, chunk); + event.run(); + if (event.isCancelled()) return; //String moneyBack = ""; if (Econ.isEnabled()) diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsUnclaimall.java b/src/com/massivecraft/factions/cmd/CmdFactionsUnclaimall.java index 51ec7c38..2a98dafd 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsUnclaimall.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsUnclaimall.java @@ -1,7 +1,5 @@ package com.massivecraft.factions.cmd; -import org.bukkit.Bukkit; - import com.massivecraft.factions.BoardColl; import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.Factions; @@ -26,6 +24,7 @@ public class CmdFactionsUnclaimall extends FCommand @Override public void perform() { + // TODO: Put this as a listener and not in here! if (Econ.isEnabled()) { double refund = Econ.calculateTotalLandRefund(myFaction.getLandCount()); @@ -39,12 +38,18 @@ public class CmdFactionsUnclaimall extends FCommand } } - FactionsEventLandUnclaimAll unclaimAllEvent = new FactionsEventLandUnclaimAll(sender, myFaction); - Bukkit.getServer().getPluginManager().callEvent(unclaimAllEvent); - // this event cannot be cancelled + // Event + FactionsEventLandUnclaimAll event = new FactionsEventLandUnclaimAll(sender, myFaction); + event.run(); + // TODO: this event cannot be cancelled yet. + // Apply BoardColl.get().removeAll(myFaction); + + // Inform myFaction.msg("%s unclaimed ALL of your faction's land.", fme.describeTo(myFaction, true)); + + // TODO: Move this to a listener instead. SpoutFeatures.updateTerritoryDisplayLoc(null); if (ConfServer.logLandUnclaims) diff --git a/src/com/massivecraft/factions/event/FactionsEventHomeTeleport.java b/src/com/massivecraft/factions/event/FactionsEventHomeTeleport.java new file mode 100644 index 00000000..2bbfa566 --- /dev/null +++ b/src/com/massivecraft/factions/event/FactionsEventHomeTeleport.java @@ -0,0 +1,25 @@ +package com.massivecraft.factions.event; + +import org.bukkit.command.CommandSender; +import org.bukkit.event.HandlerList; + +public class FactionsEventHomeTeleport 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 + // -------------------------------------------- // + + public FactionsEventHomeTeleport(CommandSender sender) + { + super(sender); + } + +} diff --git a/src/com/massivecraft/factions/listeners/FactionsListenerEcon.java b/src/com/massivecraft/factions/listeners/FactionsListenerEcon.java index 3c10b4c1..f778fe51 100644 --- a/src/com/massivecraft/factions/listeners/FactionsListenerEcon.java +++ b/src/com/massivecraft/factions/listeners/FactionsListenerEcon.java @@ -11,6 +11,7 @@ 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.FactionsEventHomeTeleport; import com.massivecraft.factions.event.FactionsEventInvitedChange; import com.massivecraft.factions.event.FactionsEventOpenChange; import com.massivecraft.factions.event.FactionsEventRelationChange; @@ -102,4 +103,11 @@ public class FactionsListenerEcon implements Listener double cost = event.isNewInvited() ? ConfServer.econCostInvite : ConfServer.econCostDeinvite; payForCommand(event, cost, Factions.get().getOuterCmdFactions().cmdFactionsInvite); } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void payForCommand(FactionsEventHomeTeleport event) + { + payForCommand(event, ConfServer.econCostHome, Factions.get().getOuterCmdFactions().cmdFactionsHome); + } + }