Simplified the perm command.

This commit is contained in:
Olof Larsson
2012-05-09 06:29:52 +02:00
parent a0a163056d
commit 5988e8e5af
6 changed files with 61 additions and 48 deletions

View File

@ -15,7 +15,7 @@ public class CmdFlag extends FCommand
//this.requiredArgs.add("");
this.optionalArgs.put("faction", "your");
this.optionalArgs.put("flag", "all");
this.optionalArgs.put("on/off", "read");
this.optionalArgs.put("yes/no", "read");
this.permission = Permission.FLAG.node;
this.disableOnLock = true;

View File

@ -1,12 +1,9 @@
package com.massivecraft.factions.cmd;
import java.util.Set;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.struct.FPerm;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Rel;
import com.massivecraft.factions.zcore.util.TextUtil;
public class CmdPerm extends FCommand
{
@ -16,10 +13,10 @@ public class CmdPerm extends FCommand
super();
this.aliases.add("perm");
//this.requiredArgs.add("");
this.optionalArgs.put("faction", "your");
this.optionalArgs.put("perm", "all");
this.optionalArgs.put("relationdelta", "read");
this.optionalArgs.put("relation", "read");
this.optionalArgs.put("yes/no", "read");
this.permission = Permission.PERM.node;
this.disableOnLock = true;
@ -66,17 +63,21 @@ public class CmdPerm extends FCommand
// Do the sender have the right to change perms for this faction?
if ( ! FPerm.PERMS.has(sender, faction, true)) return;
Rel rel = this.argAsRel(2);
if (rel == null) return;
Boolean val = this.argAsBool(3, null);
if (val == null) return;
// Do the change
Set<Rel> targetValue = FPerm.parseRelDeltas(TextUtil.implode(args.subList(2, args.size()), " "), faction.getPermittedRelations(perm));
faction.setRelationPermitted(perm, rel, val);
// The following is to make sure the leader always has the right to change perms if that is our goal.
if (perm == FPerm.PERMS && FPerm.PERMS.getDefault().contains(Rel.LEADER))
{
targetValue.add(Rel.LEADER);
faction.setRelationPermitted(FPerm.PERMS, Rel.LEADER, true);
}
faction.setPermittedRelations(perm, targetValue);
msg(p.txt.titleize("Perm for " + faction.describeTo(fme, true)));
msg(FPerm.getStateHeaders());
msg(perm.getStateInfo(faction.getPermittedRelations(perm), true));

View File

@ -343,6 +343,39 @@ public abstract class FCommand extends MCommand<P>
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