Starting to convert the faction commands.

This commit is contained in:
Olof Larsson 2013-04-16 09:48:57 +02:00
parent 03c058483c
commit 3d9847e4a6
38 changed files with 473 additions and 627 deletions

View File

@ -7,6 +7,7 @@ import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.TerritoryAccess; import com.massivecraft.factions.TerritoryAccess;
import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.factions.integration.SpoutFeatures;
import com.massivecraft.mcore.cmd.req.ReqIsPlayer;
import com.massivecraft.mcore.ps.PS; import com.massivecraft.mcore.ps.PS;
import com.massivecraft.mcore.util.Txt; 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"); this.setHelpShort("view or grant access for the claimed territory you are in");
senderMustBePlayer = true; this.addRequirements(ReqIsPlayer.get());
senderMustBeMember = false;
senderMustBeOfficer = false;
senderMustBeLeader = false;
} }
@Override @Override

View File

@ -14,11 +14,6 @@ public class CmdFactionsAdmin extends FCommand
this.optionalArgs.put("on/off", "flip"); this.optionalArgs.put("on/off", "flip");
this.permission = Perm.ADMIN.node; this.permission = Perm.ADMIN.node;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeOfficer = false;
senderMustBeLeader = false;
} }
@Override @Override

View File

@ -3,6 +3,7 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPerm; import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.mcore.cmd.req.ReqIsPlayer;
public class CmdFactionsAutoClaim extends FCommand public class CmdFactionsAutoClaim extends FCommand
{ {
@ -16,10 +17,7 @@ public class CmdFactionsAutoClaim extends FCommand
this.permission = Perm.AUTOCLAIM.node; this.permission = Perm.AUTOCLAIM.node;
senderMustBePlayer = true; this.addRequirements(ReqIsPlayer.get());
senderMustBeMember = false;
senderMustBeOfficer = false;
senderMustBeLeader = false;
} }
@Override @Override

View File

@ -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<Factions>
{
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<String> lines = new ArrayList<String>();
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)+"\""));
}
}

View File

@ -16,11 +16,6 @@ public class CmdFactionsCape extends FCommand
this.permission = Perm.CAPE.node; this.permission = Perm.CAPE.node;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeOfficer = false;
senderMustBeLeader = false;
this.addSubCommand(this.cmdCapeGet); this.addSubCommand(this.cmdCapeGet);
this.addSubCommand(this.cmdCapeSet); this.addSubCommand(this.cmdCapeSet);
this.addSubCommand(this.cmdCapeRemove); this.addSubCommand(this.cmdCapeRemove);

View File

@ -15,11 +15,6 @@ public abstract class CmdFactionsCapeAbstract extends FCommand
public CmdFactionsCapeAbstract() public CmdFactionsCapeAbstract()
{ {
this.optionalArgs.put("faction", "your"); this.optionalArgs.put("faction", "your");
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeOfficer = false;
senderMustBeLeader = false;
} }
@Override @Override

View File

@ -4,6 +4,7 @@ import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.util.SpiralTask; import com.massivecraft.factions.util.SpiralTask;
import com.massivecraft.mcore.cmd.req.ReqIsPlayer;
import com.massivecraft.mcore.ps.PS; import com.massivecraft.mcore.ps.PS;
@ -21,10 +22,7 @@ public class CmdFactionsClaim extends FCommand
this.permission = Perm.CLAIM.node; this.permission = Perm.CLAIM.node;
senderMustBePlayer = true; this.addRequirements(ReqIsPlayer.get());
senderMustBeMember = false;
senderMustBeOfficer = false;
senderMustBeLeader = false;
} }
@Override @Override

View File

