Simplified the perm command.
This commit is contained in:
parent
a0a163056d
commit
5988e8e5af
@ -136,6 +136,7 @@ public class Faction extends Entity implements EconomyParticipator
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
public void addPermittedRelation(FPerm perm, Rel rel)
|
public void addPermittedRelation(FPerm perm, Rel rel)
|
||||||
{
|
{
|
||||||
Set<Rel> newPermittedRelations = EnumSet.noneOf(Rel.class);
|
Set<Rel> newPermittedRelations = EnumSet.noneOf(Rel.class);
|
||||||
@ -150,6 +151,21 @@ public class Faction extends Entity implements EconomyParticipator
|
|||||||
newPermittedRelations.addAll(this.getPermittedRelations(perm));
|
newPermittedRelations.addAll(this.getPermittedRelations(perm));
|
||||||
newPermittedRelations.remove(rel);
|
newPermittedRelations.remove(rel);
|
||||||
this.setPermittedRelations(perm, newPermittedRelations);
|
this.setPermittedRelations(perm, newPermittedRelations);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
public void setRelationPermitted(FPerm perm, Rel rel, boolean permitted)
|
||||||
|
{
|
||||||
|
Set<Rel> newPermittedRelations = EnumSet.noneOf(Rel.class);
|
||||||
|
newPermittedRelations.addAll(this.getPermittedRelations(perm));
|
||||||
|
if (permitted)
|
||||||
|
{
|
||||||
|
newPermittedRelations.add(rel);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
newPermittedRelations.remove(rel);
|
||||||
|
}
|
||||||
|
this.setPermittedRelations(perm, newPermittedRelations);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPermittedRelations(FPerm perm, Set<Rel> rels)
|
public void setPermittedRelations(FPerm perm, Set<Rel> rels)
|
||||||
|
@ -15,7 +15,7 @@ public class CmdFlag extends FCommand
|
|||||||
//this.requiredArgs.add("");
|
//this.requiredArgs.add("");
|
||||||
this.optionalArgs.put("faction", "your");
|
this.optionalArgs.put("faction", "your");
|
||||||
this.optionalArgs.put("flag", "all");
|
this.optionalArgs.put("flag", "all");
|
||||||
this.optionalArgs.put("on/off", "read");
|
this.optionalArgs.put("yes/no", "read");
|
||||||
|
|
||||||
this.permission = Permission.FLAG.node;
|
this.permission = Permission.FLAG.node;
|
||||||
this.disableOnLock = true;
|
this.disableOnLock = true;
|
||||||
|
@ -1,12 +1,9 @@
|
|||||||
package com.massivecraft.factions.cmd;
|
package com.massivecraft.factions.cmd;
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import com.massivecraft.factions.Faction;
|
import com.massivecraft.factions.Faction;
|
||||||
import com.massivecraft.factions.struct.FPerm;
|
import com.massivecraft.factions.struct.FPerm;
|
||||||
import com.massivecraft.factions.struct.Permission;
|
import com.massivecraft.factions.struct.Permission;
|
||||||
import com.massivecraft.factions.struct.Rel;
|
import com.massivecraft.factions.struct.Rel;
|
||||||
import com.massivecraft.factions.zcore.util.TextUtil;
|
|
||||||
|
|
||||||
public class CmdPerm extends FCommand
|
public class CmdPerm extends FCommand
|
||||||
{
|
{
|
||||||
@ -16,10 +13,10 @@ public class CmdPerm extends FCommand
|
|||||||
super();
|
super();
|
||||||
this.aliases.add("perm");
|
this.aliases.add("perm");
|
||||||
|
|
||||||
//this.requiredArgs.add("");
|
|
||||||
this.optionalArgs.put("faction", "your");
|
this.optionalArgs.put("faction", "your");
|
||||||
this.optionalArgs.put("perm", "all");
|
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.permission = Permission.PERM.node;
|
||||||
this.disableOnLock = true;
|
this.disableOnLock = true;
|
||||||
@ -66,17 +63,21 @@ public class CmdPerm extends FCommand
|
|||||||
// Do the sender have the right to change perms for this faction?
|
// Do the sender have the right to change perms for this faction?
|
||||||
if ( ! FPerm.PERMS.has(sender, faction, true)) return;
|
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
|
// 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.
|
// 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))
|
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(p.txt.titleize("Perm for " + faction.describeTo(fme, true)));
|
||||||
msg(FPerm.getStateHeaders());
|
msg(FPerm.getStateHeaders());
|
||||||
msg(perm.getStateInfo(faction.getPermittedRelations(perm), true));
|
msg(perm.getStateInfo(faction.getPermittedRelations(perm), true));
|
||||||
|
@ -343,6 +343,39 @@ public abstract class FCommand extends MCommand<P>
|
|||||||
return this.argAsFactionPerm(idx, null);
|
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
|
// Commonly used logic
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
package com.massivecraft.factions.struct;
|
package com.massivecraft.factions.struct;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -128,41 +126,6 @@ public enum FPerm
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Set<Rel> parseRelDeltas(String str, Set<Rel> current)
|
|
||||||
{
|
|
||||||
Set<Rel> ret = new HashSet<Rel>();
|
|
||||||
ret.addAll(current);
|
|
||||||
|
|
||||||
List<String> nodes = new ArrayList<String>(Arrays.asList(str.split("\\s+")));
|
|
||||||
|
|
||||||
for (String node : nodes)
|
|
||||||
{
|
|
||||||
boolean add = true;
|
|
||||||
if (node.startsWith("-"))
|
|
||||||
{
|
|
||||||
add = false;
|
|
||||||
node = node.substring(1);
|
|
||||||
}
|
|
||||||
else if (node.startsWith("+"))
|
|
||||||
{
|
|
||||||
node = node.substring(1);
|
|
||||||
}
|
|
||||||
Rel rel = Rel.parse(node);
|
|
||||||
|
|
||||||
if (rel == null) continue;
|
|
||||||
|
|
||||||
if (add)
|
|
||||||
{
|
|
||||||
ret.add(rel);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ret.remove(rel);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final String errorpattern = "%s<b> does not allow you to %s<b>.";
|
private static final String errorpattern = "%s<b> does not allow you to %s<b>.";
|
||||||
public boolean has(Object testSubject, Faction hostFaction, boolean informIfNot)
|
public boolean has(Object testSubject, Faction hostFaction, boolean informIfNot)
|
||||||
{
|
{
|
||||||
|
@ -388,7 +388,7 @@ public abstract class MCommand<T extends MPlugin>
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
public Boolean argAsBool(int idx, boolean def)
|
public Boolean argAsBool(int idx, Boolean def)
|
||||||
{
|
{
|
||||||
String str = this.argAsString(idx);
|
String str = this.argAsString(idx);
|
||||||
if (str == null) return def;
|
if (str == null) return def;
|
||||||
|
Loading…
Reference in New Issue
Block a user