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

77 lines
2.1 KiB
Java
Raw Normal View History

2011-10-23 20:50:49 +02:00
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FFlag;
import com.massivecraft.factions.Perm;
2013-04-16 11:27:03 +02:00
import com.massivecraft.factions.cmd.arg.ARFFlag;
2013-04-16 11:05:49 +02:00
import com.massivecraft.factions.cmd.arg.ARFaction;
2013-04-25 13:25:15 +02:00
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
2013-04-22 09:37:53 +02:00
import com.massivecraft.factions.entity.Faction;
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;
2011-10-23 20:50:49 +02:00
2013-04-10 13:12:22 +02:00
public class CmdFactionsFlag extends FCommand
2011-10-23 20:50:49 +02:00
{
2013-11-11 09:31:04 +01:00
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
2011-10-23 20:50:49 +02:00
2013-04-10 13:12:22 +02:00
public CmdFactionsFlag()
2011-10-23 20:50:49 +02:00
{
2013-11-11 09:31:04 +01:00
// Aliases
2013-04-16 10:11:59 +02:00
this.addAliases("flag");
2013-11-11 09:31:04 +01:00
// Args
this.addOptionalArg("faction", "you");
this.addOptionalArg("flag", "all");
this.addOptionalArg("yes/no", "read");
2013-11-11 09:31:04 +01:00
// Requirements
2013-04-25 13:25:15 +02:00
this.addRequirements(ReqFactionsEnabled.get());
2013-04-16 10:11:59 +02:00
this.addRequirements(ReqHasPerm.get(Perm.FLAG.node));
2011-10-23 20:50:49 +02:00
}
2013-11-11 09:31:04 +01:00
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
2011-10-23 20:50:49 +02:00
@Override
public void perform()
2013-04-25 13:25:15 +02:00
{
Faction faction = this.arg(0, ARFaction.get(sender), usenderFaction);
2011-10-23 20:50:49 +02:00
if (faction == null) return;
if ( ! this.argIsSet(1))
{
msg(Txt.titleize("Flags for " + faction.describeTo(usender, true)));
for (FFlag flag : FFlag.values())
2011-10-23 20:50:49 +02:00
{
msg(flag.getStateInfo(faction.getFlag(flag), true));
}
return;
}
2013-04-16 11:27:03 +02:00
FFlag flag = this.arg(1, ARFFlag.get());
2011-10-23 20:50:49 +02:00
if (flag == null) return;
2013-04-16 11:27:03 +02:00
2011-10-23 20:50:49 +02:00
if ( ! this.argIsSet(2))
{
msg(Txt.titleize("Flag for " + faction.describeTo(usender, true)));
2011-10-23 20:50:49 +02:00
msg(flag.getStateInfo(faction.getFlag(flag), true));
return;
}
2013-04-16 11:27:03 +02:00
Boolean targetValue = this.arg(2, ARBoolean.get());
2011-10-23 20:50:49 +02:00
if (targetValue == null) return;
// Do the sender have the right to change flags?
if ( ! Perm.FLAG_SET.has(sender, true)) return;
2011-10-23 20:50:49 +02:00
// Do the change
msg(Txt.titleize("Flag for " + faction.describeTo(usender, true)));
2011-10-23 20:50:49 +02:00
faction.setFlag(flag, targetValue);
msg(flag.getStateInfo(faction.getFlag(flag), true));
}
}