2011-10-23 23:17:02 +02:00
|
|
|
package com.massivecraft.factions.cmd;
|
|
|
|
|
2013-04-09 13:24:55 +02:00
|
|
|
import com.massivecraft.factions.FPerm;
|
2013-04-09 12:56:29 +02:00
|
|
|
import com.massivecraft.factions.Perm;
|
2013-04-09 13:24:55 +02:00
|
|
|
import com.massivecraft.factions.Rel;
|
2013-04-16 11:27:03 +02:00
|
|
|
import com.massivecraft.factions.cmd.arg.ARFPerm;
|
2013-04-16 11:05:49 +02:00
|
|
|
import com.massivecraft.factions.cmd.arg.ARFaction;
|
2013-04-16 11:27:03 +02:00
|
|
|
import com.massivecraft.factions.cmd.arg.ARRel;
|
2013-04-22 09:37:53 +02:00
|
|
|
import com.massivecraft.factions.entity.Faction;
|
2013-04-16 11:27:03 +02:00
|
|
|
import com.massivecraft.mcore.cmd.arg.ARBoolean;
|
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;
|
2011-10-23 23:17:02 +02:00
|
|
|
|
2013-04-10 13:12:22 +02:00
|
|
|
public class CmdFactionsPerm extends FCommand
|
2011-10-23 23:17:02 +02:00
|
|
|
{
|
2013-04-10 13:12:22 +02:00
|
|
|
public CmdFactionsPerm()
|
2011-10-23 23:17:02 +02:00
|
|
|
{
|
2013-04-16 10:11:59 +02:00
|
|
|
this.addAliases("perm");
|
2011-10-23 23:17:02 +02:00
|
|
|
|
2013-04-16 11:05:49 +02:00
|
|
|
this.addOptionalArg("faction", "you");
|
2013-04-16 10:30:21 +02:00
|
|
|
this.addOptionalArg("perm", "all");
|
|
|
|
this.addOptionalArg("relation", "read");
|
|
|
|
this.addOptionalArg("yes/no", "read");
|
|
|
|
this.setErrorOnToManyArgs(false);
|
2011-10-23 23:17:02 +02:00
|
|
|
|
2013-04-16 10:11:59 +02:00
|
|
|
this.addRequirements(ReqHasPerm.get(Perm.PERM.node));
|
2011-10-23 23:17:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void perform()
|
|
|
|
{
|
2013-04-16 11:05:49 +02:00
|
|
|
Faction faction = this.arg(0, ARFaction.get(), myFaction);
|
2011-10-23 23:17:02 +02:00
|
|
|
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)));
|
2011-10-24 11:56:41 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-04-16 11:27:03 +02:00
|
|
|
FPerm perm = this.arg(1, ARFPerm.get());
|
2011-10-23 23:17:02 +02:00
|
|
|
if (perm == null) return;
|
2013-04-16 11:27:03 +02:00
|
|
|
|
2011-10-23 23:17:02 +02:00
|
|
|
if ( ! this.argIsSet(2))
|
|
|
|
{
|
2013-04-10 10:32:04 +02:00
|
|
|
msg(Txt.titleize("Perm for " + faction.describeTo(fme, true)));
|
2011-10-24 11:56:41 +02:00
|
|
|
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;
|
|
|
|
|
2013-04-16 11:27:03 +02:00
|
|
|
Rel rel = this.arg(2, ARRel.get());
|
2012-05-09 06:29:52 +02:00
|
|
|
if (rel == null) return;
|
|
|
|
|
2013-04-16 11:27:03 +02:00
|
|
|
Boolean val = this.arg(3, ARBoolean.get(), null);
|
2012-05-09 06:29:52 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-04-10 10:32:04 +02:00
|
|
|
msg(Txt.titleize("Perm for " + faction.describeTo(fme, true)));
|
2011-10-24 11:56:41 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
}
|