From 3d9847e4a6a2b63db64715ffe0e1f645f223e37e Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Tue, 16 Apr 2013 09:48:57 +0200 Subject: [PATCH] Starting to convert the faction commands. --- .../factions/cmd/CmdFactionsAccess.java | 6 +- .../factions/cmd/CmdFactionsAdmin.java | 5 - .../factions/cmd/CmdFactionsAutoClaim.java | 6 +- .../factions/cmd/CmdFactionsAutoHelp.java | 49 -- .../factions/cmd/CmdFactionsCape.java | 5 - .../factions/cmd/CmdFactionsCapeAbstract.java | 5 - .../factions/cmd/CmdFactionsClaim.java | 6 +- .../factions/cmd/CmdFactionsCreate.java | 10 +- .../factions/cmd/CmdFactionsDeinvite.java | 1 - .../factions/cmd/CmdFactionsDemote.java | 4 - .../factions/cmd/CmdFactionsDescription.java | 3 - .../factions/cmd/CmdFactionsDisband.java | 5 - .../factions/cmd/CmdFactionsFlag.java | 5 - .../factions/cmd/CmdFactionsHome.java | 6 +- .../factions/cmd/CmdFactionsInvite.java | 7 +- .../factions/cmd/CmdFactionsJoin.java | 5 - .../factions/cmd/CmdFactionsKick.java | 5 - .../factions/cmd/CmdFactionsLeader.java | 5 - .../factions/cmd/CmdFactionsLeave.java | 3 - .../factions/cmd/CmdFactionsList.java | 5 - .../factions/cmd/CmdFactionsMap.java | 6 +- .../factions/cmd/CmdFactionsOfficer.java | 5 - .../factions/cmd/CmdFactionsOpen.java | 3 - .../factions/cmd/CmdFactionsPerm.java | 5 - .../factions/cmd/CmdFactionsPower.java | 5 - .../factions/cmd/CmdFactionsPowerBoost.java | 5 - .../factions/cmd/CmdFactionsPromote.java | 4 - .../cmd/CmdFactionsRelationAbstract.java | 4 +- .../factions/cmd/CmdFactionsSeeChunk.java | 6 +- .../factions/cmd/CmdFactionsSethome.java | 6 +- .../factions/cmd/CmdFactionsShow.java | 5 - .../factions/cmd/CmdFactionsTag.java | 3 - .../factions/cmd/CmdFactionsTitle.java | 3 - .../factions/cmd/CmdFactionsUnclaim.java | 6 +- .../factions/cmd/CmdFactionsUnclaimall.java | 3 - .../factions/cmd/CmdFactionsVersion.java | 8 - .../massivecraft/factions/cmd/FCommand.java | 434 +---------------- .../factions/cmd/FCommandOld.java | 443 ++++++++++++++++++ 38 files changed, 473 insertions(+), 627 deletions(-) delete mode 100644 src/com/massivecraft/factions/cmd/CmdFactionsAutoHelp.java create mode 100644 src/com/massivecraft/factions/cmd/FCommandOld.java diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsAccess.java b/src/com/massivecraft/factions/cmd/CmdFactionsAccess.java index 5125c36d..eadef2f8 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsAccess.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsAccess.java @@ -7,6 +7,7 @@ import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.Perm; import com.massivecraft.factions.TerritoryAccess; import com.massivecraft.factions.integration.SpoutFeatures; +import com.massivecraft.mcore.cmd.req.ReqIsPlayer; import com.massivecraft.mcore.ps.PS; import com.massivecraft.mcore.util.Txt; @@ -23,10 +24,7 @@ public class CmdFactionsAccess extends FCommand this.setHelpShort("view or grant access for the claimed territory you are in"); - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeOfficer = false; - senderMustBeLeader = false; + this.addRequirements(ReqIsPlayer.get()); } @Override diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsAdmin.java b/src/com/massivecraft/factions/cmd/CmdFactionsAdmin.java index 472375fa..df26d580 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsAdmin.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsAdmin.java @@ -14,11 +14,6 @@ public class CmdFactionsAdmin extends FCommand this.optionalArgs.put("on/off", "flip"); this.permission = Perm.ADMIN.node; - - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeOfficer = false; - senderMustBeLeader = false; } @Override diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsAutoClaim.java b/src/com/massivecraft/factions/cmd/CmdFactionsAutoClaim.java index 9fcf0aaa..3e8e3dde 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsAutoClaim.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsAutoClaim.java @@ -3,6 +3,7 @@ package com.massivecraft.factions.cmd; import com.massivecraft.factions.FPerm; import com.massivecraft.factions.Faction; import com.massivecraft.factions.Perm; +import com.massivecraft.mcore.cmd.req.ReqIsPlayer; public class CmdFactionsAutoClaim extends FCommand { @@ -16,10 +17,7 @@ public class CmdFactionsAutoClaim extends FCommand this.permission = Perm.AUTOCLAIM.node; - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeOfficer = false; - senderMustBeLeader = false; + this.addRequirements(ReqIsPlayer.get()); } @Override diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsAutoHelp.java b/src/com/massivecraft/factions/cmd/CmdFactionsAutoHelp.java deleted file mode 100644 index fddcdb99..00000000 --- a/src/com/massivecraft/factions/cmd/CmdFactionsAutoHelp.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.massivecraft.factions.cmd; - -import java.util.ArrayList; - -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.zcore.CommandVisibility; -import com.massivecraft.factions.zcore.MCommand; -import com.massivecraft.mcore.util.Txt; - -public class CmdFactionsAutoHelp extends MCommand -{ - public CmdFactionsAutoHelp() - { - super(Factions.get()); - this.aliases.add("?"); - this.aliases.add("h"); - this.aliases.add("help"); - - this.setHelpShort(""); - - this.optionalArgs.put("page","1"); - } - - @Override - public void perform() - { - if (this.commandChain.size() == 0) return; - MCommand pcmd = this.commandChain.get(this.commandChain.size()-1); - - ArrayList lines = new ArrayList(); - - lines.addAll(pcmd.helpLong); - - for(MCommand scmd : pcmd.subCommands) - { - if - ( - scmd.visibility == CommandVisibility.VISIBLE - || - (scmd.visibility == CommandVisibility.SECRET && scmd.validSenderPermissions(sender, false)) - ) - { - lines.add(scmd.getUseageTemplate(this.commandChain, true)); - } - } - - sendMessage(Txt.getPage(lines, this.argAsInt(0, 1), "Help for command \""+pcmd.aliases.get(0)+"\"")); - } -} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsCape.java b/src/com/massivecraft/factions/cmd/CmdFactionsCape.java index 320a0448..3be59b9c 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsCape.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsCape.java @@ -16,11 +16,6 @@ public class CmdFactionsCape extends FCommand this.permission = Perm.CAPE.node; - senderMustBePlayer = false; - senderMustBeMember = false; - senderMustBeOfficer = false; - senderMustBeLeader = false; - this.addSubCommand(this.cmdCapeGet); this.addSubCommand(this.cmdCapeSet); this.addSubCommand(this.cmdCapeRemove); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsCapeAbstract.java b/src/com/massivecraft/factions/cmd/CmdFactionsCapeAbstract.java index 278598fd..3b9b8ce8 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsCapeAbstract.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsCapeAbstract.java @@ -15,11 +15,6 @@ public abstract class CmdFactionsCapeAbstract extends FCommand public CmdFactionsCapeAbstract() { this.optionalArgs.put("faction", "your"); - - senderMustBePlayer = false; - senderMustBeMember = false; - senderMustBeOfficer = false; - senderMustBeLeader = false; } @Override diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsClaim.java b/src/com/massivecraft/factions/cmd/CmdFactionsClaim.java index 31739d83..2a0a31f7 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsClaim.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsClaim.java @@ -4,6 +4,7 @@ import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.Faction; import com.massivecraft.factions.Perm; import com.massivecraft.factions.util.SpiralTask; +import com.massivecraft.mcore.cmd.req.ReqIsPlayer; import com.massivecraft.mcore.ps.PS; @@ -21,10 +22,7 @@ public class CmdFactionsClaim extends FCommand this.permission = Perm.CLAIM.node; - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeOfficer = false; - senderMustBeLeader = false; + this.addRequirements(ReqIsPlayer.get()); } @Override diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsCreate.java b/src/com/massivecraft/factions/cmd/CmdFactionsCreate.java index 7395f265..98c34617 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsCreate.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsCreate.java @@ -14,6 +14,7 @@ import com.massivecraft.factions.Perm; import com.massivecraft.factions.Rel; import com.massivecraft.factions.event.FPlayerJoinEvent; import com.massivecraft.factions.event.FactionCreateEvent; +import com.massivecraft.mcore.cmd.req.ReqIsPlayer; public class CmdFactionsCreate extends FCommand { @@ -26,11 +27,6 @@ public class CmdFactionsCreate extends FCommand //this.optionalArgs.put("", ""); this.permission = Perm.CREATE.node; - - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeOfficer = false; - senderMustBeLeader = false; } @Override @@ -63,7 +59,7 @@ public class CmdFactionsCreate extends FCommand // trigger the faction creation event (cancellable) String factionId = FactionColl.get().getIdStrategy().generate(FactionColl.get()); - FactionCreateEvent createEvent = new FactionCreateEvent(me, tag, factionId); + FactionCreateEvent createEvent = new FactionCreateEvent(sender, tag, factionId); Bukkit.getServer().getPluginManager().callEvent(createEvent); if(createEvent.isCancelled()) return; @@ -83,7 +79,7 @@ public class CmdFactionsCreate extends FCommand faction.setTag(tag); // trigger the faction join event for the creator - FPlayerJoinEvent joinEvent = new FPlayerJoinEvent(FPlayerColl.get().get(me),faction,FPlayerJoinEvent.PlayerJoinReason.CREATE); + FPlayerJoinEvent joinEvent = new FPlayerJoinEvent(FPlayerColl.get().get(sender),faction,FPlayerJoinEvent.PlayerJoinReason.CREATE); Bukkit.getServer().getPluginManager().callEvent(joinEvent); // join event cannot be cancelled or you'll have an empty faction diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsDeinvite.java b/src/com/massivecraft/factions/cmd/CmdFactionsDeinvite.java index 619f08df..80e9b593 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsDeinvite.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsDeinvite.java @@ -17,7 +17,6 @@ public class CmdFactionsDeinvite extends FCommand this.permission = Perm.DEINVITE.node; - senderMustBePlayer = true; senderMustBeMember = false; senderMustBeOfficer = true; senderMustBeLeader = false; diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsDemote.java b/src/com/massivecraft/factions/cmd/CmdFactionsDemote.java index 931a529a..cd787202 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsDemote.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsDemote.java @@ -20,10 +20,6 @@ public class CmdFactionsDemote extends FCommand //To demote someone from member -> recruit you must be an officer. //To demote someone from officer -> member you must be a leader. //We'll handle this internally - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeOfficer = false; - senderMustBeLeader = false; } @Override diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsDescription.java b/src/com/massivecraft/factions/cmd/CmdFactionsDescription.java index 2fe42f19..18e09203 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsDescription.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsDescription.java @@ -19,10 +19,7 @@ public class CmdFactionsDescription extends FCommand this.permission = Perm.DESCRIPTION.node; - senderMustBePlayer = true; - senderMustBeMember = false; senderMustBeOfficer = true; - senderMustBeLeader = false; } @Override diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsDisband.java b/src/com/massivecraft/factions/cmd/CmdFactionsDisband.java index 238b98e7..3ef2bfdd 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsDisband.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsDisband.java @@ -26,11 +26,6 @@ public class CmdFactionsDisband extends FCommand this.optionalArgs.put("faction", "your"); this.permission = Perm.DISBAND.node; - - senderMustBePlayer = false; - senderMustBeMember = false; - senderMustBeOfficer = false; - senderMustBeLeader = false; } @Override diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsFlag.java b/src/com/massivecraft/factions/cmd/CmdFactionsFlag.java index dfb9e05f..221808e9 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsFlag.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsFlag.java @@ -19,11 +19,6 @@ public class CmdFactionsFlag extends FCommand this.optionalArgs.put("yes/no", "read"); this.permission = Perm.FLAG.node; - - senderMustBePlayer = false; - senderMustBeMember = false; - senderMustBeOfficer = false; - senderMustBeLeader = false; } @Override diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsHome.java b/src/com/massivecraft/factions/cmd/CmdFactionsHome.java index f419ee35..93571c6f 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsHome.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsHome.java @@ -16,6 +16,7 @@ import com.massivecraft.factions.Faction; import com.massivecraft.factions.Perm; import com.massivecraft.factions.Rel; import com.massivecraft.factions.integration.EssentialsFeatures; +import com.massivecraft.mcore.cmd.req.ReqIsPlayer; import com.massivecraft.mcore.ps.PS; import com.massivecraft.mcore.util.SmokeUtil; @@ -33,10 +34,9 @@ public class CmdFactionsHome extends FCommand this.permission = Perm.HOME.node; - senderMustBePlayer = true; + this.addRequirements(ReqIsPlayer.get()); + senderMustBeMember = true; - senderMustBeOfficer = false; - senderMustBeLeader = false; } @Override diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsInvite.java b/src/com/massivecraft/factions/cmd/CmdFactionsInvite.java index a508d88a..637f1e02 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsInvite.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsInvite.java @@ -4,6 +4,7 @@ import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.FPerm; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.Perm; +import com.massivecraft.mcore.cmd.req.ReqIsPlayer; public class CmdFactionsInvite extends FCommand { @@ -18,10 +19,10 @@ public class CmdFactionsInvite extends FCommand this.permission = Perm.INVITE.node; - senderMustBePlayer = true; - senderMustBeMember = false; + + this.addRequirements(ReqIsPlayer.get()); + senderMustBeOfficer = true; - senderMustBeLeader = false; } @Override diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsJoin.java b/src/com/massivecraft/factions/cmd/CmdFactionsJoin.java index 5ac9dad1..4752f51e 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsJoin.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsJoin.java @@ -21,11 +21,6 @@ public class CmdFactionsJoin extends FCommand this.optionalArgs.put("player", "you"); this.permission = Perm.JOIN.node; - - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeOfficer = false; - senderMustBeLeader = false; } @Override diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsKick.java b/src/com/massivecraft/factions/cmd/CmdFactionsKick.java index e3fb63a0..5ccfd1b4 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsKick.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsKick.java @@ -23,11 +23,6 @@ public class CmdFactionsKick extends FCommand //this.optionalArgs.put("", ""); this.permission = Perm.KICK.node; - - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeOfficer = false; - senderMustBeLeader = false; } @Override diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsLeader.java b/src/com/massivecraft/factions/cmd/CmdFactionsLeader.java index 6351e87d..9aab9958 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsLeader.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsLeader.java @@ -22,11 +22,6 @@ public class CmdFactionsLeader extends FCommand this.optionalArgs.put("faction", "your"); this.permission = Perm.LEADER.node; - - senderMustBePlayer = false; - senderMustBeMember = false; - senderMustBeOfficer = false; - senderMustBeLeader = false; } @Override diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsLeave.java b/src/com/massivecraft/factions/cmd/CmdFactionsLeave.java index a27c681c..f94ec811 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsLeave.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsLeave.java @@ -14,10 +14,7 @@ public class CmdFactionsLeave extends FCommand { this.permission = Perm.LEAVE.node; - senderMustBePlayer = true; senderMustBeMember = true; - senderMustBeOfficer = false; - senderMustBeLeader = false; } @Override diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsList.java b/src/com/massivecraft/factions/cmd/CmdFactionsList.java index 551ed5fb..057f5ac9 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsList.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsList.java @@ -24,11 +24,6 @@ public class CmdFactionsList extends FCommand this.optionalArgs.put("page", "1"); this.permission = Perm.LIST.node; - - senderMustBePlayer = false; - senderMustBeMember = false; - senderMustBeOfficer = false; - senderMustBeLeader = false; } @Override diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsMap.java b/src/com/massivecraft/factions/cmd/CmdFactionsMap.java index ac6f9878..ee712a3b 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsMap.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsMap.java @@ -3,6 +3,7 @@ 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.req.ReqIsPlayer; import com.massivecraft.mcore.ps.PS; @@ -18,10 +19,7 @@ public class CmdFactionsMap extends FCommand this.permission = Perm.MAP.node; - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeOfficer = false; - senderMustBeLeader = false; + this.addRequirements(ReqIsPlayer.get()); } @Override diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsOfficer.java b/src/com/massivecraft/factions/cmd/CmdFactionsOfficer.java index 09bbb76f..7a600805 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsOfficer.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsOfficer.java @@ -17,11 +17,6 @@ public class CmdFactionsOfficer extends FCommand //this.optionalArgs.put("", ""); this.permission = Perm.OFFICER.node; - - senderMustBePlayer = false; - senderMustBeMember = false; - senderMustBeOfficer = false; - senderMustBeLeader = false; } @Override diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsOpen.java b/src/com/massivecraft/factions/cmd/CmdFactionsOpen.java index 1ba456f5..5227f674 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsOpen.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsOpen.java @@ -17,10 +17,7 @@ public class CmdFactionsOpen extends FCommand this.permission = Perm.OPEN.node; - senderMustBePlayer = true; - senderMustBeMember = false; senderMustBeOfficer = true; - senderMustBeLeader = false; } @Override diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPerm.java b/src/com/massivecraft/factions/cmd/CmdFactionsPerm.java index 4b474bf8..36f7d967 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPerm.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsPerm.java @@ -22,11 +22,6 @@ public class CmdFactionsPerm extends FCommand this.permission = Perm.PERM.node; this.errorOnToManyArgs = false; - - senderMustBePlayer = false; - senderMustBeMember = false; - senderMustBeOfficer = false; - senderMustBeLeader = false; } @Override diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPower.java b/src/com/massivecraft/factions/cmd/CmdFactionsPower.java index 6a48ac57..02e49d95 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPower.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsPower.java @@ -17,11 +17,6 @@ public class CmdFactionsPower extends FCommand this.optionalArgs.put("player", "you"); this.permission = Perm.POWER.node; - - senderMustBePlayer = false; - senderMustBeMember = false; - senderMustBeOfficer = false; - senderMustBeLeader = false; } @Override diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPowerBoost.java b/src/com/massivecraft/factions/cmd/CmdFactionsPowerBoost.java index cb09da75..2fa5b3ff 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPowerBoost.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsPowerBoost.java @@ -17,11 +17,6 @@ public class CmdFactionsPowerBoost extends FCommand this.requiredArgs.add("#"); this.permission = Perm.POWERBOOST.node; - - senderMustBePlayer = false; - senderMustBeMember = false; - senderMustBeOfficer = false; - senderMustBeLeader = false; } @Override diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPromote.java b/src/com/massivecraft/factions/cmd/CmdFactionsPromote.java index 37aee943..947b2017 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPromote.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsPromote.java @@ -20,10 +20,6 @@ public class CmdFactionsPromote extends FCommand //To promote someone from recruit -> member you must be an officer. //To promote someone from member -> officer you must be a leader. //We'll handle this internally - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeOfficer = false; - senderMustBeLeader = false; } @Override diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsRelationAbstract.java b/src/com/massivecraft/factions/cmd/CmdFactionsRelationAbstract.java index 8ecb3ff6..f7e9260e 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsRelationAbstract.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsRelationAbstract.java @@ -9,6 +9,7 @@ import com.massivecraft.factions.Perm; import com.massivecraft.factions.Rel; import com.massivecraft.factions.event.FactionRelationEvent; import com.massivecraft.factions.integration.SpoutFeatures; +import com.massivecraft.mcore.cmd.req.ReqIsPlayer; public abstract class CmdFactionsRelationAbstract extends FCommand { @@ -22,10 +23,7 @@ public abstract class CmdFactionsRelationAbstract extends FCommand this.permission = Perm.RELATION.node; - senderMustBePlayer = true; - senderMustBeMember = false; senderMustBeOfficer = true; - senderMustBeLeader = false; } @Override diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsSeeChunk.java b/src/com/massivecraft/factions/cmd/CmdFactionsSeeChunk.java index 2b9518f2..f5d35207 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsSeeChunk.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsSeeChunk.java @@ -7,6 +7,7 @@ import org.bukkit.entity.Player; import com.massivecraft.factions.Perm; import com.massivecraft.factions.util.VisualizeUtil; +import com.massivecraft.mcore.cmd.req.ReqIsPlayer; public class CmdFactionsSeeChunk extends FCommand { @@ -18,10 +19,7 @@ public class CmdFactionsSeeChunk extends FCommand this.permission = Perm.SEE_CHUNK.node; - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeOfficer = false; - senderMustBeLeader = false; + this.addRequirements(ReqIsPlayer.get()); } @Override diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsSethome.java b/src/com/massivecraft/factions/cmd/CmdFactionsSethome.java index e7e30657..5c0961fc 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.mcore.cmd.req.ReqIsPlayer; import com.massivecraft.mcore.ps.PS; public class CmdFactionsSethome extends FCommand @@ -18,10 +19,7 @@ public class CmdFactionsSethome extends FCommand this.permission = Perm.SETHOME.node; - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeOfficer = false; - senderMustBeLeader = false; + this.addRequirements(ReqIsPlayer.get()); } @Override diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsShow.java b/src/com/massivecraft/factions/cmd/CmdFactionsShow.java index 8b1d0b06..65e90949 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsShow.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsShow.java @@ -26,11 +26,6 @@ public class CmdFactionsShow extends FCommand this.optionalArgs.put("faction", "your"); this.permission = Perm.SHOW.node; - - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeOfficer = false; - senderMustBeLeader = false; } @Override diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsTag.java b/src/com/massivecraft/factions/cmd/CmdFactionsTag.java index cda317cb..15827311 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsTag.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsTag.java @@ -24,10 +24,7 @@ public class CmdFactionsTag extends FCommand this.permission = Perm.TAG.node; - senderMustBePlayer = true; - senderMustBeMember = false; senderMustBeOfficer = true; - senderMustBeLeader = false; } @Override diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsTitle.java b/src/com/massivecraft/factions/cmd/CmdFactionsTitle.java index 87fc6902..bb33edca 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsTitle.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsTitle.java @@ -17,10 +17,7 @@ public class CmdFactionsTitle extends FCommand this.permission = Perm.TITLE.node; - senderMustBePlayer = true; - senderMustBeMember = false; senderMustBeOfficer = true; - senderMustBeLeader = false; } @Override diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsUnclaim.java b/src/com/massivecraft/factions/cmd/CmdFactionsUnclaim.java index efdd6390..7008a81c 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsUnclaim.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsUnclaim.java @@ -11,6 +11,7 @@ import com.massivecraft.factions.FPerm; import com.massivecraft.factions.Faction; import com.massivecraft.factions.Factions; import com.massivecraft.factions.Perm; +import com.massivecraft.mcore.cmd.req.ReqIsPlayer; import com.massivecraft.mcore.ps.PS; public class CmdFactionsUnclaim extends FCommand @@ -25,10 +26,7 @@ public class CmdFactionsUnclaim extends FCommand this.permission = Perm.UNCLAIM.node; - senderMustBePlayer = true; - senderMustBeMember = false; - senderMustBeOfficer = false; - senderMustBeLeader = false; + this.addRequirements(ReqIsPlayer.get()); } @Override diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsUnclaimall.java b/src/com/massivecraft/factions/cmd/CmdFactionsUnclaimall.java index 564508f5..b18c87f7 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsUnclaimall.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsUnclaimall.java @@ -22,10 +22,7 @@ public class CmdFactionsUnclaimall extends FCommand this.permission = Perm.UNCLAIM_ALL.node; - senderMustBePlayer = true; - senderMustBeMember = false; senderMustBeOfficer = true; - senderMustBeLeader = false; } @Override diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsVersion.java b/src/com/massivecraft/factions/cmd/CmdFactionsVersion.java index f00ecd8e..035d2089 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsVersion.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsVersion.java @@ -10,15 +10,7 @@ public class CmdFactionsVersion extends FCommand { this.aliases.add("version"); - //this.requiredArgs.add(""); - //this.optionalArgs.put("", ""); - this.permission = Perm.VERSION.node; - - senderMustBePlayer = false; - senderMustBeMember = false; - senderMustBeOfficer = false; - senderMustBeLeader = false; } @Override diff --git a/src/com/massivecraft/factions/cmd/FCommand.java b/src/com/massivecraft/factions/cmd/FCommand.java index bbe0526e..1615a812 100644 --- a/src/com/massivecraft/factions/cmd/FCommand.java +++ b/src/com/massivecraft/factions/cmd/FCommand.java @@ -1,443 +1,19 @@ package com.massivecraft.factions.cmd; -import java.util.List; - -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import com.massivecraft.factions.ConfServer; -import com.massivecraft.factions.integration.Econ; -import com.massivecraft.factions.FFlag; -import com.massivecraft.factions.FPerm; import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayerColl; import com.massivecraft.factions.Faction; -import com.massivecraft.factions.FactionColl; -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.Rel; -import com.massivecraft.factions.zcore.MCommand; -import com.massivecraft.mcore.util.Txt; +import com.massivecraft.mcore.cmd.MCommand; - -public abstract class FCommand extends MCommand +public abstract class FCommand extends MCommand { public FPlayer fme; public Faction myFaction; - // TODO: All these are "command reqs" - public boolean senderMustBeMember; - public boolean senderMustBeOfficer; - public boolean senderMustBeLeader; - - public boolean isMoneyCommand; - - public FCommand() - { - super(Factions.get()); - - // The money commands must be disabled if money should not be used. - isMoneyCommand = false; - - senderMustBeMember = false; - senderMustBeOfficer = false; - senderMustBeLeader = false; - } - @Override - public void execute(CommandSender sender, List args, List> commandChain) + public void fixSenderVars() { - if (sender instanceof Player) - { - this.fme = FPlayerColl.get().get(sender); - this.myFaction = this.fme.getFaction(); - } - else - { - this.fme = null; - this.myFaction = null; - } - super.execute(sender, args, commandChain); - } - - @Override - public boolean isEnabled() - { - if (this.isMoneyCommand && ! ConfServer.econEnabled) - { - msg("Faction economy features are disabled on this server."); - return false; - } - - if (this.isMoneyCommand && ! ConfServer.bankEnabled) - { - msg("The faction bank system is disabled on this server."); - return false; - } - - return true; - } - - @Override - public boolean validSenderType(CommandSender sender, boolean informSenderIfNot) - { - boolean superValid = super.validSenderType(sender, informSenderIfNot); - if ( ! superValid) return false; - - if ( ! (this.senderMustBeMember || this.senderMustBeOfficer || this.senderMustBeLeader)) return true; - - if ( ! (sender instanceof Player)) return false; - - FPlayer fplayer = FPlayerColl.get().get((Player)sender); - - if ( ! fplayer.hasFaction()) - { - sender.sendMessage(Txt.parse("You are not member of any faction.")); - return false; - } - - if (this.senderMustBeOfficer && ! fplayer.getRole().isAtLeast(Rel.OFFICER)) - { - sender.sendMessage(Txt.parse("Only faction moderators can %s.", this.getHelpShort())); - return false; - } - - if (this.senderMustBeLeader && ! fplayer.getRole().isAtLeast(Rel.LEADER)) - { - sender.sendMessage(Txt.parse("Only faction admins can %s.", this.getHelpShort())); - return false; - } - - return true; - } - - // -------------------------------------------- // - // Assertions - // -------------------------------------------- // - - // These are not used. Remove in the future if no need for them arises. - - /* - public boolean assertHasFaction() - { - if (me == null) return true; - - if ( ! fme.hasFaction()) - { - sendMessage("You are not member of any faction."); - return false; - } - return true; - } - - public boolean assertMinRole(Rel role) - { - if (me == null) return true; - - if (fme.getRole().isLessThan(role)) - { - msg("You must be "+role+" to "+this.getHelpShort()+"."); - return false; - } - return true; - }*/ - - // -------------------------------------------- // - // Argument Readers - // -------------------------------------------- // - - // TODO: Convert these arg-readers to MCore ArgReaders. - - // FPLAYER ====================== - public FPlayer strAsFPlayer(String name, FPlayer def, boolean msg) - { - FPlayer ret = def; - - if (name != null) - { - FPlayer fplayer = FPlayerColl.get().get(name); - if (fplayer != null) - { - ret = fplayer; - } - } - - if (msg && ret == null) - { - this.msg("No player \"

%s\" could be found.", name); - } - - return ret; - } - public FPlayer argAsFPlayer(int idx, FPlayer def, boolean msg) - { - return this.strAsFPlayer(this.argAsString(idx), def, msg); - } - public FPlayer argAsFPlayer(int idx, FPlayer def) - { - return this.argAsFPlayer(idx, def, true); - } - public FPlayer argAsFPlayer(int idx) - { - return this.argAsFPlayer(idx, null); - } - - // BEST FPLAYER MATCH ====================== - public FPlayer strAsBestFPlayerMatch(String name, FPlayer def, boolean msg) - { - FPlayer ret = def; - - if (name != null) - { - // TODO: Easy fix for now - //FPlayer fplayer = FPlayerColl.get().getBestIdMatch(name); - FPlayer fplayer = FPlayerColl.get().getId2entity().get(name); - if (fplayer != null) - { - ret = fplayer; - } - } - - if (msg && ret == null) - { - this.msg("No player match found for \"

