Ability to pay for commands (through economy) is now checked before firing events which can be canceled, and actual payment made after making sure the event isn't canceled.

Added Econ.hasAtLeast(EconomyParticipator ep, double delta, String toDoThis) method to check if an account has at least a specified amount of money in it. Also added related FCommand.canAffordCommand(double cost, String toDoThis).
This commit is contained in:
Brettflan
2012-03-13 09:48:34 -05:00
parent fd8ca30af6
commit 7b9674dc4b
8 changed files with 80 additions and 94 deletions

View File

@@ -58,12 +58,15 @@ public class CmdCreate extends FCommand
return;
}
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make sure they can pay
if ( ! canAffordCommand(Conf.econCostCreate, "to create a new faction")) return;
// trigger the faction creation event (cancellable)
FactionCreateEvent createEvent = new FactionCreateEvent(me, tag);
Bukkit.getServer().getPluginManager().callEvent(createEvent);
if(createEvent.isCancelled()) return;
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make 'em pay
// then make 'em pay (if applicable)
if ( ! payForCommand(Conf.econCostCreate, "to create a new faction", "for creating a new faction")) return;
Faction faction = Factions.i.create();