From d3488311de93476f0f8fc454b21abe9305a1c47d Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Fri, 19 Apr 2013 10:07:53 +0200 Subject: [PATCH] It makes no sense to charge for purely informational commands does it? If it does we can add them in later again. Also adding in a in progress listener to show how internal events should be used for integration with other plugins --- src/com/massivecraft/factions/ConfServer.java | 4 -- src/com/massivecraft/factions/Factions.java | 6 +++ .../factions/cmd/CmdFactionsList.java | 4 -- .../factions/cmd/CmdFactionsMap.java | 7 --- .../factions/cmd/CmdFactionsPower.java | 4 -- .../factions/cmd/CmdFactionsSethome.java | 4 +- .../factions/cmd/CmdFactionsShow.java | 3 -- ...vent.java => FactionsHomeChangeEvent.java} | 4 +- .../listeners/FactionsListenerEcon.java | 49 +++++++++++++++++++ 9 files changed, 59 insertions(+), 26 deletions(-) rename src/com/massivecraft/factions/event/{FactionsHomeChangedEvent.java => FactionsHomeChangeEvent.java} (88%) create mode 100644 src/com/massivecraft/factions/listeners/FactionsListenerEcon.java diff --git a/src/com/massivecraft/factions/ConfServer.java b/src/com/massivecraft/factions/ConfServer.java index c0b03087..95404a9c 100644 --- a/src/com/massivecraft/factions/ConfServer.java +++ b/src/com/massivecraft/factions/ConfServer.java @@ -287,10 +287,6 @@ public class ConfServer extends SimpleConfig public static double econCostTag = 0.0; public static double econCostDesc = 0.0; public static double econCostTitle = 0.0; - public static double econCostList = 0.0; - public static double econCostMap = 0.0; - public static double econCostPower = 0.0; - public static double econCostShow = 0.0; public static double econCostOpen = 0.0; public static double econCostAlly = 0.0; public static double econCostTruce = 0.0; diff --git a/src/com/massivecraft/factions/Factions.java b/src/com/massivecraft/factions/Factions.java index 12a88a22..f058c691 100644 --- a/src/com/massivecraft/factions/Factions.java +++ b/src/com/massivecraft/factions/Factions.java @@ -25,6 +25,7 @@ import com.massivecraft.factions.integration.SpoutFeatures; 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; @@ -84,6 +85,11 @@ public class Factions extends MPlugin FactionsListenerChat.get().setup(); FactionsListenerExploit.get().setup(); + // NOTE: This listener is a work in progress. + // The goal is that the Econ integration should be completely based on listening to our own events. + // Right now only a few situations are handled through this listener. + FactionsListenerEcon.get().setup(); + // TODO: Get rid of these this.playerListener = new TodoFactionsPlayerListener(); getServer().getPluginManager().registerEvents(this.playerListener, this); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsList.java b/src/com/massivecraft/factions/cmd/CmdFactionsList.java index f7778c10..ad984eac 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsList.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsList.java @@ -3,7 +3,6 @@ package com.massivecraft.factions.cmd; import java.util.ArrayList; import java.util.List; -import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.Faction; import com.massivecraft.factions.FactionColl; import com.massivecraft.factions.FactionListComparator; @@ -31,9 +30,6 @@ public class CmdFactionsList extends FCommand Integer pageHumanBased = this.arg(0, ARInteger.get(), 1); if (pageHumanBased == 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.econCostList)) return; - // Create Messages List lines = new ArrayList(); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsMap.java b/src/com/massivecraft/factions/cmd/CmdFactionsMap.java index 818081c1..67efd8d3 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsMap.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsMap.java @@ -1,7 +1,6 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.BoardColl; -import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.Perm; import com.massivecraft.mcore.cmd.arg.ARBoolean; import com.massivecraft.mcore.cmd.req.ReqHasPerm; @@ -26,9 +25,6 @@ public class CmdFactionsMap extends FCommand { if (!this.argIsSet(0)) { - // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay - if (!payForCommand(ConfServer.econCostMap)) return; - showMap(); return; } @@ -37,9 +33,6 @@ public class CmdFactionsMap extends FCommand { // Turn on - // if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay - if (!payForCommand(ConfServer.econCostMap)) return; - fme.setMapAutoUpdating(true); msg("Map auto update ENABLED."); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPower.java b/src/com/massivecraft/factions/cmd/CmdFactionsPower.java index 65031ab3..c4e42dc3 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPower.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsPower.java @@ -1,6 +1,5 @@ package com.massivecraft.factions.cmd; -import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.Perm; import com.massivecraft.factions.cmd.arg.ARFPlayer; @@ -26,9 +25,6 @@ public class CmdFactionsPower extends FCommand if (target != fme && ! Perm.POWER_ANY.has(sender, true)) 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.econCostPower)) return; - double powerBoost = target.getPowerBoost(); String boost = (powerBoost == 0.0) ? "" : (powerBoost > 0.0 ? " (bonus: " : " (penalty: ") + powerBoost + ")"; msg("%s - Power / Maxpower: %d / %d %s", target.describeTo(fme, true), target.getPowerRounded(), target.getPowerMaxRounded(), boost); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsSethome.java b/src/com/massivecraft/factions/cmd/CmdFactionsSethome.java index 596189ca..4a8d12b4 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.FactionsHomeChangedEvent; +import com.massivecraft.factions.event.FactionsHomeChangeEvent; import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqIsPlayer; import com.massivecraft.mcore.ps.PS; @@ -48,7 +48,7 @@ public class CmdFactionsSethome extends FCommand return; } - FactionsHomeChangedEvent event = new FactionsHomeChangedEvent(sender, FactionsHomeChangedEvent.REASON_COMMAND_SETHOME, faction, newHome); + FactionsHomeChangeEvent event = new FactionsHomeChangeEvent(sender, FactionsHomeChangeEvent.REASON_COMMAND_SETHOME, faction, newHome); event.run(); if (event.isCancelled()) return; newHome = event.getNewHome(); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsShow.java b/src/com/massivecraft/factions/cmd/CmdFactionsShow.java index 011f91e7..3db0ff54 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsShow.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsShow.java @@ -34,9 +34,6 @@ public class CmdFactionsShow extends FCommand Faction faction = this.arg(0, ARFaction.get(), myFaction); if (faction == 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.econCostShow)) return; - Collection admins = faction.getFPlayersWhereRole(Rel.LEADER); Collection mods = faction.getFPlayersWhereRole(Rel.OFFICER); Collection normals = faction.getFPlayersWhereRole(Rel.MEMBER); diff --git a/src/com/massivecraft/factions/event/FactionsHomeChangedEvent.java b/src/com/massivecraft/factions/event/FactionsHomeChangeEvent.java similarity index 88% rename from src/com/massivecraft/factions/event/FactionsHomeChangedEvent.java rename to src/com/massivecraft/factions/event/FactionsHomeChangeEvent.java index 10dca018..7cda7710 100644 --- a/src/com/massivecraft/factions/event/FactionsHomeChangedEvent.java +++ b/src/com/massivecraft/factions/event/FactionsHomeChangeEvent.java @@ -7,7 +7,7 @@ import com.massivecraft.factions.Faction; import com.massivecraft.mcore.event.MCoreCancellableEvent; import com.massivecraft.mcore.ps.PS; -public class FactionsHomeChangedEvent extends MCoreCancellableEvent +public class FactionsHomeChangeEvent extends MCoreCancellableEvent { // -------------------------------------------- // // CONSTANTS @@ -46,7 +46,7 @@ public class FactionsHomeChangedEvent extends MCoreCancellableEvent // CONSTRUCT // -------------------------------------------- // - public FactionsHomeChangedEvent(CommandSender sender, String reason, Faction faction, PS newHome) + public FactionsHomeChangeEvent(CommandSender sender, String reason, Faction faction, PS newHome) { this.sender = sender; this.reason = reason; diff --git a/src/com/massivecraft/factions/listeners/FactionsListenerEcon.java b/src/com/massivecraft/factions/listeners/FactionsListenerEcon.java new file mode 100644 index 00000000..e0470a67 --- /dev/null +++ b/src/com/massivecraft/factions/listeners/FactionsListenerEcon.java @@ -0,0 +1,49 @@ +package com.massivecraft.factions.listeners; + +import org.bukkit.Bukkit; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +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.integration.Econ; + +public class FactionsListenerEcon implements Listener +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static FactionsListenerEcon i = new FactionsListenerEcon(); + public static FactionsListenerEcon get() { return i; } + public FactionsListenerEcon() {} + + // -------------------------------------------- // + // SETUP + // -------------------------------------------- // + + public void setup() + { + Bukkit.getPluginManager().registerEvents(this, Factions.get()); + } + + // -------------------------------------------- // + // LISTENER + // -------------------------------------------- // + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void onFactionsHomeChangeEvent(FactionsHomeChangeEvent event) + { + // If the faction home is being changed through a command ... + if (!event.getReason().equals(FactionsHomeChangeEvent.REASON_COMMAND_SETHOME)) return; + + // ... and the sender can not afford the command ... + if (Econ.payForAction(ConfServer.econCostSethome, event.getSender(), Factions.get().getOuterCmdFactions().cmdFactionsSethome.getDesc())) return; + + // ... then cancel the change. + event.setCancelled(true); + } + +}