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 )
2020-11-10 03:05:33 +00:00
@CommandParameters ( description = " List, add, or remove master builders. Master builders can also clear their own IPs. " , usage = " /<command> <list | clearip <ip> | clearips | <<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 ;
}
2020-11-10 03:05:33 +00:00
case " clearips " :
{
if ( args . length > 1 )
{
return false ;
}
if ( senderIsConsole )
{
msg ( " Only in-game players may use this command. " , ChatColor . RED ) ;
return true ;
}
PlayerData data = plugin . pl . getData ( sender . getName ( ) ) ;
if ( ! data . isMasterBuilder ( ) )
{
msg ( " You are not a master builder! " , ChatColor . RED ) ;
return true ;
}
int counter = data . getIps ( ) . size ( ) - 1 ;
data . clearIps ( ) ;
data . addIp ( FUtil . getIp ( playerSender ) ) ;
plugin . sql . addPlayer ( data ) ;
msg ( counter + " IPs removed. " ) ;
msg ( data . getIps ( ) . get ( 0 ) + " is now your only IP address " ) ;
FUtil . staffAction ( sender . getName ( ) , " Clearing my IPs " , true ) ;
return true ;
}
case " clearip " :
{
if ( args . length < 2 )
{
return false ;
}
if ( senderIsConsole )
{
msg ( " Only in-game players may use this command. " , ChatColor . RED ) ;
return true ;
}
PlayerData data = plugin . pl . getData ( sender . getName ( ) ) ;
final String targetIp = FUtil . getIp ( playerSender ) ;
if ( ! data . isMasterBuilder ( ) )
{
msg ( " You are not a master builder! " , ChatColor . RED ) ;
return true ;
}
if ( targetIp . equals ( args [ 1 ] ) )
{
msg ( " You cannot remove your current IP. " ) ;
return true ;
}
data . removeIp ( args [ 1 ] ) ;
plugin . sql . addPlayer ( data ) ;
msg ( " Removed IP " + args [ 1 ] ) ;
msg ( " Current IPs: " + StringUtils . join ( data . getIps ( ) , " , " ) ) ;
return true ;
}
2018-05-13 19:49:13 +00:00
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
2020-11-10 02:11:21 +00:00
PlayerData data = player ! = null ? plugin . pl . getData ( player ) : plugin . pl . getData ( args [ 1 ] ) ;
2020-07-10 09:09:47 +00:00
2020-11-10 02:11:21 +00:00
if ( data = = null )
2020-07-10 09:09:47 +00:00
{
2020-11-10 02:11:21 +00:00
msg ( PLAYER_NOT_FOUND , ChatColor . RED ) ;
return true ;
2020-07-10 09:09:47 +00:00
}
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-11-10 02:11:21 +00:00
FUtil . staffAction ( sender . getName ( ) , " Re-adding " + data . getName ( ) + " to the Master Builder list " , true ) ;
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 ) ;
2018-05-13 19:49:13 +00:00
}
2020-11-10 02:11:21 +00:00
if ( player ! = null )
{
plugin . pl . verify ( player , null ) ;
plugin . rm . updateDisplay ( player ) ;
player . setOp ( true ) ;
player . sendMessage ( YOU_ARE_OP ) ;
}
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-11-10 02:11:21 +00:00
FUtil . staffAction ( sender . getName ( ) , " Adding " + data . 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 ) ;
2020-11-10 02:11:21 +00:00
if ( player ! = null )
{
plugin . rm . updateDisplay ( player ) ;
}
2020-06-30 07:25:38 +00:00
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-11-10 02:11:21 +00:00
PlayerData data = player ! = null ? plugin . pl . getData ( player ) : plugin . pl . getData ( args [ 1 ] ) ;
2018-05-13 19:49:13 +00:00
2020-11-10 02:11:21 +00:00
if ( data = = null | | ! 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 22:42:46 +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 ) ;
2020-11-10 02:11:21 +00:00
if ( player ! = null )
{
plugin . rm . updateDisplay ( player ) ;
}
2018-05-13 19:49:13 +00:00
return true ;
}
default :
{
return false ;
}
}
}
2020-11-10 02:11:21 +00:00
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-11-10 03:05:33 +00:00
return Arrays . asList ( " add " , " remove " , " list " , " clearips " , " clearip " ) ;
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-11-10 02:11:21 +00:00
if ( args [ 0 ] . equalsIgnoreCase ( " 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-11-10 03:05:33 +00:00
else if ( args [ 0 ] . equalsIgnoreCase ( " 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
}
2020-11-10 03:05:33 +00:00
else if ( args [ 0 ] . equalsIgnoreCase ( " clearip " ) )
{
PlayerData data = plugin . pl . getData ( sender . getName ( ) ) ;
if ( data . isMasterBuilder ( ) )
{
return data . getIps ( ) ;
}
return Collections . emptyList ( ) ;
}
2019-01-29 04:57:41 +00:00
}
return Collections . emptyList ( ) ;
}
2018-05-13 19:49:13 +00:00
}