%s\".", name); - } - - return ret; - } - public FPlayer argAsBestFPlayerMatch(int idx, FPlayer def, boolean msg) - { - return this.strAsBestFPlayerMatch(this.argAsString(idx), def, msg); - } - public FPlayer argAsBestFPlayerMatch(int idx, FPlayer def) - { - return this.argAsBestFPlayerMatch(idx, def, true); - } - public FPlayer argAsBestFPlayerMatch(int idx) - { - return this.argAsBestFPlayerMatch(idx, null); - } - - // FACTION ====================== - public Faction strAsFaction(String name, Faction def, boolean msg) - { - Faction ret = def; - - if (name != null) - { - Faction faction = null; - - // First we try an exact match - if (faction == null) - { - faction = FactionColl.get().getByTag(name); - } - - // Next we match faction tags - if (faction == null) - { - faction = FactionColl.get().getBestTagMatch(name); - } - - // Next we match player names - if (faction == null) - { - // TODO: Easy fix for now - //FPlayer fplayer = FPlayerColl.get().getBestIdMatch(name); - FPlayer fplayer = FPlayerColl.get().getId2entity().get(name); - - if (fplayer != null) - { - faction = fplayer.getFaction(); - } - } - - if (faction != null) - { - ret = faction; - } - } - - if (msg && ret == null) - { - this.msg("The faction or player \"

