2011-10-23 23:17:02 +02:00
|
|
|
package com.massivecraft.factions.cmd;
|
|
|
|
|
|
|
|
import com.massivecraft.factions.Faction;
|
2013-04-09 12:56:29 +02:00
|
|
|
import com.massivecraft.factions.Perm;
|
2011-10-24 01:37:51 +02:00
|
|
|
import com.massivecraft.factions.struct.FPerm;
|
2011-10-23 23:17:02 +02:00
|
|
|
import com.massivecraft.factions.struct.Rel;
|
|
|
|
|
|
|
|
public class CmdPerm extends FCommand
|
|
|
|
{
|
|
|
|
|
|
|
|
public CmdPerm()
|
|
|
|
{
|
|
|
|
super();
|
|
|
|
this.aliases.add("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");
|
2011-10-23 23:17:02 +02:00
|
|
|
|
2013-04-09 12:56:29 +02:00
|
|
|
this.permission = Perm.PERM.node;
|
2011-10-23 23:17:02 +02:00
|
|
|
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;
|
|
|
|
|
|
|
|
if ( ! this.argIsSet(1))
|
|
|
|
{
|
2011-10-24 11:56:41 +02:00
|
|
|
msg(p.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-23 23:17:02 +02:00
|
|
|
{
|
2011-10-24 01:37:51 +02:00
|
|
|
msg(perm.getStateInfo(faction.getPermittedRelations(perm), true));
|
2011-10-23 23:17:02 +02:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-10-24 01:37:51 +02:00
|
|
|
FPerm perm = this.argAsFactionPerm(1);
|
2011-10-23 23:17:02 +02:00
|
|
|
if (perm == null) return;
|
|
|
|
if ( ! this.argIsSet(2))
|
|
|
|
{
|
2011-10-24 11:56:41 +02:00
|
|
|
msg(p.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));
|
2011-10-23 23:17:02 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do the sender have the right to change perms for this faction?
|
2011-10-25 21:18:08 +02:00
|
|
|
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;
|
|
|
|
|
2011-10-25 21:18:08 +02:00
|
|
|
// Do the change
|
2012-05-09 06:29:52 +02:00
|
|
|
faction.setRelationPermitted(perm, rel, val);
|
2011-10-25 21:18:08 +02:00
|
|
|
|
|
|
|
// 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))
|
2011-10-23 23:17:02 +02:00
|
|
|
{
|
2012-05-09 06:29:52 +02:00
|
|
|
faction.setRelationPermitted(FPerm.PERMS, Rel.LEADER, true);
|
2011-10-23 23:17:02 +02:00
|
|
|
}
|
|
|
|
|
2011-10-24 11:56:41 +02:00
|
|
|
msg(p.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));
|
2011-10-23 23:17:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|