@ -14,6 +14,7 @@ import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel; import com.massivecraft.factions.Rel;
import com.massivecraft.factions.event.FPlayerJoinEvent; import com.massivecraft.factions.event.FPlayerJoinEvent;
import com.massivecraft.factions.event.FactionCreateEvent; import com.massivecraft.factions.event.FactionCreateEvent;
import com.massivecraft.mcore.cmd.req.ReqIsPlayer;
public class CmdFactionsCreate extends FCommand public class CmdFactionsCreate extends FCommand
{ {
@ -26,11 +27,6 @@ public class CmdFactionsCreate extends FCommand
//this.optionalArgs.put("", ""); //this.optionalArgs.put("", "");
this.permission = Perm.CREATE.node; this.permission = Perm.CREATE.node;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeOfficer = false;
senderMustBeLeader = false;
} }
@Override @Override
@ -63,7 +59,7 @@ public class CmdFactionsCreate extends FCommand
// trigger the faction creation event (cancellable) // trigger the faction creation event (cancellable)
String factionId = FactionColl.get().getIdStrategy().generate(FactionColl.get()); 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); Bukkit.getServer().getPluginManager().callEvent(createEvent);
if(createEvent.isCancelled()) return; if(createEvent.isCancelled()) return;
@ -83,7 +79,7 @@ public class CmdFactionsCreate extends FCommand
faction.setTag(tag); faction.setTag(tag);
// trigger the faction join event for the creator // 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); Bukkit.getServer().getPluginManager().callEvent(joinEvent);
// join event cannot be cancelled or you'll have an empty faction // join event cannot be cancelled or you'll have an empty faction

View File

@ -17,7 +17,6 @@ public class CmdFactionsDeinvite extends FCommand
this.permission = Perm.DEINVITE.node; this.permission = Perm.DEINVITE.node;
senderMustBePlayer = true;
senderMustBeMember = false; senderMustBeMember = false;
senderMustBeOfficer = true; senderMustBeOfficer = true;
senderMustBeLeader = false; senderMustBeLeader = false;

View File

@ -20,10 +20,6 @@ public class CmdFactionsDemote extends FCommand
//To demote someone from member -> recruit you must be an officer. //To demote someone from member -> recruit you must be an officer.
//To demote someone from officer -> member you must be a leader. //To demote someone from officer -> member you must be a leader.
//We'll handle this internally //We'll handle this internally
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeOfficer = false;
senderMustBeLeader = false;
} }
@Override @Override

View File

@ -19,10 +19,7 @@ public class CmdFactionsDescription extends FCommand
this.permission = Perm.DESCRIPTION.node; this.permission = Perm.DESCRIPTION.node;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeOfficer = true; senderMustBeOfficer = true;
senderMustBeLeader = false;
} }
@Override @Override

View File

@ -26,11 +26,6 @@ public class CmdFactionsDisband extends FCommand
this.optionalArgs.put("faction", "your"); this.optionalArgs.put("faction", "your");
this.permission = Perm.DISBAND.node; this.permission = Perm.DISBAND.node;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeOfficer = false;
senderMustBeLeader = false;
} }
@Override @Override

View File

@ -19,11 +19,6 @@ public class CmdFactionsFlag extends FCommand
this.optionalArgs.put("yes/no", "read"); this.optionalArgs.put("yes/no", "read");
this.permission = Perm.FLAG.node; this.permission = Perm.FLAG.node;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeOfficer = false;
senderMustBeLeader = false;
} }
@Override @Override

View File

@ -16,6 +16,7 @@ import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel; import com.massivecraft.factions.Rel;
import com.massivecraft.factions.integration.EssentialsFeatures; import com.massivecraft.factions.integration.EssentialsFeatures;
import com.massivecraft.mcore.cmd.req.ReqIsPlayer;
import com.massivecraft.mcore.ps.PS; import com.massivecraft.mcore.ps.PS;
import com.massivecraft.mcore.util.SmokeUtil; import com.massivecraft.mcore.util.SmokeUtil;
@ -33,10 +34,9 @@ public class CmdFactionsHome extends FCommand
this.permission = Perm.HOME.node; this.permission = Perm.HOME.node;
senderMustBePlayer = true; this.addRequirements(ReqIsPlayer.get());
senderMustBeMember = true; senderMustBeMember = true;
senderMustBeOfficer = false;
senderMustBeLeader = false;
} }
@Override @Override

View File

@ -4,6 +4,7 @@ import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.FPerm; import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.mcore.cmd.req.ReqIsPlayer;
public class CmdFactionsInvite extends FCommand public class CmdFactionsInvite extends FCommand
{ {
@ -18,10 +19,10 @@ public class CmdFactionsInvite extends FCommand
this.permission = Perm.INVITE.node; this.permission = Perm.INVITE.node;
senderMustBePlayer = true;
senderMustBeMember = false; this.addRequirements(ReqIsPlayer.get());
senderMustBeOfficer = true; senderMustBeOfficer = true;
senderMustBeLeader = false;
} }
@Override @Override