%s\" could not be found.", name); - } - - return ret; - } - public Faction argAsFaction(int idx, Faction def, boolean msg) - { - return this.strAsFaction(this.argAsString(idx), def, msg); - } - public Faction argAsFaction(int idx, Faction def) - { - return this.argAsFaction(idx, def, true); - } - public Faction argAsFaction(int idx) - { - return this.argAsFaction(idx, null); - } - - // FACTION FLAG ====================== - public FFlag strAsFactionFlag(String name, FFlag def, boolean msg) - { - FFlag ret = def; - - if (name != null) - { - FFlag flag = FFlag.parse(name); - if (flag != null) - { - ret = flag; - } - } - - if (msg && ret == null) - { - this.msg("The faction-flag \"

%s\" could not be found.", name); - } - - return ret; - } - public FFlag argAsFactionFlag(int idx, FFlag def, boolean msg) - { - return this.strAsFactionFlag(this.argAsString(idx), def, msg); - } - public FFlag argAsFactionFlag(int idx, FFlag def) - { - return this.argAsFactionFlag(idx, def, true); - } - public FFlag argAsFactionFlag(int idx) - { - return this.argAsFactionFlag(idx, null); - } - - // FACTION PERM ====================== - public FPerm strAsFactionPerm(String name, FPerm def, boolean msg) - { - FPerm ret = def; - - if (name != null) - { - FPerm perm = FPerm.parse(name); - if (perm != null) - { - ret = perm; - } - } - - if (msg && ret == null) - { - this.msg("The faction-perm \"

