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

94 lines
2.7 KiB
Java
Raw Normal View History

package com.massivecraft.factions.cmd;
2013-04-16 11:05:49 +02:00
import com.massivecraft.factions.cmd.arg.ARFaction;
import com.massivecraft.factions.entity.FactionColl;
import com.massivecraft.factions.entity.MPlayer;
2013-04-22 09:37:53 +02:00
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MConf;
2014-06-04 16:47:01 +02:00
import com.massivecraft.factions.event.EventFactionsDisband;
import com.massivecraft.factions.event.EventFactionsMembershipChange;
import com.massivecraft.factions.event.EventFactionsMembershipChange.MembershipChangeReason;
import com.massivecraft.factions.FFlag;
import com.massivecraft.factions.FPerm;
2013-04-09 13:00:09 +02:00
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Perm;
2014-06-04 14:02:23 +02:00
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
2014-06-21 19:03:39 +02:00
import com.massivecraft.massivecore.util.IdUtil;
2014-06-04 14:02:23 +02:00
import com.massivecraft.massivecore.util.Txt;
2014-09-18 13:41:20 +02:00
public class CmdFactionsDisband extends FactionsCommand
{
2013-11-11 09:31:04 +01:00
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
2013-04-10 13:12:22 +02:00
public CmdFactionsDisband()
{
2013-11-11 09:31:04 +01:00
// Aliases
2013-04-16 10:11:59 +02:00
this.addAliases("disband");
2013-11-11 09:31:04 +01:00
// Args
this.addOptionalArg("faction", "you");
2013-04-25 13:25:15 +02:00
2013-11-11 09:31:04 +01:00
// Requirements
2013-04-16 10:11:59 +02:00
this.addRequirements(ReqHasPerm.get(Perm.DISBAND.node));
}
2013-11-11 09:31:04 +01:00
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public void perform()
2013-04-25 13:25:15 +02:00
{
// Args
2014-09-18 13:41:20 +02:00
Faction faction = this.arg(0, ARFaction.get(), msenderFaction);
if (faction == null) return;
// FPerm
2014-09-18 13:41:20 +02:00
if ( ! FPerm.DISBAND.has(msender, faction, true)) return;
// Verify
if (faction.getFlag(FFlag.PERMANENT))
{
msg("<i>This faction is designated as permanent, so you cannot disband it.");
return;
}
// Event
2014-06-04 16:47:01 +02:00
EventFactionsDisband event = new EventFactionsDisband(me, faction);
event.run();
if (event.isCancelled()) return;
// Merged Apply and Inform
// Run event for each player in the faction
2014-09-17 13:29:58 +02:00
for (MPlayer mplayer : faction.getMPlayers())
2012-03-13 13:47:54 +01:00
{
2014-09-17 13:29:58 +02:00
EventFactionsMembershipChange membershipChangeEvent = new EventFactionsMembershipChange(sender, mplayer, FactionColl.get().getNone(), MembershipChangeReason.DISBAND);
2013-04-19 14:08:45 +02:00
membershipChangeEvent.run();
}
// Inform
for (MPlayer mplayer : faction.getMPlayersWhereOnline(true))
{
mplayer.msg("<h>%s<i> disbanded your faction.", msender.describeTo(mplayer));
}
if (msenderFaction != faction)
{
msender.msg("<i>You disbanded <h>%s<i>." , faction.describeTo(msender));
}
// Log
if (MConf.get().logFactionDisband)
{
2014-09-18 13:41:20 +02:00
Factions.get().log(Txt.parse("<i>The faction <h>%s <i>(<h>%s<i>) was disbanded by <h>%s<i>.", faction.getName(), faction.getId(), msender.getDisplayName(IdUtil.getConsole())));
}
// Apply
faction.detach();
}
2013-11-11 09:31:04 +01:00
}