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

112 lines
3.3 KiB
Java
Raw Normal View History

package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel;
import com.massivecraft.factions.cmd.arg.ARMPerm;
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;
import com.massivecraft.factions.entity.MPerm;
2014-06-04 14:02:23 +02:00
import com.massivecraft.massivecore.cmd.arg.ARBoolean;
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
import com.massivecraft.massivecore.util.Txt;
2014-09-18 13:41:20 +02:00
public class CmdFactionsPerm extends FactionsCommand
{
2013-11-11 09:31:04 +01:00
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
2013-04-10 13:12:22 +02:00
public CmdFactionsPerm()
{
2013-11-11 09:31:04 +01:00
// Aliases
2013-04-16 10:11:59 +02:00
this.addAliases("perm");
2013-11-11 09:31:04 +01:00
// Args
2013-04-16 11:05:49 +02:00
this.addOptionalArg("faction", "you");
this.addOptionalArg("perm", "all");
this.addOptionalArg("relation", "read");
this.addOptionalArg("yes/no", "read");
this.setErrorOnToManyArgs(false);
2013-11-11 09:31:04 +01:00
// Requirements
2013-04-16 10:11:59 +02:00
this.addRequirements(ReqHasPerm.get(Perm.PERM.node));
}
2013-11-11 09:31:04 +01:00
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public void perform()
{
// Arg: Faction
2014-09-18 13:41:20 +02:00
Faction faction = this.arg(0, ARFaction.get(), msenderFaction);
if (faction == null) return;
// Case: Show All
if ( ! this.argIsSet(1))
{
2014-09-18 13:41:20 +02:00
msg(Txt.titleize("Perms for " + faction.describeTo(msender, true)));
msg(MPerm.getStateHeaders());
for (MPerm perm : MPerm.getAll())
{
2011-10-24 01:37:51 +02:00
msg(perm.getStateInfo(faction.getPermittedRelations(perm), true));
}
return;
}
// Arg: MPerm
MPerm mperm = this.arg(1, ARMPerm.get());
if (mperm == null) return;
2013-04-16 11:27:03 +02:00
// Case: Show One
if ( ! this.argIsSet(2))
{
2014-09-18 13:41:20 +02:00
msg(Txt.titleize("Perm for " + faction.describeTo(msender, true)));
msg(MPerm.getStateHeaders());
msg(mperm.getStateInfo(faction.getPermittedRelations(mperm), true));
return;
}
// Do the sender have the right to change perms for this faction?
if ( ! MPerm.getPermPerms().has(msender, faction, true)) return;
// Is this perm editable?
if (!msender.isUsingAdminMode() && !mperm.isEditable())
{
msg("<b>The perm <h>%s <b>is not editable.", mperm.getName());
return;
}
// Arg: Rel
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;
if ( ! this.argIsSet(3))
{
msg("<b>Should <h>%s <b>have the <h>%s <b>permission or not?\nYou must <h>add \"yes\" or \"no\" <b>at the end.", Txt.getNicedEnum(rel), Txt.upperCaseFirst(mperm.getName()));
return;
}
// Arg: Target Value
Boolean targetValue = this.arg(3, ARBoolean.get(), null);
if (targetValue == null) return;
2012-05-09 06:29:52 +02:00
// Apply
faction.setRelationPermitted(mperm, rel, targetValue);
// The following is to make sure the leader always has the right to change perms if that is our goal.
if (mperm == MPerm.getPermPerms() && MPerm.getPermPerms().getStandard().contains(Rel.LEADER))
{
faction.setRelationPermitted(MPerm.getPermPerms(), Rel.LEADER, true);
}
// Inform
2014-09-18 13:41:20 +02:00
msg(Txt.titleize("Perm for " + faction.describeTo(msender, true)));
msg(MPerm.getStateHeaders());
msg(mperm.getStateInfo(faction.getPermittedRelations(mperm), true));
}
}