View File

@ -21,11 +21,6 @@ public class CmdFactionsJoin extends FCommand
this.optionalArgs.put("player", "you"); this.optionalArgs.put("player", "you");
this.permission = Perm.JOIN.node; this.permission = Perm.JOIN.node;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeOfficer = false;
senderMustBeLeader = false;
} }
@Override @Override

View File

@ -23,11 +23,6 @@ public class CmdFactionsKick extends FCommand
//this.optionalArgs.put("", ""); //this.optionalArgs.put("", "");
this.permission = Perm.KICK.node; this.permission = Perm.KICK.node;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeOfficer = false;
senderMustBeLeader = false;
} }
@Override @Override

View File

@ -22,11 +22,6 @@ public class CmdFactionsLeader extends FCommand
this.optionalArgs.put("faction", "your"); this.optionalArgs.put("faction", "your");
this.permission = Perm.LEADER.node; this.permission = Perm.LEADER.node;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeOfficer = false;
senderMustBeLeader = false;
} }
@Override @Override

View File

@ -14,10 +14,7 @@ public class CmdFactionsLeave extends FCommand {
this.permission = Perm.LEAVE.node; this.permission = Perm.LEAVE.node;
senderMustBePlayer = true;
senderMustBeMember = true; senderMustBeMember = true;
senderMustBeOfficer = false;
senderMustBeLeader = false;
} }
@Override @Override

View File

@ -24,11 +24,6 @@ public class CmdFactionsList extends FCommand
this.optionalArgs.put("page", "1"); this.optionalArgs.put("page", "1");
this.permission = Perm.LIST.node; this.permission = Perm.LIST.node;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeOfficer = false;
senderMustBeLeader = false;
} }
@Override @Override

View File

@ -3,6 +3,7 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.BoardColl; import com.massivecraft.factions.BoardColl;
import com.massivecraft.factions.ConfServer; import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.mcore.cmd.req.ReqIsPlayer;
import com.massivecraft.mcore.ps.PS; import com.massivecraft.mcore.ps.PS;
@ -18,10 +19,7 @@ public class CmdFactionsMap extends FCommand
this.permission = Perm.MAP.node; this.permission = Perm.MAP.node;
senderMustBePlayer = true; this.addRequirements(ReqIsPlayer.get());
senderMustBeMember = false;
senderMustBeOfficer = false;
senderMustBeLeader = false;
} }
@Override @Override

View File

@ -17,11 +17,6 @@ public class CmdFactionsOfficer extends FCommand
//this.optionalArgs.put("", ""); //this.optionalArgs.put("", "");
this.permission = Perm.OFFICER.node; this.permission = Perm.OFFICER.node;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeOfficer = false;
senderMustBeLeader = false;
} }
@Override @Override

View File

@ -17,10 +17,7 @@ public class CmdFactionsOpen extends FCommand
this.permission = Perm.OPEN.node; this.permission = Perm.OPEN.node;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeOfficer = true; senderMustBeOfficer = true;
senderMustBeLeader = false;
} }
@Override @Override

View File

@ -22,11 +22,6 @@ public class CmdFactionsPerm extends FCommand
this.permission = Perm.PERM.node; this.permission = Perm.PERM.node;
this.errorOnToManyArgs = false; this.errorOnToManyArgs = false;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeOfficer = false;
senderMustBeLeader = false;
} }
@Override @Override

View File

@ -17,11 +17,6 @@ public class CmdFactionsPower extends FCommand
this.optionalArgs.put("player", "you"); this.optionalArgs.put("player", "you");
this.permission = Perm.POWER.node; this.permission = Perm.POWER.node;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeOfficer = false;
senderMustBeLeader = false;
} }
@Override @Override

View File

@ -17,11 +17,6 @@ public class CmdFactionsPowerBoost extends FCommand
this.requiredArgs.add("#"); this.requiredArgs.add("#");
this.permission = Perm.POWERBOOST.node; this.permission = Perm.POWERBOOST.node;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeOfficer = false;
senderMustBeLeader = false;
} }
@Override @Override

