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

This commit is contained in:
Olof Larsson 2013-04-19 10:07:53 +02:00
parent 2f8f0713e8
commit d3488311de
9 changed files with 59 additions and 26 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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<String> lines = new ArrayList<String>();

View File

@ -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("<i>Map auto update <green>ENABLED.");

View File

@ -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<a> - Power / Maxpower: <i>%d / %d %s", target.describeTo(fme, true), target.getPowerRounded(), target.getPowerMaxRounded(), boost);

View File

@ -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();

View File

@ -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<FPlayer> admins = faction.getFPlayersWhereRole(Rel.LEADER);
Collection<FPlayer> mods = faction.getFPlayersWhereRole(Rel.OFFICER);
Collection<FPlayer> normals = faction.getFPlayersWhereRole(Rel.MEMBER);

View File

@ -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;

View File

@ -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);
}
}