2011-10-09 21:57:43 +02:00
|
|
|
package com.massivecraft.factions.cmd;
|
2011-03-22 15:45:41 +01:00
|
|
|
|
2013-04-09 12:56:29 +02:00
|
|
|
import com.massivecraft.factions.Perm;
|
2013-04-16 12:04:12 +02:00
|
|
|
import com.massivecraft.factions.Rel;
|
2013-04-25 13:25:15 +02:00
|
|
|
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
|
2013-04-25 13:53:22 +02:00
|
|
|
import com.massivecraft.factions.cmd.req.ReqHasFaction;
|
2013-04-16 12:04:12 +02:00
|
|
|
import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast;
|
2013-04-19 12:27:39 +02:00
|
|
|
import com.massivecraft.factions.event.FactionsEventOpenChange;
|
2013-04-16 11:05:49 +02:00
|
|
|
import com.massivecraft.mcore.cmd.arg.ARBoolean;
|
2013-04-16 10:11:59 +02:00
|
|
|
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
|
2011-03-22 15:45:41 +01:00
|
|
|
|
2013-04-10 13:12:22 +02:00
|
|
|
public class CmdFactionsOpen extends FCommand
|
2011-10-09 18:35:39 +02:00
|
|
|
{
|
2013-04-10 13:12:22 +02:00
|
|
|
public CmdFactionsOpen()
|
2011-10-09 18:35:39 +02:00
|
|
|
{
|
2013-04-16 10:11:59 +02:00
|
|
|
this.addAliases("open");
|
2011-10-09 18:35:39 +02:00
|
|
|
|
2013-04-16 10:30:21 +02:00
|
|
|
this.addOptionalArg("yes/no", "toggle");
|
2011-03-22 18:48:09 +01:00
|
|
|
|
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.OPEN.node));
|
2013-04-25 13:53:22 +02:00
|
|
|
this.addRequirements(ReqHasFaction.get());
|
2013-04-16 12:04:12 +02:00
|
|
|
this.addRequirements(ReqRoleIsAtLeast.get(Rel.OFFICER));
|
2011-03-22 15:45:41 +01:00
|
|
|
}
|
|
|
|
|
2011-06-21 07:38:31 +02:00
|
|
|
@Override
|
2011-10-09 18:35:39 +02:00
|
|
|
public void perform()
|
|
|
|
{
|
2013-04-19 12:27:39 +02:00
|
|
|
// Args
|
2013-04-25 07:29:19 +02:00
|
|
|
Boolean newOpen = this.arg(0, ARBoolean.get(), !usenderFaction.isOpen());
|
2013-04-19 12:27:39 +02:00
|
|
|
if (newOpen == null) return;
|
2013-04-16 11:05:49 +02:00
|
|
|
|
2013-04-19 12:27:39 +02:00
|
|
|
// Event
|
2013-04-25 07:29:19 +02:00
|
|
|
FactionsEventOpenChange event = new FactionsEventOpenChange(sender, usenderFaction, newOpen);
|
2013-04-19 12:27:39 +02:00
|
|
|
event.run();
|
|
|
|
if (event.isCancelled()) return;
|
|
|
|
newOpen = event.isNewOpen();
|
2011-03-22 15:45:41 +01:00
|
|
|
|
2013-04-19 12:27:39 +02:00
|
|
|
// Apply
|
2013-04-25 07:29:19 +02:00
|
|
|
usenderFaction.setOpen(newOpen);
|
2011-03-22 15:45:41 +01:00
|
|
|
|
|
|
|
// Inform
|
2013-04-25 07:29:19 +02:00
|
|
|
String descTarget = usenderFaction.isOpen() ? "open" : "closed";
|
|
|
|
usenderFaction.msg("%s<i> changed the faction to <h>%s<i>.", usender.describeTo(usenderFaction, true), descTarget);
|
2011-03-22 15:45:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|