%s\" could not be found.", name); - } - - return ret; - } - public FPerm argAsFactionPerm(int idx, FPerm def, boolean msg) - { - return this.strAsFactionPerm(this.argAsString(idx), def, msg); - } - public FPerm argAsFactionPerm(int idx, FPerm def) - { - return this.argAsFactionPerm(idx, def, true); - } - public FPerm argAsFactionPerm(int idx) - { - return this.argAsFactionPerm(idx, null); - } - - // FACTION REL ====================== - public Rel strAsRel(String name, Rel def, boolean msg) - { - Rel ret = def; - - if (name != null) - { - Rel perm = Rel.parse(name); - if (perm != null) - { - ret = perm; - } - } - - if (msg && ret == null) - { - this.msg("The role \"

%s\" could not be found.", name); - } - - return ret; - } - public Rel argAsRel(int idx, Rel def, boolean msg) - { - return this.strAsRel(this.argAsString(idx), def, msg); - } - public Rel argAsRel(int idx, Rel def) - { - return this.argAsRel(idx, def, true); - } - public Rel argAsRel(int idx) - { - 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); + this.fme = FPlayerColl.get().get(this.sender); + this.myFaction = this.fme.getFaction(); } } diff --git a/src/com/massivecraft/factions/cmd/FCommandOld.java b/src/com/massivecraft/factions/cmd/FCommandOld.java new file mode 100644 index 00000000..d8c12fec --- /dev/null +++ b/src/com/massivecraft/factions/cmd/FCommandOld.java @@ -0,0 +1,443 @@ +package com.massivecraft.factions.cmd; + +import java.util.List; + +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import com.massivecraft.factions.ConfServer; +import com.massivecraft.factions.integration.Econ; +import com.massivecraft.factions.FFlag; +import com.massivecraft.factions.FPerm; +import com.massivecraft.factions.FPlayer; +import com.massivecraft.factions.FPlayerColl; +import com.massivecraft.factions.Faction; +import com.massivecraft.factions.FactionColl; +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.Rel; +import com.massivecraft.factions.zcore.MCommand; +import com.massivecraft.mcore.util.Txt; + + +public abstract class FCommandOld extends MCommand +{ + public FPlayer fme; + public Faction myFaction; + + // TODO: All these are "command reqs" + public boolean senderMustBeMember; + public boolean senderMustBeOfficer; + public boolean senderMustBeLeader; + + public boolean isMoneyCommand; + + public FCommandOld() + { + super(Factions.get()); + + // The money commands must be disabled if money should not be used. + isMoneyCommand = false; + + senderMustBeMember = false; + senderMustBeOfficer = false; + senderMustBeLeader = false; + } + + @Override + public void execute(CommandSender sender, List args, List> commandChain) + { + if (sender instanceof Player) + { + this.fme = FPlayerColl.get().get(sender); + this.myFaction = this.fme.getFaction(); + } + else + { + this.fme = null; + this.myFaction = null; + } + super.execute(sender, args, commandChain); + } + + @Override + public boolean isEnabled() + { + if (this.isMoneyCommand && ! ConfServer.econEnabled) + { + msg("Faction economy features are disabled on this server."); + return false; + } + + if (this.isMoneyCommand && ! ConfServer.bankEnabled) + { + msg("The faction bank system is disabled on this server."); + return false; + } + + return true; + } + + @Override + public boolean validSenderType(CommandSender sender, boolean informSenderIfNot) + { + boolean superValid = super.validSenderType(sender, informSenderIfNot); + if ( ! superValid) return false; + + if ( ! (this.senderMustBeMember || this.senderMustBeOfficer || this.senderMustBeLeader)) return true; + + if ( ! (sender instanceof Player)) return false; + + FPlayer fplayer = FPlayerColl.get().get((Player)sender); + + if ( ! fplayer.hasFaction()) + { + sender.sendMessage(Txt.parse("You are not member of any faction.")); + return false; + } + + if (this.senderMustBeOfficer && ! fplayer.getRole().isAtLeast(Rel.OFFICER)) + { + sender.sendMessage(Txt.parse("Only faction moderators can %s.", this.getHelpShort())); + return false; + } + + if (this.senderMustBeLeader && ! fplayer.getRole().isAtLeast(Rel.LEADER)) + { + sender.sendMessage(Txt.parse("Only faction admins can %s.", this.getHelpShort())); + return false; + } + + return true; + } + + // -------------------------------------------- // + // Assertions + // -------------------------------------------- // + + // These are not used. Remove in the future if no need for them arises. + + /* + public boolean assertHasFaction() + { + if (me == null) return true; + + if ( ! fme.hasFaction()) + { + sendMessage("You are not member of any faction."); + return false; + } + return true; + } + + public boolean assertMinRole(Rel role) + { + if (me == null) return true; + + if (fme.getRole().isLessThan(role)) + { + msg("You must be "+role+" to "+this.getHelpShort()+"."); + return false; + } + return true; + }*/ + + // -------------------------------------------- // + // Argument Readers + // -------------------------------------------- // + + // TODO: Convert these arg-readers to MCore ArgReaders. + + // FPLAYER ====================== + public FPlayer strAsFPlayer(String name, FPlayer def, boolean msg) + { + FPlayer ret = def; + + if (name != null) + { + FPlayer fplayer = FPlayerColl.get().get(name); + if (fplayer != null) + { + ret = fplayer; + } + } + + if (msg && ret == null) + { + this.msg("No player \"

%s\" could be found.", name); + } + + return ret; + } + public FPlayer argAsFPlayer(int idx, FPlayer def, boolean msg) + { + return this.strAsFPlayer(this.argAsString(idx), def, msg); + } + public FPlayer argAsFPlayer(int idx, FPlayer def) + { + return this.argAsFPlayer(idx, def, true); + } + public FPlayer argAsFPlayer(int idx) + { + return this.argAsFPlayer(idx, null); + } + + // BEST FPLAYER MATCH ====================== + public FPlayer strAsBestFPlayerMatch(String name, FPlayer def, boolean msg) + { + FPlayer ret = def; + + if (name != null) + { + // TODO: Easy fix for now + //FPlayer fplayer = FPlayerColl.get().getBestIdMatch(name); + FPlayer fplayer = FPlayerColl.get().getId2entity().get(name); + if (fplayer != null) + { + ret = fplayer; + } + } + + if (msg && ret == null) + { + this.msg("No player match found for \"

