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

91 lines
2.9 KiB
Java
Raw Normal View History

package com.massivecraft.factions.cmd;
2017-02-10 16:38:36 +01:00
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.cmd.type.TypeFaction;
2017-02-10 16:38:36 +01:00
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.FactionColl;
2017-02-10 16:38:36 +01:00
import com.massivecraft.factions.entity.MConf;
import com.massivecraft.factions.entity.MFlag;
import com.massivecraft.factions.entity.MPerm;
import com.massivecraft.factions.entity.MPlayer;
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;
2015-02-12 12:00:55 +01:00
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.command.type.primitive.TypeStringConfirmation;
import com.massivecraft.massivecore.util.ConfirmationUtil;
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()
{
// Parameters
this.addParameter(TypeFaction.get(), "faction");
this.addParameter(TypeStringConfirmation.get(), "confirmation", "");
}
2013-11-11 09:31:04 +01:00
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
2015-02-12 12:00:55 +01:00
public void perform() throws MassiveException
{
// Args
Faction faction = this.readArg();
String confirmationString = this.readArg(null);
if(MConf.get().requireConfirmationForFactionDisbanding) ConfirmationUtil.tryConfirm(this);
// MPerm
if ( ! MPerm.getPermDisband().has(msender, faction, true)) return;
// Verify
if (faction.getFlag(MFlag.getFlagPermanent()))
{
throw new MassiveException().addMsg("<i>This faction is designated as permanent, so you cannot disband it.");
}
// 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
}