View File

@ -20,10 +20,6 @@ public class CmdFactionsPromote extends FCommand
//To promote someone from recruit -> member you must be an officer. //To promote someone from recruit -> member you must be an officer.
//To promote someone from member -> officer you must be a leader. //To promote someone from member -> officer you must be a leader.
//We'll handle this internally //We'll handle this internally
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeOfficer = false;
senderMustBeLeader = false;
} }
@Override @Override

View File

@ -9,6 +9,7 @@ import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel; import com.massivecraft.factions.Rel;
import com.massivecraft.factions.event.FactionRelationEvent; import com.massivecraft.factions.event.FactionRelationEvent;
import com.massivecraft.factions.integration.SpoutFeatures; import com.massivecraft.factions.integration.SpoutFeatures;
import com.massivecraft.mcore.cmd.req.ReqIsPlayer;
public abstract class CmdFactionsRelationAbstract extends FCommand public abstract class CmdFactionsRelationAbstract extends FCommand
{ {
@ -22,10 +23,7 @@ public abstract class CmdFactionsRelationAbstract extends FCommand
this.permission = Perm.RELATION.node; this.permission = Perm.RELATION.node;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeOfficer = true; senderMustBeOfficer = true;
senderMustBeLeader = false;
} }
@Override @Override

View File

@ -7,6 +7,7 @@ import org.bukkit.entity.Player;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.util.VisualizeUtil; import com.massivecraft.factions.util.VisualizeUtil;
import com.massivecraft.mcore.cmd.req.ReqIsPlayer;
public class CmdFactionsSeeChunk extends FCommand public class CmdFactionsSeeChunk extends FCommand
{ {
@ -18,10 +19,7 @@ public class CmdFactionsSeeChunk extends FCommand
this.permission = Perm.SEE_CHUNK.node; this.permission = Perm.SEE_CHUNK.node;
senderMustBePlayer = true; this.addRequirements(ReqIsPlayer.get());
senderMustBeMember = false;
senderMustBeOfficer = false;
senderMustBeLeader = false;
} }
@Override @Override

View File

@ -5,6 +5,7 @@ import com.massivecraft.factions.ConfServer;
import com.massivecraft.factions.FPerm; import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.mcore.cmd.req.ReqIsPlayer;
import com.massivecraft.mcore.ps.PS; import com.massivecraft.mcore.ps.PS;
public class CmdFactionsSethome extends FCommand public class CmdFactionsSethome extends FCommand
@ -18,10 +19,7 @@ public class CmdFactionsSethome extends FCommand
this.permission = Perm.SETHOME.node; this.permission = Perm.SETHOME.node;
senderMustBePlayer = true; this.addRequirements(ReqIsPlayer.get());
senderMustBeMember = false;
senderMustBeOfficer = false;
senderMustBeLeader = false;
} }
@Override @Override

View File

@ -26,11 +26,6 @@ public class CmdFactionsShow extends FCommand
this.optionalArgs.put("faction", "your"); this.optionalArgs.put("faction", "your");
this.permission = Perm.SHOW.node; this.permission = Perm.SHOW.node;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeOfficer = false;
senderMustBeLeader = false;
} }
@Override @Override

View File

@ -24,10 +24,7 @@ public class CmdFactionsTag extends FCommand
this.permission = Perm.TAG.node; this.permission = Perm.TAG.node;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeOfficer = true; senderMustBeOfficer = true;
senderMustBeLeader = false;
} }
@Override @Override

View File

@ -17,10 +17,7 @@ public class CmdFactionsTitle extends FCommand
this.permission = Perm.TITLE.node; this.permission = Perm.TITLE.node;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeOfficer = true; senderMustBeOfficer = true;
senderMustBeLeader = false;
} }
@Override @Override

View File

@ -11,6 +11,7 @@ import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.mcore.cmd.req.ReqIsPlayer;
import com.massivecraft.mcore.ps.PS; import com.massivecraft.mcore.ps.PS;
public class CmdFactionsUnclaim extends FCommand public class CmdFactionsUnclaim extends FCommand
@ -25,10 +26,7 @@ public class CmdFactionsUnclaim extends FCommand
this.permission = Perm.UNCLAIM.node; this.permission = Perm.UNCLAIM.node;
senderMustBePlayer = true; this.addRequirements(ReqIsPlayer.get());
senderMustBeMember = false;
senderMustBeOfficer = false;
senderMustBeLeader = false;
} }
@Override @Override

