2011-10-23 20:50:49 +02:00
|
|
|
package com.massivecraft.factions.cmd;
|
|
|
|
|
2014-10-02 11:45:06 +02:00
|
|
|
import com.massivecraft.factions.FPerm;
|
2013-04-09 12:56:29 +02:00
|
|
|
import com.massivecraft.factions.Perm;
|
2014-10-02 11:45:06 +02:00
|
|
|
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;
|
2014-10-02 11:45:06 +02:00
|
|
|
import com.massivecraft.factions.entity.MFlag;
|
|
|
|
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
|
2013-04-16 10:30:21 +02:00
|
|
|
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
|
|
|
{
|
2014-10-02 11:45:06 +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;
|
|
|
|
|
2014-10-02 11:45:06 +02:00
|
|
|
// 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)));
|
2014-10-02 11:45:06 +02:00
|
|
|
for (MFlag mflag : MFlag.getAll())
|
2011-10-23 20:50:49 +02:00
|
|
|
{
|
2014-10-02 11:45:06 +02:00
|
|
|
if (!mflag.isVisible() && !msender.isUsingAdminMode()) continue;
|
|
|
|
msg(mflag.getStateInfo(faction.getFlag(mflag), true));
|
2011-10-23 20:50:49 +02:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-02 11:45:06 +02:00
|
|
|
// Arg: MFlag
|
|
|
|
MFlag mflag = this.arg(1, ARMFlag.get());
|
|
|
|
if (mflag == null) return;
|
2013-04-16 11:27:03 +02:00
|
|
|
|
2014-10-02 11:45:06 +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)));
|
2014-10-02 11:45:06 +02:00
|
|
|
msg(mflag.getStateInfo(faction.getFlag(mflag), true));
|
2011-10-23 20:50:49 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-02 11:45:06 +02:00
|
|
|
// Do the sender have the right to change flags for this faction?
|
|
|
|
if ( ! FPerm.PERMS.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;
|
|
|
|
|
2014-10-02 11:45:06 +02:00
|
|
|
// 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
|
|
|
}
|
|
|
|
|
|
|
|
}
|