2015-01-09 22:36:12 +01:00
package com.massivecraft.factions.cmd ;
import com.massivecraft.factions.Perm ;
2015-10-21 19:35:41 +02:00
import com.massivecraft.factions.cmd.type.TypeFaction ;
import com.massivecraft.factions.cmd.type.TypeMFlag ;
2015-01-09 22:36:12 +01:00
import com.massivecraft.factions.entity.Faction ;
import com.massivecraft.factions.entity.MFlag ;
import com.massivecraft.factions.entity.MPerm ;
import com.massivecraft.factions.event.EventFactionsFlagChange ;
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 ;
import com.massivecraft.massivecore.command.type.primitive.TypeBoolean ;
2015-01-09 22:36:12 +01:00
public class CmdFactionsFlagSet extends FactionsCommand
{
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public CmdFactionsFlagSet ( )
{
// Aliases
this . addAliases ( " set " ) ;
2015-10-21 19:35:41 +02:00
// Parameters
this . addParameter ( TypeMFlag . get ( ) , " flag " ) ;
2015-11-06 02:10:29 +01:00
this . addParameter ( TypeBoolean . getYes ( ) , " yes/no " ) ;
2015-10-21 19:35:41 +02:00
this . addParameter ( TypeFaction . get ( ) , " faction " , " you " ) ;
2015-01-09 22:36:12 +01:00
// Requirements
2016-05-26 10:17:44 +02:00
this . addRequirements ( RequirementHasPerm . get ( Perm . FLAG_SET ) ) ;
2015-01-09 22:36:12 +01:00
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
2015-02-12 12:00:55 +01:00
public void perform ( ) throws MassiveException
2015-01-09 22:36:12 +01:00
{
// Args
2015-05-06 17:04:35 +02:00
MFlag flag = this . readArg ( ) ;
boolean value = this . readArg ( ) ;
Faction faction = this . readArg ( msenderFaction ) ;
2015-01-09 22:36:12 +01:00
// Do the sender have the right to change flags for this faction?
if ( ! MPerm . getPermFlags ( ) . has ( msender , faction , true ) ) return ;
// Is this flag editable?
2016-02-02 19:03:11 +01:00
if ( ! msender . isOverriding ( ) & & ! flag . isEditable ( ) )
2015-01-09 22:36:12 +01:00
{
msg ( " <b>The flag <h>%s <b>is not editable. " , flag . getName ( ) ) ;
return ;
}
// Event
EventFactionsFlagChange event = new EventFactionsFlagChange ( sender , faction , flag , value ) ;
event . run ( ) ;
if ( event . isCancelled ( ) ) return ;
value = event . isNewValue ( ) ;
// No change
if ( faction . getFlag ( flag ) = = value )
{
msg ( " %s <i>already has %s <i>set to %s<i>. " , faction . describeTo ( msender ) , flag . getStateDesc ( value , false , true , true , false , true ) , flag . getStateDesc ( value , true , true , false , false , false ) ) ;
return ;
}
// Apply
faction . setFlag ( flag , value ) ;
// Inform
String stateInfo = flag . getStateDesc ( faction . getFlag ( flag ) , true , false , true , true , true ) ;
if ( msender . getFaction ( ) ! = faction )
{
// Send message to sender
msg ( " <h>%s <i>set a flag for <h>%s<i>. " , msender . describeTo ( msender , true ) , faction . describeTo ( msender , true ) ) ;
2015-09-03 09:33:01 +02:00
message ( stateInfo ) ;
2015-01-09 22:36:12 +01:00
}
faction . msg ( " <h>%s <i>set a flag for <h>%s<i>. " , msender . describeTo ( faction , true ) , faction . describeTo ( faction , true ) ) ;
faction . sendMessage ( stateInfo ) ;
}
}