Factions/src/com/massivecraft/factions/cmd/CmdFactionsPerm.java

84 lines
2.2 KiB
Java
Raw Normal View History

package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPerm;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel;
2013-04-16 10:11:59 +02:00
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
2013-04-10 10:32:04 +02:00
import com.massivecraft.mcore.util.Txt;
2013-04-10 13:12:22 +02:00
public class CmdFactionsPerm extends FCommand
{
2013-04-10 13:12:22 +02:00
public CmdFactionsPerm()
{
super();
2013-04-16 10:11:59 +02:00
this.addAliases("perm");
this.optionalArgs.put("faction", "your");
this.optionalArgs.put("perm", "all");
2012-05-09 06:29:52 +02:00
this.optionalArgs.put("relation", "read");
this.optionalArgs.put("yes/no", "read");
2013-04-16 10:11:59 +02:00
this.addRequirements(ReqHasPerm.get(Perm.PERM.node));
this.errorOnToManyArgs = false;
}
@Override
public void perform()
{
Faction faction = myFaction;
if (this.argIsSet(0))
{
faction = this.argAsFaction(0);
}
if (faction == null) return;
if ( ! this.argIsSet(1))
{
2013-04-10 10:32:04 +02:00
msg(Txt.titleize("Perms for " + faction.describeTo(fme, true)));
msg(FPerm.getStateHeaders());
2011-10-24 01:37:51 +02:00
for (FPerm perm : FPerm.values())
{
2011-10-24 01:37:51 +02:00
msg(perm.getStateInfo(faction.getPermittedRelations(perm), true));
}
return;
}
2011-10-24 01:37:51 +02:00
FPerm perm = this.argAsFactionPerm(1);
if (perm == null) return;
if ( ! this.argIsSet(2))
{
2013-04-10 10:32:04 +02:00
msg(Txt.titleize("Perm for " + faction.describeTo(fme, true)));
msg(FPerm.getStateHeaders());
2011-10-24 01:37:51 +02:00
msg(perm.getStateInfo(faction.getPermittedRelations(perm), true));
return;
}
// Do the sender have the right to change perms for this faction?
if ( ! FPerm.PERMS.has(sender, faction, true)) return;
2012-05-09 06:29:52 +02:00
Rel rel = this.argAsRel(2);
if (rel == null) return;
Boolean val = this.argAsBool(3, null);
if (val == null) return;
// Do the change
2012-05-09 06:29:52 +02:00
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))
{
2012-05-09 06:29:52 +02:00
faction.setRelationPermitted(FPerm.PERMS, Rel.LEADER, true);
}
2013-04-10 10:32:04 +02:00
msg(Txt.titleize("Perm for " + faction.describeTo(fme, true)));
msg(FPerm.getStateHeaders());
2011-10-24 01:37:51 +02:00
msg(perm.getStateInfo(faction.getPermittedRelations(perm), true));
}
}