%s\".", name); + } + + return ret; + } + public FPlayer argAsBestFPlayerMatch(int idx, FPlayer def, boolean msg) + { + return this.strAsBestFPlayerMatch(this.argAsString(idx), def, msg); + } + public FPlayer argAsBestFPlayerMatch(int idx, FPlayer def) + { + return this.argAsBestFPlayerMatch(idx, def, true); + } + public FPlayer argAsBestFPlayerMatch(int idx) + { + return this.argAsBestFPlayerMatch(idx, null); + } + + // FACTION ====================== + public Faction strAsFaction(String name, Faction def, boolean msg) + { + Faction ret = def; + + if (name != null) + { + Faction faction = null; + + // First we try an exact match + if (faction == null) + { + faction = FactionColl.get().getByTag(name); + } + + // Next we match faction tags + if (faction == null) + { + faction = FactionColl.get().getBestTagMatch(name); + } + + // Next we match player names + if (faction == null) + { + // TODO: Easy fix for now + //FPlayer fplayer = FPlayerColl.get().getBestIdMatch(name); + FPlayer fplayer = FPlayerColl.get().getId2entity().get(name); + + if (fplayer != null) + { + faction = fplayer.getFaction(); + } + } + + if (faction != null) + { + ret = faction; + } + } + + if (msg && ret == null) + { + this.msg("The faction or player \"

