2012-03-09 23:09:33 +01:00
package com.massivecraft.factions.cmd ;
2013-04-16 11:05:49 +02:00
import com.massivecraft.factions.cmd.arg.ARFaction ;
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-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:24:55 +02:00
import com.massivecraft.factions.FPerm ;
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 ;
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 ;
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
// Args
2013-04-16 10:30:21 +02:00
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 ) ) ;
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
public void perform ( )
2013-04-25 13:25:15 +02:00
{
2013-04-19 12:44:28 +02:00
// Args
2014-09-18 13:41:20 +02:00
Faction faction = this . arg ( 0 , ARFaction . get ( ) , msenderFaction ) ;
2012-03-09 23:09:33 +01:00
if ( faction = = null ) return ;
2013-04-19 12:44:28 +02:00
// FPerm
2014-09-18 13:41:20 +02:00
if ( ! FPerm . DISBAND . has ( msender , faction , true ) ) return ;
2012-03-09 23:09:33 +01:00
2013-04-19 12:44:28 +02:00
// Verify
2014-10-02 11:45:06 +02:00
if ( faction . getFlag ( MFlag . getPermanent ( ) ) )
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
}