2012-03-09 23:09:33 +01:00
package com.massivecraft.factions.cmd ;
2017-02-10 16:38:36 +01:00
import com.massivecraft.factions.Factions ;
2015-10-21 19:35:41 +02:00
import com.massivecraft.factions.cmd.type.TypeFaction ;
2017-02-10 16:38:36 +01:00
import com.massivecraft.factions.entity.Faction ;
2014-09-17 13:17:33 +02:00
import com.massivecraft.factions.entity.FactionColl ;
2017-02-10 16:38:36 +01:00
import com.massivecraft.factions.entity.MConf ;
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 ;
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 ;
2019-01-19 12:21:28 +01:00
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 ;
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
{
2015-10-21 19:35:41 +02:00
// Parameters
2019-01-19 12:21:28 +01:00
this . addParameter ( TypeFaction . get ( ) , " faction " ) ;
this . addParameter ( TypeStringConfirmation . get ( ) , " confirmation " , " " ) ;
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
2019-01-19 12:21:28 +01:00
Faction faction = this . readArg ( ) ;
String confirmationString = this . readArg ( null ) ;
if ( MConf . get ( ) . requireConfirmationForFactionDisbanding ) ConfirmationUtil . tryConfirm ( this ) ;
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
{
2019-01-19 12:21:28 +01:00
throw new MassiveException ( ) . addMsg ( " <i>This faction is designated as permanent, so you cannot disband it. " ) ;
2012-03-09 23:09:33 +01:00
}
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
}