%s\" could not be found.", name); + } + + return ret; + } + public Faction argAsFaction(int idx, Faction def, boolean msg) + { + return this.strAsFaction(this.argAsString(idx), def, msg); + } + public Faction argAsFaction(int idx, Faction def) + { + return this.argAsFaction(idx, def, true); + } + public Faction argAsFaction(int idx) + { + return this.argAsFaction(idx, null); + } + + // FACTION FLAG ====================== + public FFlag strAsFactionFlag(String name, FFlag def, boolean msg) + { + FFlag ret = def; + + if (name != null) + { + FFlag flag = FFlag.parse(name); + if (flag != null) + { + ret = flag; + } + } + + if (msg && ret == null) + { + this.msg("The faction-flag \"

%s\" could not be found.", name); + } + + return ret; + } + public FFlag argAsFactionFlag(int idx, FFlag def, boolean msg) + { + return this.strAsFactionFlag(this.argAsString(idx), def, msg); + } + public FFlag argAsFactionFlag(int idx, FFlag def) + { + return this.argAsFactionFlag(idx, def, true); + } + public FFlag argAsFactionFlag(int idx) + { + return this.argAsFactionFlag(idx, null); + } + + // FACTION PERM ====================== + public FPerm strAsFactionPerm(String name, FPerm def, boolean msg) + { + FPerm ret = def; + + if (name != null) + { + FPerm perm = FPerm.parse(name); + if (perm != null) + { + ret = perm; + } + } + + if (msg && ret == null) + { + this.msg("The faction-perm \"

%s\" could not be found.", name); + } + + return ret; + } + public FPerm argAsFactionPerm(int idx, FPerm def, boolean msg) + { + return this.strAsFactionPerm(this.argAsString(idx), def, msg); + } + public FPerm argAsFactionPerm(int idx, FPerm def) + { + return this.argAsFactionPerm(idx, def, true); + } + public FPerm argAsFactionPerm(int idx) + { + return this.argAsFactionPerm(idx, null); + } + + // FACTION REL ====================== + public Rel strAsRel(String name, Rel def, boolean msg) + { + Rel ret = def; + + if (name != null) + { + Rel perm = Rel.parse(name); + if (perm != null) + { + ret = perm; + } + } + + if (msg && ret == null) + { + this.msg("The role \"

%s\" could not be found.", name); + } + + return ret; + } + public Rel argAsRel(int idx, Rel def, boolean msg) + { + return this.strAsRel(this.argAsString(idx), def, msg); + } + public Rel argAsRel(int idx, Rel def) + { + return this.argAsRel(idx, def, true); + } + public Rel argAsRel(int idx) + { + 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); + } +}