Working on the faction perms as well now
This commit is contained in:
88
src/com/massivecraft/factions/cmd/CmdPerm.java
Normal file
88
src/com/massivecraft/factions/cmd/CmdPerm.java
Normal file
@ -0,0 +1,88 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.struct.FactionPerm;
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
import com.massivecraft.factions.struct.Rel;
|
||||
import com.massivecraft.factions.zcore.util.TextUtil;
|
||||
|
||||
public class CmdPerm extends FCommand
|
||||
{
|
||||
|
||||
public CmdPerm()
|
||||
{
|
||||
super();
|
||||
this.aliases.add("perm");
|
||||
|
||||
//this.requiredArgs.add("");
|
||||
this.optionalArgs.put("faction", "your");
|
||||
this.optionalArgs.put("perm", "all");
|
||||
this.optionalArgs.put("relationdelta", "read");
|
||||
|
||||
this.permission = Permission.PERM.node;
|
||||
this.disableOnLock = true;
|
||||
|
||||
this.errorOnToManyArgs = false;
|
||||
|
||||
senderMustBePlayer = false;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeOfficer = false;
|
||||
senderMustBeLeader = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
Faction faction = myFaction;
|
||||
if (this.argIsSet(0))
|
||||
{
|
||||
faction = this.argAsFaction(0);
|
||||
}
|
||||
if (faction == null) return;
|
||||
|
||||
msg(p.txt.titleize("Perm(s) for " + faction.describeTo(fme)));
|
||||
|
||||
if ( ! this.argIsSet(1))
|
||||
{
|
||||
for (FactionPerm perm : FactionPerm.values())
|
||||
{
|
||||
msg(perm.getStateInfo(faction.getPerm(perm), true));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
FactionPerm perm = this.argAsFactionPerm(1);
|
||||
if (perm == null) return;
|
||||
if ( ! this.argIsSet(2))
|
||||
{
|
||||
msg(perm.getStateInfo(faction.getPerm(perm), true));
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Awesomesause parser for deltas...
|
||||
Set<Rel> targetValue = FactionPerm.parseRelDeltas(TextUtil.implode(args.subList(2, args.size()-1), " "), faction.getPerm(perm));
|
||||
|
||||
// Do the sender have the right to change perms for this faction?
|
||||
if (Permission.PERM_ANY.has(sender))
|
||||
{
|
||||
// This sender may modify any perm for anyone
|
||||
}
|
||||
else if (faction != myFaction)
|
||||
{
|
||||
msg("<b>You are not a member in that faction.");
|
||||
return;
|
||||
}
|
||||
else if (fme.getRole().isLessThan(Rel.OFFICER))
|
||||
{
|
||||
msg("<b>You must be faction leader or officer to change your faction permissions.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Do the change
|
||||
faction.setPerm(perm, targetValue);
|
||||
msg(perm.getStateInfo(faction.getPerm(perm), true));
|
||||
}
|
||||
|
||||
}
|
@ -31,6 +31,7 @@ public class FCmdRoot extends FCommand
|
||||
public CmdOpen cmdOpen = new CmdOpen();
|
||||
public CmdOwner cmdOwner = new CmdOwner();
|
||||
public CmdOwnerList cmdOwnerList = new CmdOwnerList();
|
||||
public CmdPerm cmdPerm = new CmdPerm();
|
||||
public CmdPower cmdPower = new CmdPower();
|
||||
public CmdRelationAlly cmdRelationAlly = new CmdRelationAlly();
|
||||
public CmdRelationEnemy cmdRelationEnemy = new CmdRelationEnemy();
|
||||
@ -93,6 +94,7 @@ public class FCmdRoot extends FCommand
|
||||
this.addSubCommand(this.cmdOpen);
|
||||
this.addSubCommand(this.cmdOwner);
|
||||
this.addSubCommand(this.cmdOwnerList);
|
||||
this.addSubCommand(this.cmdPerm);
|
||||
this.addSubCommand(this.cmdPower);
|
||||
this.addSubCommand(this.cmdRelationAlly);
|
||||
this.addSubCommand(this.cmdRelationEnemy);
|
||||
|
@ -13,6 +13,7 @@ import com.massivecraft.factions.Faction;
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.P;
|
||||
import com.massivecraft.factions.struct.FactionFlag;
|
||||
import com.massivecraft.factions.struct.FactionPerm;
|
||||
import com.massivecraft.factions.struct.Rel;
|
||||
import com.massivecraft.factions.zcore.MCommand;
|
||||
|
||||
@ -308,6 +309,40 @@ public abstract class FCommand extends MCommand<P>
|
||||
return this.argAsFactionFlag(idx, null);
|
||||
}
|
||||
|
||||
// FACTION PERM ======================
|
||||
public FactionPerm strAsFactionPerm(String name, FactionPerm def, boolean msg)
|
||||
{
|
||||
FactionPerm ret = def;
|
||||
|
||||
if (name != null)
|
||||
{
|
||||
FactionPerm perm = FactionPerm.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 FactionPerm argAsFactionPerm(int idx, FactionPerm def, boolean msg)
|
||||
{
|
||||
return this.strAsFactionPerm(this.argAsString(idx), def, msg);
|
||||
}
|
||||
public FactionPerm argAsFactionPerm(int idx, FactionPerm def)
|
||||
{
|
||||
return this.argAsFactionPerm(idx, def, true);
|
||||
}
|
||||
public FactionPerm argAsFactionPerm(int idx)
|
||||
{
|
||||
return this.argAsFactionPerm(idx, null);
|
||||
}
|
||||
|
||||
|
||||
// -------------------------------------------- //
|
||||
// Commonly used logic
|
||||
|
Reference in New Issue
Block a user