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

105 lines
3.0 KiB
Java
Raw Normal View History

2011-10-23 20:50:49 +02:00
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Perm;
import com.massivecraft.factions.cmd.arg.ARMFlag;
2013-04-16 11:05:49 +02:00
import com.massivecraft.factions.cmd.arg.ARFaction;
2013-04-22 09:37:53 +02:00
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MFlag;
import com.massivecraft.factions.entity.MPerm;
import com.massivecraft.factions.event.EventFactionsFlagChange;
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
2014-09-18 13:41:20 +02:00
public class CmdFactionsFlag extends FactionsCommand
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-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
{
// Arg: Faction
2014-09-18 13:41:20 +02:00
Faction faction = this.arg(0, ARFaction.get(), msenderFaction);
2011-10-23 20:50:49 +02:00
if (faction == null) return;
// Case: Show All
2011-10-23 20:50:49 +02:00
if ( ! this.argIsSet(1))
{
2014-09-18 13:41:20 +02:00
msg(Txt.titleize("Flags for " + faction.describeTo(msender, true)));
for (MFlag mflag : MFlag.getAll())
2011-10-23 20:50:49 +02:00
{
if (!mflag.isVisible() && !msender.isUsingAdminMode()) continue;
msg(mflag.getStateInfo(faction.getFlag(mflag), true));
2011-10-23 20:50:49 +02:00
}
return;
}
// Arg: MFlag
MFlag mflag = this.arg(1, ARMFlag.get());
if (mflag == null) return;
2013-04-16 11:27:03 +02:00
// Case: Show One
2011-10-23 20:50:49 +02:00
if ( ! this.argIsSet(2))
{
2014-09-18 13:41:20 +02:00
msg(Txt.titleize("Flag for " + faction.describeTo(msender, true)));
msg(mflag.getStateInfo(faction.getFlag(mflag), true));
2011-10-23 20:50:49 +02:00
return;
}
// Do the sender have the right to change flags for this faction?
if ( ! MPerm.getPermFlags().has(msender, faction, true)) return;
// Is this flag editable?
if (!msender.isUsingAdminMode() && !mflag.isEditable())
{
msg("<b>The flag <h>%s <b>is not editable.", mflag.getName());
return;
}
// Arg: Target Value
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;
// Event
EventFactionsFlagChange event = new EventFactionsFlagChange(sender, faction, mflag, targetValue);
event.run();
if (event.isCancelled()) return;
targetValue = event.isNewValue();
// Apply
faction.setFlag(mflag, targetValue);
// Inform
String stateInfo = mflag.getStateInfo(faction.getFlag(mflag), true);
if (msender.getFaction() != faction)
{
// Send message to sender
msg("<h>%s <i>set a flag for <h>%s", msender.describeTo(msender, true), faction.describeTo(msender, true));
msg(stateInfo);
}
faction.msg("<h>%s <i>set a flag for <h>%s", msender.describeTo(faction, true), faction.describeTo(faction, true));
faction.msg(stateInfo);
2011-10-23 20:50:49 +02:00
}
}