2012-03-09 23:09:33 +01:00
package com.massivecraft.factions.cmd ;
2015-10-21 19:35:41 +02:00
import com.massivecraft.factions.cmd.type.TypeFaction ;
2014-09-17 13:17:33 +02:00
import com.massivecraft.factions.entity.FactionColl ;
2014-10-02 11:45:06 +02:00
import com.massivecraft.factions.entity.MFlag ;
2014-10-02 14:02:07 +02:00
import com.massivecraft.factions.entity.MPerm ;
2014-09-17 13:17:33 +02:00
import com.massivecraft.factions.entity.MPlayer ;
2013-04-22 09:37:53 +02:00
import com.massivecraft.factions.entity.Faction ;
2013-04-22 10:05:03 +02:00
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 ;
2013-04-09 13:00:09 +02:00
import com.massivecraft.factions.Factions ;
2013-04-09 12:56:29 +02:00
import com.massivecraft.factions.Perm ;
2015-02-12 12:00:55 +01:00
import com.massivecraft.massivecore.MassiveException ;
2015-11-06 02:10:29 +01:00
import com.massivecraft.massivecore.command.requirement.RequirementHasPerm ;
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 ;
2012-03-09 23:09:33 +01:00
2014-09-18 13:41:20 +02:00
public class CmdFactionsDisband extends FactionsCommand
2012-03-09 23:09:33 +01:00
{
2013-11-11 09:31:04 +01:00
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
2013-04-10 13:12:22 +02:00
public CmdFactionsDisband ( )
2012-03-09 23:09:33 +01:00
{
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
2015-10-21 19:35:41 +02:00
// Parameters
this . addParameter ( TypeFaction . get ( ) , " faction " , " you " ) ;
2013-04-25 13:25:15 +02:00
2013-11-11 09:31:04 +01:00
// Requirements
2015-11-06 02:10:29 +01:00
this . addRequirements ( RequirementHasPerm . get ( Perm . DISBAND . node ) ) ;
2012-03-09 23:09:33 +01:00
}
2013-11-11 09:31:04 +01:00
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
2012-03-09 23:09:33 +01:00
@Override
2015-02-12 12:00:55 +01:00
public void perform ( ) throws MassiveException
2014-10-22 07:50:30 +02:00
{
2013-04-19 12:44:28 +02:00
// Args
2015-05-06 17:04:35 +02:00
Faction faction = this . readArg ( msenderFaction ) ;
2012-03-09 23:09:33 +01:00
2014-10-02 14:02:07 +02:00
// MPerm
2014-10-03 09:01:36 +02:00
if ( ! MPerm . getPermDisband ( ) . has ( msender , faction , true ) ) return ;
2012-03-09 23:09:33 +01:00
2013-04-19 12:44:28 +02:00
// Verify
2014-10-07 12:30:44 +02:00
if ( faction . getFlag ( MFlag . getFlagPermanent ( ) ) )
2012-03-09 23:09:33 +01:00
{
msg ( " <i>This faction is designated as permanent, so you cannot disband it. " ) ;
return ;
}
2013-04-19 12:44:28 +02:00
// Event
2014-06-04 16:47:01 +02:00
EventFactionsDisband event = new EventFactionsDisband ( me , faction ) ;
2013-04-19 12:44:28 +02:00
event . run ( ) ;
if ( event . isCancelled ( ) ) return ;
2012-03-09 23:09:33 +01:00
2013-04-19 12:44:28 +02:00
// Merged Apply and Inform
2013-04-22 17:59:51 +02:00
// 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 ( ) ;
2012-03-09 23:09:33 +01:00
}
2014-09-18 14:37:30 +02:00
// Inform
for ( MPlayer mplayer : faction . getMPlayersWhereOnline ( true ) )
2012-03-09 23:09:33 +01:00
{
2014-09-18 14:37:30 +02:00
mplayer . msg ( " <h>%s<i> disbanded your faction. " , msender . describeTo ( mplayer ) ) ;
2012-03-09 23:09:33 +01:00
}
2013-04-22 10:05:03 +02:00
2014-09-18 14:37:30 +02:00
if ( msenderFaction ! = faction )
{
msender . msg ( " <i>You disbanded <h>%s<i>. " , faction . describeTo ( msender ) ) ;
}
// Log
2013-04-22 10:05:03 +02:00
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 ( ) ) ) ) ;
2013-06-18 09:07:05 +02:00
}
2012-03-09 23:09:33 +01:00
2014-09-18 14:37:30 +02:00
// Apply
2012-03-09 23:09:33 +01:00
faction . detach ( ) ;
}
2013-11-11 09:31:04 +01:00
2012-03-09 23:09:33 +01:00
}