View File

@ -22,10 +22,7 @@ public class CmdFactionsUnclaimall extends FCommand
this.permission = Perm.UNCLAIM_ALL.node; this.permission = Perm.UNCLAIM_ALL.node;
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeOfficer = true; senderMustBeOfficer = true;
senderMustBeLeader = false;
} }
@Override @Override

View File

@ -10,15 +10,7 @@ public class CmdFactionsVersion extends FCommand
{ {
this.aliases.add("version"); this.aliases.add("version");
//this.requiredArgs.add("");
//this.optionalArgs.put("", "");
this.permission = Perm.VERSION.node; this.permission = Perm.VERSION.node;
senderMustBePlayer = false;
senderMustBeMember = false;
senderMustBeOfficer = false;
senderMustBeLeader = false;
} }
@Override @Override

View File

@ -1,443 +1,19 @@
package com.massivecraft.factions.cmd; 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.FPlayer;
import com.massivecraft.factions.FPlayerColl; import com.massivecraft.factions.FPlayerColl;
import com.massivecraft.factions.Faction; import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FactionColl; import com.massivecraft.mcore.cmd.MCommand;
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 FCommand extends MCommand
public abstract class FCommand extends MCommand<Factions>
{ {
public FPlayer fme; public FPlayer fme;
public Faction myFaction; 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 @Override
public void execute(CommandSender sender, List<String> args, List<MCommand<?>> commandChain) public void fixSenderVars()
{ {
if (sender instanceof Player) this.fme = FPlayerColl.get().get(this.sender);
{ this.myFaction = this.fme.getFaction();
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("<b>Faction economy features are disabled on this server.");
return false;
}
if (this.isMoneyCommand && ! ConfServer.bankEnabled)
{
msg("<b>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("<b>You are not member of any faction."));
return false;
}
if (this.senderMustBeOfficer && ! fplayer.getRole().isAtLeast(Rel.OFFICER))
{
sender.sendMessage(Txt.parse("<b>Only faction moderators can %s.", this.getHelpShort()));
return false;
}
if (this.senderMustBeLeader && ! fplayer.getRole().isAtLeast(Rel.LEADER))
{
sender.sendMessage(Txt.parse("<b>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("<b>You <h>must be "+role+"<b> 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("<b>No player \"<p>%s<b>\" 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("<b>No player match found for \"<p>%s<b>\".", 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("<b>The faction or player \"<p>%s<b>\" 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("<b>The faction-flag \"<p>%s<b>\" 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("<b>The faction-perm \"<p>%s<b>\" 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("<b>The role \"<p>%s<b>\" 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 <b>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("<b>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("<b>Moderators can't control each other..."));
}
}
else
{
i.sendMessage(Txt.parse("<b>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);
} }
} }

View File

@ -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<Factions>
{
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<String> args, List<MCommand<?>> 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("<b>Faction economy features are disabled on this server.");
return false;
}
if (this.isMoneyCommand && ! ConfServer.bankEnabled)
{
msg("<b>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("<b>You are not member of any faction."));
return false;
}
if (this.senderMustBeOfficer && ! fplayer.getRole().isAtLeast(Rel.OFFICER))
{
sender.sendMessage(Txt.parse("<b>Only faction moderators can %s.", this.getHelpShort()));
return false;
}
if (this.senderMustBeLeader && ! fplayer.getRole().isAtLeast(Rel.LEADER))
{
sender.sendMessage(Txt.parse("<b>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("<b>You <h>must be "+role+"<b> 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("<b>No player \"<p>%s<b>\" 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("<b>No player match found for \"<p>%s<b>\".", 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("<b>The faction or player \"<p>%s<b>\" 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("<b>The faction-flag \"<p>%s<b>\" 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("<b>The faction-perm \"<p>%s<b>\" 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("<b>The role \"<p>%s<b>\" 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 <b>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("<b>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("<b>Moderators can't control each other..."));
}
}
else
{
i.sendMessage(Txt.parse("<b>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);
}
}