From e874ea60dfe59942af3eee11826ae5386a0d8d57 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Tue, 16 Apr 2013 11:05:49 +0200 Subject: [PATCH] Even more command fixes. --- .../factions/cmd/CmdFactionsCapeAbstract.java | 6 +- .../factions/cmd/CmdFactionsCapeSet.java | 3 +- .../factions/cmd/CmdFactionsClaim.java | 68 ++++++++++--------- .../factions/cmd/CmdFactionsCreate.java | 2 +- .../factions/cmd/CmdFactionsDeinvite.java | 4 +- .../factions/cmd/CmdFactionsDemote.java | 3 +- .../factions/cmd/CmdFactionsDisband.java | 4 +- .../factions/cmd/CmdFactionsFlag.java | 7 +- .../factions/cmd/CmdFactionsInvite.java | 5 +- .../factions/cmd/CmdFactionsJoin.java | 8 ++- .../factions/cmd/CmdFactionsKick.java | 3 +- .../factions/cmd/CmdFactionsLeader.java | 6 +- .../factions/cmd/CmdFactionsMoneyBalance.java | 9 +-- .../factions/cmd/CmdFactionsMoneyDeposit.java | 11 ++- .../cmd/CmdFactionsMoneyTransferFf.java | 12 +++- .../cmd/CmdFactionsMoneyTransferFp.java | 14 +++- .../cmd/CmdFactionsMoneyTransferPf.java | 14 +++- .../cmd/CmdFactionsMoneyWithdraw.java | 10 ++- .../factions/cmd/CmdFactionsOfficer.java | 3 +- .../factions/cmd/CmdFactionsOpen.java | 14 ++-- .../factions/cmd/CmdFactionsPerm.java | 9 +-- .../factions/cmd/CmdFactionsPower.java | 3 +- .../factions/cmd/CmdFactionsPowerBoost.java | 2 +- .../factions/cmd/CmdFactionsPromote.java | 3 +- .../cmd/CmdFactionsRelationAbstract.java | 3 +- .../factions/cmd/CmdFactionsSethome.java | 3 +- .../factions/cmd/CmdFactionsShow.java | 9 +-- .../factions/cmd/CmdFactionsTag.java | 2 +- .../factions/cmd/CmdFactionsTitle.java | 8 ++- .../massivecraft/factions/cmd/FCommand.java | 66 ++++++++++++++++++ .../factions/cmd/FCommandOld.java | 60 ---------------- 31 files changed, 216 insertions(+), 158 deletions(-) diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsCapeAbstract.java b/src/com/massivecraft/factions/cmd/CmdFactionsCapeAbstract.java index 6d62cb68..1c0a5ba7 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsCapeAbstract.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsCapeAbstract.java @@ -6,6 +6,7 @@ import org.bukkit.command.CommandSender; import com.massivecraft.factions.FPerm; import com.massivecraft.factions.Faction; +import com.massivecraft.factions.cmd.arg.ARFaction; public abstract class CmdFactionsCapeAbstract extends FCommand { @@ -20,9 +21,6 @@ public abstract class CmdFactionsCapeAbstract extends FCommand @Override public boolean validCall(CommandSender sender, List args) { - if ( ! super.validCall(sender, args)) return false; - - this.capeFaction = null; this.currentCape = null; @@ -32,7 +30,7 @@ public abstract class CmdFactionsCapeAbstract extends FCommand return false; } - this.capeFaction = this.argAsFaction(this.requiredArgs.size(), this.myFaction); + this.capeFaction = this.arg(this.requiredArgs.size(), ARFaction.get(), this.myFaction); if (this.capeFaction == null) return false; // Do we have permission to manage the cape of that faction? diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsCapeSet.java b/src/com/massivecraft/factions/cmd/CmdFactionsCapeSet.java index 73b5c1b3..646a7e9f 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsCapeSet.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsCapeSet.java @@ -15,6 +15,7 @@ public class CmdFactionsCapeSet extends CmdFactionsCapeAbstract this.addAliases("set"); this.addRequiredArg("url"); + this.setErrorOnToManyArgs(false); this.addRequirements(ReqHasPerm.get(Perm.CAPE_SET.node)); } @@ -22,7 +23,7 @@ public class CmdFactionsCapeSet extends CmdFactionsCapeAbstract @Override public void perform() { - String newCape = this.argAsString(0); + String newCape = this.argConcatFrom(0); if (isUrlValid(newCape)) { diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsClaim.java b/src/com/massivecraft/factions/cmd/CmdFactionsClaim.java index 9999eed2..eff2279e 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsClaim.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsClaim.java @@ -3,7 +3,9 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.Faction; import com.massivecraft.factions.Perm; +import com.massivecraft.factions.cmd.arg.ARFaction; import com.massivecraft.factions.util.SpiralTask; +import com.massivecraft.mcore.cmd.arg.ARInteger; import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqIsPlayer; import com.massivecraft.mcore.ps.PS; @@ -26,9 +28,12 @@ public class CmdFactionsClaim extends FCommand @Override public void perform() { - // Read and validate input - final Faction forFaction = this.argAsFaction(0, myFaction); - int radius = this.argAsInt(1, 1); + Faction forFaction = this.arg(0, ARFaction.get()); + if (forFaction == null) return; + + Integer radius = this.arg(1, ARInteger.get(), 1); + if (radius == null) return; + if (radius < 1) { @@ -40,36 +45,37 @@ public class CmdFactionsClaim extends FCommand { // single chunk fme.attemptClaim(forFaction, me.getLocation(), true); + return; } - else + + // radius claim + if (! Perm.CLAIM_RADIUS.has(sender, false)) { - // radius claim - if (! Perm.CLAIM_RADIUS.has(sender, false)) - { - msg("You do not have permission to claim in a radius."); - return; - } - - new SpiralTask(PS.valueOf(me), radius) - { - private int failCount = 0; - private final int limit = ConfServer.radiusClaimFailureLimit - 1; - - @Override - public boolean work() - { - boolean success = fme.attemptClaim(forFaction, this.currentLocation(), true); - if (success) - failCount = 0; - else if ( ! success && failCount++ >= limit) - { - this.stop(); - return false; - } - - return true; - } - }; + msg("You do not have permission to claim in a radius."); + return; } + + // TODO: I do not beleive in the spiral-task. Get rid of this. The failcount can be precalculated. + new SpiralTask(PS.valueOf(me), radius) + { + private int failCount = 0; + private final int limit = ConfServer.radiusClaimFailureLimit - 1; + + @Override + public boolean work() + { + boolean success = fme.attemptClaim(forFaction, this.currentLocation(), true); + if (success) + failCount = 0; + else if ( ! success && failCount++ >= limit) + { + this.stop(); + return false; + } + + return true; + } + }; + } } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsCreate.java b/src/com/massivecraft/factions/cmd/CmdFactionsCreate.java index ac3e9e3b..73e3a8d6 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsCreate.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsCreate.java @@ -31,7 +31,7 @@ public class CmdFactionsCreate extends FCommand @Override public void perform() { - String tag = this.argAsString(0); + String tag = this.arg(0); if (fme.hasFaction()) { diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsDeinvite.java b/src/com/massivecraft/factions/cmd/CmdFactionsDeinvite.java index 0743908a..13a6039c 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsDeinvite.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsDeinvite.java @@ -2,6 +2,7 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.Perm; +import com.massivecraft.factions.cmd.arg.ARFPlayer; import com.massivecraft.mcore.cmd.req.ReqHasPerm; public class CmdFactionsDeinvite extends FCommand @@ -15,6 +16,7 @@ public class CmdFactionsDeinvite extends FCommand this.addRequirements(ReqHasPerm.get(Perm.DEINVITE.node)); + // TODO: Base on faction permissions instead? senderMustBeMember = false; senderMustBeOfficer = true; senderMustBeLeader = false; @@ -23,7 +25,7 @@ public class CmdFactionsDeinvite extends FCommand @Override public void perform() { - FPlayer you = this.argAsBestFPlayerMatch(0); + FPlayer you = this.arg(0, ARFPlayer.getStartAny()); if (you == null) return; if (you.getFaction() == myFaction) diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsDemote.java b/src/com/massivecraft/factions/cmd/CmdFactionsDemote.java index 353af78f..899bbb81 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsDemote.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsDemote.java @@ -3,6 +3,7 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.Perm; import com.massivecraft.factions.Rel; +import com.massivecraft.factions.cmd.arg.ARFPlayer; import com.massivecraft.mcore.cmd.req.ReqHasPerm; public class CmdFactionsDemote extends FCommand @@ -24,7 +25,7 @@ public class CmdFactionsDemote extends FCommand @Override public void perform() { - FPlayer you = this.argAsBestFPlayerMatch(0); + FPlayer you = this.arg(0, ARFPlayer.getStartAny()); if (you == null) return; if (you.getFaction() != myFaction) diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsDisband.java b/src/com/massivecraft/factions/cmd/CmdFactionsDisband.java index 5ff0d642..8808f0d0 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsDisband.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsDisband.java @@ -3,6 +3,7 @@ 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.FPlayerLeaveEvent; import com.massivecraft.factions.event.FactionDisbandEvent; import com.massivecraft.factions.integration.Econ; @@ -30,8 +31,7 @@ public class CmdFactionsDisband extends FCommand @Override public void perform() { - // The faction, default to your own.. but null if console sender. - Faction faction = this.argAsFaction(0, fme == null ? null : myFaction); + Faction faction = this.arg(0, ARFaction.get(), myFaction); if (faction == null) return; if ( ! FPerm.DISBAND.has(sender, faction, true)) return; diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsFlag.java b/src/com/massivecraft/factions/cmd/CmdFactionsFlag.java index 9c342e46..9464a4c3 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsFlag.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsFlag.java @@ -3,6 +3,7 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.FFlag; import com.massivecraft.factions.Faction; import com.massivecraft.factions.Perm; +import com.massivecraft.factions.cmd.arg.ARFaction; import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.util.Txt; @@ -23,11 +24,7 @@ public class CmdFactionsFlag extends FCommand @Override public void perform() { - Faction faction = myFaction; - if (this.argIsSet(0)) - { - faction = this.argAsFaction(0); - } + Faction faction = this.arg(0, ARFaction.get(), myFaction); if (faction == null) return; if ( ! this.argIsSet(1)) diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsInvite.java b/src/com/massivecraft/factions/cmd/CmdFactionsInvite.java index 8012e592..59a4bd64 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsInvite.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsInvite.java @@ -3,7 +3,10 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.FPerm; import com.massivecraft.factions.FPlayer; +import com.massivecraft.factions.Faction; import com.massivecraft.factions.Perm; +import com.massivecraft.factions.cmd.arg.ARFPlayer; +import com.massivecraft.factions.cmd.arg.ARFaction; import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqIsPlayer; @@ -24,7 +27,7 @@ public class CmdFactionsInvite extends FCommand @Override public void perform() { - FPlayer you = this.argAsBestFPlayerMatch(0); + FPlayer you = this.arg(0, ARFPlayer.getStartAny()); if (you == null) return; if (you.getFaction() == myFaction) diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsJoin.java b/src/com/massivecraft/factions/cmd/CmdFactionsJoin.java index 302cc595..decbe244 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsJoin.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsJoin.java @@ -8,6 +8,8 @@ import com.massivecraft.factions.FPlayerColl; import com.massivecraft.factions.Faction; 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.mcore.cmd.req.ReqHasPerm; @@ -26,10 +28,12 @@ public class CmdFactionsJoin extends FCommand @Override public void perform() { - Faction faction = this.argAsFaction(0); + Faction faction = this.arg(0, ARFaction.get()); if (faction == null) return; - FPlayer fplayer = this.argAsBestFPlayerMatch(1, fme, false); + FPlayer fplayer = this.arg(1, ARFPlayer.getStartAny(), fme); + if (fplayer == null) return; + boolean samePlayer = fplayer == fme; if (!samePlayer && ! Perm.JOIN_OTHERS.has(sender, false)) diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsKick.java b/src/com/massivecraft/factions/cmd/CmdFactionsKick.java index 003545aa..6f7d3f7b 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsKick.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsKick.java @@ -9,6 +9,7 @@ import com.massivecraft.factions.Faction; 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.mcore.cmd.req.ReqHasPerm; @@ -27,7 +28,7 @@ public class CmdFactionsKick extends FCommand @Override public void perform() { - FPlayer you = this.argAsBestFPlayerMatch(0); + FPlayer you = this.arg(1, ARFPlayer.getStartAny()); if (you == null) return; if (fme == you) diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsLeader.java b/src/com/massivecraft/factions/cmd/CmdFactionsLeader.java index f7139b28..ab1f6f4a 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsLeader.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsLeader.java @@ -7,6 +7,8 @@ import com.massivecraft.factions.FPlayerColl; import com.massivecraft.factions.Faction; 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.util.RelationUtil; import com.massivecraft.mcore.cmd.req.ReqHasPerm; @@ -27,10 +29,10 @@ public class CmdFactionsLeader extends FCommand @Override public void perform() { - FPlayer newLeader = this.argAsBestFPlayerMatch(0); + FPlayer newLeader = this.arg(0, ARFPlayer.getStartAny()); if (newLeader == null) return; - Faction targetFaction = this.argAsFaction(1, myFaction); + Faction targetFaction = this.arg(1, ARFaction.get(), myFaction); if (targetFaction == null) return; FPlayer targetFactionCurrentLeader = targetFaction.getFPlayerLeader(); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsMoneyBalance.java b/src/com/massivecraft/factions/cmd/CmdFactionsMoneyBalance.java index bccbc264..b155d839 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsMoneyBalance.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsMoneyBalance.java @@ -1,5 +1,6 @@ package com.massivecraft.factions.cmd; +import com.massivecraft.factions.cmd.arg.ARFaction; import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.Faction; import com.massivecraft.factions.Perm; @@ -21,13 +22,9 @@ public class CmdFactionsMoneyBalance extends FCommand @Override public void perform() { - Faction faction = myFaction; - if (this.argIsSet(0)) - { - faction = this.argAsFaction(0); - } - + Faction faction = this.arg(0, ARFaction.get(), myFaction); if (faction == null) return; + if (faction != myFaction && ! Perm.MONEY_BALANCE_ANY.has(sender, true)) return; Econ.sendBalanceInfo(fme, faction); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsMoneyDeposit.java b/src/com/massivecraft/factions/cmd/CmdFactionsMoneyDeposit.java index 6a16349a..a7f56e1b 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsMoneyDeposit.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsMoneyDeposit.java @@ -1,10 +1,13 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.ConfServer; +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.iface.EconomyParticipator; import com.massivecraft.factions.integration.Econ; +import com.massivecraft.mcore.cmd.arg.ARDouble; import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.util.Txt; @@ -29,9 +32,13 @@ public class CmdFactionsMoneyDeposit extends FCommand @Override public void perform() { - double amount = this.argAsDouble(0, 0d); - EconomyParticipator faction = this.argAsFaction(1, myFaction); + Double amount = this.arg(0, ARDouble.get()); + if (amount == null) return; + + Faction faction = this.arg(1, ARFaction.get(), myFaction); if (faction == null) return; + + boolean success = Econ.transferMoney(fme, fme, faction, amount); if (success && ConfServer.logMoneyTransactions) diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsMoneyTransferFf.java b/src/com/massivecraft/factions/cmd/CmdFactionsMoneyTransferFf.java index 6fa59f95..186eba75 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsMoneyTransferFf.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsMoneyTransferFf.java @@ -1,10 +1,13 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.ConfServer; +import com.massivecraft.factions.Faction; import com.massivecraft.factions.Perm; +import com.massivecraft.factions.cmd.arg.ARFaction; import com.massivecraft.factions.iface.EconomyParticipator; import com.massivecraft.factions.Factions; import com.massivecraft.factions.integration.Econ; +import com.massivecraft.mcore.cmd.arg.ARDouble; import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.util.Txt; @@ -29,10 +32,13 @@ public class CmdFactionsMoneyTransferFf extends FCommand @Override public void perform() { - double amount = this.argAsDouble(0, 0d); - EconomyParticipator from = this.argAsFaction(1); + Double amount = this.arg(0, ARDouble.get()); + if (amount == null) return; + + Faction from = this.arg(1, ARFaction.get()); if (from == null) return; - EconomyParticipator to = this.argAsFaction(2); + + Faction to = this.arg(2, ARFaction.get()); if (to == null) return; boolean success = Econ.transferMoney(fme, from, to, amount); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsMoneyTransferFp.java b/src/com/massivecraft/factions/cmd/CmdFactionsMoneyTransferFp.java index 5bc389aa..b3be667a 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsMoneyTransferFp.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsMoneyTransferFp.java @@ -1,10 +1,15 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.ConfServer; +import com.massivecraft.factions.FPlayer; +import com.massivecraft.factions.Faction; import com.massivecraft.factions.Perm; +import com.massivecraft.factions.cmd.arg.ARFPlayer; +import com.massivecraft.factions.cmd.arg.ARFaction; import com.massivecraft.factions.iface.EconomyParticipator; import com.massivecraft.factions.Factions; import com.massivecraft.factions.integration.Econ; +import com.massivecraft.mcore.cmd.arg.ARDouble; import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.util.Txt; @@ -29,10 +34,13 @@ public class CmdFactionsMoneyTransferFp extends FCommand @Override public void perform() { - double amount = this.argAsDouble(0, 0d); - EconomyParticipator from = this.argAsFaction(1); + Double amount = this.arg(0, ARDouble.get()); + if (amount == null) return; + + Faction from = this.arg(1, ARFaction.get()); if (from == null) return; - EconomyParticipator to = this.argAsBestFPlayerMatch(2); + + FPlayer to = this.arg(2, ARFPlayer.getStartAny()); if (to == null) return; boolean success = Econ.transferMoney(fme, from, to, amount); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsMoneyTransferPf.java b/src/com/massivecraft/factions/cmd/CmdFactionsMoneyTransferPf.java index fae7f1f5..e77ebe9b 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsMoneyTransferPf.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsMoneyTransferPf.java @@ -1,10 +1,15 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.ConfServer; +import com.massivecraft.factions.FPlayer; +import com.massivecraft.factions.Faction; import com.massivecraft.factions.Perm; +import com.massivecraft.factions.cmd.arg.ARFPlayer; +import com.massivecraft.factions.cmd.arg.ARFaction; import com.massivecraft.factions.iface.EconomyParticipator; import com.massivecraft.factions.Factions; import com.massivecraft.factions.integration.Econ; +import com.massivecraft.mcore.cmd.arg.ARDouble; import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.util.Txt; @@ -29,10 +34,13 @@ public class CmdFactionsMoneyTransferPf extends FCommand @Override public void perform() { - double amount = this.argAsDouble(0, 0d); - EconomyParticipator from = this.argAsBestFPlayerMatch(1); + Double amount = this.arg(0, ARDouble.get()); + if (amount == null) return; + + FPlayer from = this.arg(1, ARFPlayer.getStartAny()); if (from == null) return; - EconomyParticipator to = this.argAsFaction(2); + + Faction to = this.arg(2, ARFaction.get()); if (to == null) return; boolean success = Econ.transferMoney(fme, from, to, amount); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsMoneyWithdraw.java b/src/com/massivecraft/factions/cmd/CmdFactionsMoneyWithdraw.java index 1b614e47..a665564c 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsMoneyWithdraw.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsMoneyWithdraw.java @@ -1,10 +1,13 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.ConfServer; +import com.massivecraft.factions.Faction; import com.massivecraft.factions.Perm; +import com.massivecraft.factions.cmd.arg.ARFaction; import com.massivecraft.factions.iface.EconomyParticipator; import com.massivecraft.factions.Factions; import com.massivecraft.factions.integration.Econ; +import com.massivecraft.mcore.cmd.arg.ARDouble; import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.util.Txt; @@ -28,9 +31,12 @@ public class CmdFactionsMoneyWithdraw extends FCommand @Override public void perform() { - double amount = this.argAsDouble(0, 0d); - EconomyParticipator faction = this.argAsFaction(1, myFaction); + Double amount = this.arg(0, ARDouble.get()); + if (amount == null) return; + + Faction faction = this.arg(1, ARFaction.get(), myFaction); if (faction == null) return; + boolean success = Econ.transferMoney(fme, faction, fme, amount); if (success && ConfServer.logMoneyTransactions) diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsOfficer.java b/src/com/massivecraft/factions/cmd/CmdFactionsOfficer.java index 8d505c2e..9d75fb3e 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsOfficer.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsOfficer.java @@ -4,6 +4,7 @@ import com.massivecraft.factions.Faction; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.Perm; import com.massivecraft.factions.Rel; +import com.massivecraft.factions.cmd.arg.ARFPlayer; import com.massivecraft.mcore.cmd.req.ReqHasPerm; public class CmdFactionsOfficer extends FCommand @@ -21,7 +22,7 @@ public class CmdFactionsOfficer extends FCommand @Override public void perform() { - FPlayer you = this.argAsBestFPlayerMatch(0); + FPlayer you = this.arg(0, ARFPlayer.getStartAny()); if (you == null) return; boolean permAny = Perm.OFFICER_ANY.has(sender, false); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsOpen.java b/src/com/massivecraft/factions/cmd/CmdFactionsOpen.java index 3faf8bc7..bb979ec2 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsOpen.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsOpen.java @@ -4,6 +4,7 @@ import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.Faction; import com.massivecraft.factions.FactionColl; import com.massivecraft.factions.Perm; +import com.massivecraft.mcore.cmd.arg.ARBoolean; import com.massivecraft.mcore.cmd.req.ReqHasPerm; public class CmdFactionsOpen extends FCommand @@ -22,22 +23,25 @@ public class CmdFactionsOpen extends FCommand @Override public void perform() { + Boolean target = this.arg(0, ARBoolean.get(), !myFaction.isOpen()); + if (target == 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, "to open or close the faction", "for opening or closing the faction")) return; - - myFaction.setOpen(this.argAsBool(0, ! myFaction.isOpen())); - String open = myFaction.isOpen() ? "open" : "closed"; + myFaction.setOpen(target); + + String descTarget = myFaction.isOpen() ? "open" : "closed"; // Inform - myFaction.msg("%s changed the faction to %s.", fme.describeTo(myFaction, true), open); + myFaction.msg("%s changed the faction to %s.", fme.describeTo(myFaction, true), descTarget); for (Faction faction : FactionColl.get().getAll()) { if (faction == myFaction) { continue; } - faction.msg("The faction %s is now %s", myFaction.getTag(faction), open); + faction.msg("The faction %s is now %s", myFaction.getTag(faction), descTarget); } } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPerm.java b/src/com/massivecraft/factions/cmd/CmdFactionsPerm.java index 8dc3110d..80737562 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPerm.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsPerm.java @@ -4,6 +4,7 @@ import com.massivecraft.factions.FPerm; import com.massivecraft.factions.Faction; import com.massivecraft.factions.Perm; import com.massivecraft.factions.Rel; +import com.massivecraft.factions.cmd.arg.ARFaction; import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.util.Txt; @@ -13,7 +14,7 @@ public class CmdFactionsPerm extends FCommand { this.addAliases("perm"); - this.addOptionalArg("faction", "your"); + this.addOptionalArg("faction", "you"); this.addOptionalArg("perm", "all"); this.addOptionalArg("relation", "read"); this.addOptionalArg("yes/no", "read"); @@ -25,11 +26,7 @@ public class CmdFactionsPerm extends FCommand @Override public void perform() { - Faction faction = myFaction; - if (this.argIsSet(0)) - { - faction = this.argAsFaction(0); - } + Faction faction = this.arg(0, ARFaction.get(), myFaction); if (faction == null) return; if ( ! this.argIsSet(1)) diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPower.java b/src/com/massivecraft/factions/cmd/CmdFactionsPower.java index 1faa6e5f..3c4df96f 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPower.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsPower.java @@ -3,6 +3,7 @@ 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; import com.massivecraft.mcore.cmd.req.ReqHasPerm; public class CmdFactionsPower extends FCommand @@ -20,7 +21,7 @@ public class CmdFactionsPower extends FCommand @Override public void perform() { - FPlayer target = this.argAsBestFPlayerMatch(0, fme); + FPlayer target = this.arg(0, ARFPlayer.getStartAny(), fme); if (target == null) return; if (target != fme && ! Perm.POWER_ANY.has(sender, true)) return; diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPowerBoost.java b/src/com/massivecraft/factions/cmd/CmdFactionsPowerBoost.java index d9c234b9..23203565 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPowerBoost.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsPowerBoost.java @@ -22,7 +22,7 @@ public class CmdFactionsPowerBoost extends FCommand @Override public void perform() { - String type = this.argAsString(0).toLowerCase(); + String type = this.arg(0).toLowerCase(); boolean doPlayer = true; if (type.equals("f") || type.equals("faction")) { diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPromote.java b/src/com/massivecraft/factions/cmd/CmdFactionsPromote.java index 2b7ee866..8a8dc12d 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPromote.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsPromote.java @@ -3,6 +3,7 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.Perm; import com.massivecraft.factions.Rel; +import com.massivecraft.factions.cmd.arg.ARFPlayer; import com.massivecraft.mcore.cmd.req.ReqHasPerm; public class CmdFactionsPromote extends FCommand @@ -24,7 +25,7 @@ public class CmdFactionsPromote extends FCommand @Override public void perform() { - FPlayer you = this.argAsBestFPlayerMatch(0); + FPlayer you = this.arg(0, ARFPlayer.getStartAny()); if (you == null) return; if (you.getFaction() != myFaction) diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsRelationAbstract.java b/src/com/massivecraft/factions/cmd/CmdFactionsRelationAbstract.java index 36c24915..ebe6009d 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsRelationAbstract.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsRelationAbstract.java @@ -7,6 +7,7 @@ import com.massivecraft.factions.FFlag; import com.massivecraft.factions.Faction; import com.massivecraft.factions.Perm; import com.massivecraft.factions.Rel; +import com.massivecraft.factions.cmd.arg.ARFaction; import com.massivecraft.factions.event.FactionRelationEvent; import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.mcore.cmd.req.ReqHasPerm; @@ -28,7 +29,7 @@ public abstract class CmdFactionsRelationAbstract extends FCommand @Override public void perform() { - Faction them = this.argAsFaction(0); + Faction them = this.arg(0, ARFaction.get()); if (them == null) return; /*if ( ! them.isNormal()) diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsSethome.java b/src/com/massivecraft/factions/cmd/CmdFactionsSethome.java index f9d6f97b..d8b7b140 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsSethome.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsSethome.java @@ -5,6 +5,7 @@ import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.FPerm; import com.massivecraft.factions.Faction; import com.massivecraft.factions.Perm; +import com.massivecraft.factions.cmd.arg.ARFaction; import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.cmd.req.ReqIsPlayer; import com.massivecraft.mcore.ps.PS; @@ -30,7 +31,7 @@ public class CmdFactionsSethome extends FCommand return; } - Faction faction = this.argAsFaction(0, myFaction); + Faction faction = this.arg(0, ARFaction.get(), myFaction); if (faction == null) return; // Can the player set the home for this faction? diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsShow.java b/src/com/massivecraft/factions/cmd/CmdFactionsShow.java index 414184a1..5c025894 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsShow.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsShow.java @@ -6,6 +6,7 @@ import java.util.List; import java.util.Map; import com.massivecraft.factions.ConfServer; +import com.massivecraft.factions.cmd.arg.ARFaction; import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.FFlag; import com.massivecraft.factions.FPlayer; @@ -30,12 +31,8 @@ public class CmdFactionsShow extends FCommand @Override public void perform() { - Faction faction = myFaction; - if (this.argIsSet(0)) - { - faction = this.argAsFaction(0); - if (faction == null) return; - } + 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, "to show faction information", "for showing faction information")) return; diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsTag.java b/src/com/massivecraft/factions/cmd/CmdFactionsTag.java index 2271a304..014393c0 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsTag.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsTag.java @@ -30,7 +30,7 @@ public class CmdFactionsTag extends FCommand @Override public void perform() { - String tag = this.argAsString(0); + String tag = this.arg(0); // TODO does not first test cover selfcase? if (FactionColl.get().isTagTaken(tag) && ! MiscUtil.getComparisonString(tag).equals(myFaction.getComparisonTag())) diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsTitle.java b/src/com/massivecraft/factions/cmd/CmdFactionsTitle.java index fde60ad7..e8063ee2 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsTitle.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsTitle.java @@ -3,7 +3,9 @@ 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; import com.massivecraft.factions.integration.SpoutFeatures; +import com.massivecraft.mcore.cmd.arg.ARString; import com.massivecraft.mcore.cmd.req.ReqHasPerm; import com.massivecraft.mcore.util.Txt; @@ -24,11 +26,11 @@ public class CmdFactionsTitle extends FCommand @Override public void perform() { - FPlayer you = this.argAsBestFPlayerMatch(0); + FPlayer you = this.arg(0, ARFPlayer.getStartAny()); if (you == null) return; - args.remove(0); - String title = Txt.implode(args, " "); + String title = this.argConcatFrom(1, ARString.get(), ""); + if (title == null) return; if ( ! canIAdministerYou(fme, you)) return; diff --git a/src/com/massivecraft/factions/cmd/FCommand.java b/src/com/massivecraft/factions/cmd/FCommand.java index 1615a812..15b39eff 100644 --- a/src/com/massivecraft/factions/cmd/FCommand.java +++ b/src/com/massivecraft/factions/cmd/FCommand.java @@ -1,9 +1,13 @@ package com.massivecraft.factions.cmd; +import com.massivecraft.factions.ConfServer; 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; public abstract class FCommand extends MCommand { @@ -16,4 +20,66 @@ public abstract class FCommand extends MCommand this.fme = FPlayerColl.get().get(this.sender); this.myFaction = this.fme.getFaction(); } + + // -------------------------------------------- // + // COMMONLY USED LOGIC + // -------------------------------------------- // + + public boolean canIAdministerYou(FPlayer i, FPlayer you) + { + if ( ! i.getFaction().equals(you.getFaction())) + { + i.sendMessage(Txt.parse("%s is not in the same faction as you.",you.describeTo(i, true))); + return false; + } + + if (i.getRole().isMoreThan(you.getRole()) || i.getRole().equals(Rel.LEADER) ) + { + return true; + } + + if (you.getRole().equals(Rel.LEADER)) + { + i.sendMessage(Txt.parse("Only the faction admin can do that.")); + } + else if (i.getRole().equals(Rel.OFFICER)) + { + if ( i == you ) + { + return true; //Moderators can control themselves + } + else + { + i.sendMessage(Txt.parse("Moderators can't control each other...")); + } + } + else + { + i.sendMessage(Txt.parse("You must be a faction moderator to do that.")); + } + + return false; + } + + // 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, String toDoThis, String forDoingThis) + { + if ( ! Econ.shouldBeUsed() || this.fme == null || cost == 0.0 || fme.hasAdminMode()) return true; + + if(ConfServer.bankEnabled && ConfServer.bankFactionPaysCosts && fme.hasFaction()) + return Econ.modifyMoney(myFaction, -cost, toDoThis, forDoingThis); + else + return Econ.modifyMoney(fme, -cost, toDoThis, forDoingThis); + } + + // like above, but just make sure they can pay; returns true unless person can't afford the cost + public boolean canAffordCommand(double cost, String toDoThis) + { + if ( ! Econ.shouldBeUsed() || this.fme == null || cost == 0.0 || fme.hasAdminMode()) return true; + + if(ConfServer.bankEnabled && ConfServer.bankFactionPaysCosts && fme.hasFaction()) + return Econ.hasAtLeast(myFaction, cost, toDoThis); + else + return Econ.hasAtLeast(fme, cost, toDoThis); + } } diff --git a/src/com/massivecraft/factions/cmd/FCommandOld.java b/src/com/massivecraft/factions/cmd/FCommandOld.java index d8c12fec..7b104c3f 100644 --- a/src/com/massivecraft/factions/cmd/FCommandOld.java +++ b/src/com/massivecraft/factions/cmd/FCommandOld.java @@ -379,65 +379,5 @@ public abstract class FCommandOld extends MCommand return this.argAsRel(idx, null); } - // -------------------------------------------- // - // Commonly used logic - // -------------------------------------------- // - public boolean canIAdministerYou(FPlayer i, FPlayer you) - { - if ( ! i.getFaction().equals(you.getFaction())) - { - i.sendMessage(Txt.parse("%s is not in the same faction as you.",you.describeTo(i, true))); - return false; - } - - if (i.getRole().isMoreThan(you.getRole()) || i.getRole().equals(Rel.LEADER) ) - { - return true; - } - - if (you.getRole().equals(Rel.LEADER)) - { - i.sendMessage(Txt.parse("Only the faction admin can do that.")); - } - else if (i.getRole().equals(Rel.OFFICER)) - { - if ( i == you ) - { - return true; //Moderators can control themselves - } - else - { - i.sendMessage(Txt.parse("Moderators can't control each other...")); - } - } - else - { - i.sendMessage(Txt.parse("You must be a faction moderator to do that.")); - } - - return false; - } - - // 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, String toDoThis, String forDoingThis) - { - if ( ! Econ.shouldBeUsed() || this.fme == null || cost == 0.0 || fme.hasAdminMode()) return true; - - if(ConfServer.bankEnabled && ConfServer.bankFactionPaysCosts && fme.hasFaction()) - return Econ.modifyMoney(myFaction, -cost, toDoThis, forDoingThis); - else - return Econ.modifyMoney(fme, -cost, toDoThis, forDoingThis); - } - - // like above, but just make sure they can pay; returns true unless person can't afford the cost - public boolean canAffordCommand(double cost, String toDoThis) - { - if ( ! Econ.shouldBeUsed() || this.fme == null || cost == 0.0 || fme.hasAdminMode()) return true; - - if(ConfServer.bankEnabled && ConfServer.bankFactionPaysCosts && fme.hasFaction()) - return Econ.hasAtLeast(myFaction, cost, toDoThis); - else - return Econ.hasAtLeast(fme, cost, toDoThis); - } }