2018-05-13 19:49:13 +00:00
package me.totalfreedom.totalfreedommod.command ;
2019-01-29 04:57:41 +00:00
import java.util.Arrays ;
import java.util.Collections ;
import java.util.List ;
2020-06-30 07:25:38 +00:00
import me.totalfreedom.totalfreedommod.player.PlayerData ;
2018-05-13 19:49:13 +00:00
import me.totalfreedom.totalfreedommod.rank.Rank ;
import me.totalfreedom.totalfreedommod.util.FUtil ;
2019-07-28 06:04:16 +00:00
import org.apache.commons.lang.StringUtils ;
2018-05-13 19:49:13 +00:00
import org.bukkit.ChatColor ;
import org.bukkit.command.Command ;
import org.bukkit.command.CommandSender ;
import org.bukkit.entity.Player ;
2020-06-30 07:25:38 +00:00
@CommandPermissions ( level = Rank . OP , source = SourceType . BOTH )
@CommandParameters ( description = " List, add, or remove master builders, reload the master builder list, or view the info of master builders. " , usage = " /<command> <list | <<add | remove> <username>>> " )
2018-05-13 19:49:13 +00:00
public class Command_mbconfig extends FreedomCommand
{
@Override
public boolean run ( CommandSender sender , Player playerSender , Command cmd , String commandLabel , String [ ] args , boolean senderIsConsole )
{
if ( args . length < 1 )
{
return false ;
}
switch ( args [ 0 ] )
{
case " list " :
{
2020-06-30 07:25:38 +00:00
msg ( " Master Builders: " + StringUtils . join ( plugin . pl . getMasterBuilderNames ( ) , " , " ) , ChatColor . GOLD ) ;
2018-05-13 19:49:13 +00:00
return true ;
}
case " add " :
{
if ( args . length < 2 )
{
return false ;
}
2020-06-30 07:25:38 +00:00
if ( ! plugin . pl . canManageMasterBuilders ( sender . getName ( ) ) )
2018-05-13 19:49:13 +00:00
{
2020-06-30 07:25:38 +00:00
return noPerms ( ) ;
2018-05-13 19:49:13 +00:00
}
2020-06-30 07:25:38 +00:00
final Player player = getPlayer ( args [ 1 ] ) ;
2020-07-10 09:09:47 +00:00
PlayerData data ;
if ( player = = null )
{
data = plugin . pl . getData ( args [ 1 ] ) ;
if ( data = = null )
{
msg ( PLAYER_NOT_FOUND ) ;
return true ;
}
}
else
{
data = plugin . pl . getData ( player ) ;
}
2018-05-13 19:49:13 +00:00
2020-06-30 07:25:38 +00:00
if ( data . isMasterBuilder ( ) & & plugin . pl . isPlayerImpostor ( player ) )
2018-05-13 19:49:13 +00:00
{
2020-08-15 06:44:57 +00:00
FUtil . staffAction ( sender . getName ( ) , " Re-adding " + player . getName ( ) + " to the Master Builder list " , true ) ;
2020-06-30 07:25:38 +00:00
player . setOp ( true ) ;
player . sendMessage ( YOU_ARE_OP ) ;
2018-05-13 19:49:13 +00:00
2020-06-30 07:25:38 +00:00
if ( plugin . pl . getPlayer ( player ) . getFreezeData ( ) . isFrozen ( ) )
2018-05-13 19:49:13 +00:00
{
2020-06-30 07:25:38 +00:00
plugin . pl . getPlayer ( player ) . getFreezeData ( ) . setFrozen ( false ) ;
player . sendMessage ( ChatColor . GRAY + " You have been unfrozen. " ) ;
2018-05-13 19:49:13 +00:00
}
2020-06-30 07:25:38 +00:00
plugin . pl . verify ( player , null ) ;
plugin . rm . updateDisplay ( player ) ;
2018-05-13 19:49:13 +00:00
}
2020-06-30 07:25:38 +00:00
else if ( ! data . isMasterBuilder ( ) )
2018-05-13 19:49:13 +00:00
{
2020-08-15 06:44:57 +00:00
FUtil . staffAction ( sender . getName ( ) , " Adding " + player . getName ( ) + " to the Master Builder list " , true ) ;
2020-06-30 07:25:38 +00:00
data . setMasterBuilder ( true ) ;
data . setVerification ( true ) ;
plugin . pl . save ( data ) ;
plugin . rm . updateDisplay ( player ) ;
return true ;
2018-05-13 19:49:13 +00:00
}
2020-06-30 07:25:38 +00:00
else
2018-05-13 19:49:13 +00:00
{
2020-06-30 07:25:38 +00:00
msg ( " That player is already on the Master Builder list. " ) ;
return true ;
2018-05-13 19:49:13 +00:00
}
}
case " remove " :
{
if ( args . length < 2 )
{
return false ;
}
2020-06-30 07:25:38 +00:00
if ( ! plugin . pl . canManageMasterBuilders ( sender . getName ( ) ) )
2018-05-13 19:49:13 +00:00
{
2020-06-30 07:25:38 +00:00
return noPerms ( ) ;
2018-05-13 19:49:13 +00:00
}
Player player = getPlayer ( args [ 1 ] ) ;
2020-06-30 07:25:38 +00:00
PlayerData data = plugin . pl . getData ( player ) ;
2018-05-13 19:49:13 +00:00
2020-06-30 07:25:38 +00:00
if ( ! data . isMasterBuilder ( ) )
2018-05-13 19:49:13 +00:00
{
2018-07-31 08:03:12 +00:00
msg ( " Master Builder not found: " + args [ 1 ] ) ;
2018-05-13 19:49:13 +00:00
return true ;
}
2020-08-15 06:44:57 +00:00
FUtil . staffAction ( sender . getName ( ) , " Removing " + data . getName ( ) + " from the Master Builder list " , true ) ;
2020-06-30 07:25:38 +00:00
data . setMasterBuilder ( false ) ;
if ( data . getDiscordID ( ) = = null )
2018-05-13 19:49:13 +00:00
{
2020-06-30 07:25:38 +00:00
data . setVerification ( false ) ;
2018-05-13 19:49:13 +00:00
}
2020-06-30 07:25:38 +00:00
plugin . pl . save ( data ) ;
plugin . rm . updateDisplay ( player ) ;
2018-05-13 19:49:13 +00:00
return true ;
}
default :
{
return false ;
}
}
}
2019-01-29 04:57:41 +00:00
@Override
public List < String > getTabCompleteOptions ( CommandSender sender , Command command , String alias , String [ ] args )
{
2020-07-01 03:21:44 +00:00
if ( args . length = = 1 )
2019-01-29 04:57:41 +00:00
{
2020-07-01 03:21:44 +00:00
return Arrays . asList ( " add " , " remove " , " list " ) ;
2019-01-29 04:57:41 +00:00
}
2020-07-01 03:21:44 +00:00
else if ( args . length = = 2 )
2019-01-29 04:57:41 +00:00
{
2020-07-01 03:21:44 +00:00
if ( args [ 0 ] . equals ( " add " ) )
2019-01-29 04:57:41 +00:00
{
2020-07-01 03:21:44 +00:00
return FUtil . getPlayerList ( ) ;
2019-01-29 04:57:41 +00:00
}
2020-07-01 03:21:44 +00:00
else if ( args [ 0 ] . equals ( " remove " ) )
2019-01-29 04:57:41 +00:00
{
2020-07-01 03:21:44 +00:00
return plugin . pl . getMasterBuilderNames ( ) ;
2019-01-29 04:57:41 +00:00
}
}
return Collections . emptyList ( ) ;
}
2018-05-13 19:49:13 +00:00
}