2016-05-12 19:40:39 +00:00
package me.totalfreedom.totalfreedommod.command ;
2020-01-25 06:27:16 +00:00
import java.util.ArrayList ;
2018-07-31 07:01:29 +00:00
import java.util.Arrays ;
2020-01-25 06:27:16 +00:00
import java.util.Collections ;
import java.util.List ;
2016-05-12 19:40:39 +00:00
import me.totalfreedom.totalfreedommod.admin.Admin ;
2019-04-21 00:16:00 +00:00
import me.totalfreedom.totalfreedommod.config.ConfigEntry ;
2020-06-30 07:25:38 +00:00
import me.totalfreedom.totalfreedommod.player.PlayerData ;
2016-05-12 19:40:39 +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 ;
2016-05-12 19:40:39 +00:00
import org.bukkit.ChatColor ;
import org.bukkit.command.Command ;
import org.bukkit.command.CommandSender ;
import org.bukkit.entity.Player ;
2020-01-25 06:27:16 +00:00
@CommandPermissions ( level = Rank . SUPER_ADMIN , source = SourceType . ONLY_IN_GAME )
2020-06-30 07:25:38 +00:00
@CommandParameters ( description = " Manage your admin entry. " , usage = " /<command> [-o <admin>] <clearips | clearip <ip> | setlogin <message> | clearlogin | setacformat <format> | clearacformat> | oldtags | logstick | syncroles> " )
2016-05-12 19:40:39 +00:00
public class Command_myadmin extends FreedomCommand
{
@Override
2020-07-01 01:51:06 +00:00
public boolean run ( CommandSender sender , Player playerSender , Command cmd , String commandLabel , String [ ] args , boolean senderIsConsole )
2016-05-12 19:40:39 +00:00
{
if ( args . length < 1 )
{
return false ;
}
Player init = null ;
Admin target = getAdmin ( playerSender ) ;
Player targetPlayer = playerSender ;
// -o switch
if ( args [ 0 ] . equals ( " -o " ) )
{
checkRank ( Rank . SENIOR_ADMIN ) ;
init = playerSender ;
targetPlayer = getPlayer ( args [ 1 ] ) ;
if ( targetPlayer = = null )
{
msg ( FreedomCommand . PLAYER_NOT_FOUND ) ;
return true ;
}
2016-08-26 09:42:13 +00:00
2016-05-12 19:40:39 +00:00
target = getAdmin ( targetPlayer ) ;
if ( target = = null )
{
2020-01-25 06:27:16 +00:00
msg ( " That player is not an admin " , ChatColor . RED ) ;
2016-05-12 19:40:39 +00:00
return true ;
}
// Shift 2
args = Arrays . copyOfRange ( args , 2 , args . length ) ;
if ( args . length < 1 )
{
return false ;
}
}
2020-07-01 01:51:06 +00:00
final String targetIp = FUtil . getIp ( targetPlayer ) ;
2016-08-26 09:42:13 +00:00
2016-05-12 19:40:39 +00:00
switch ( args [ 0 ] )
{
case " clearips " :
{
if ( args . length ! = 1 )
{
return false ; // Double check: the player might mean "clearip"
}
if ( init = = null )
{
FUtil . adminAction ( sender . getName ( ) , " Clearing my supered IPs " , true ) ;
}
else
{
FUtil . adminAction ( sender . getName ( ) , " Clearing " + target . getName ( ) + " ' supered IPs " , true ) ;
}
int counter = target . getIps ( ) . size ( ) - 1 ;
target . clearIPs ( ) ;
target . addIp ( targetIp ) ;
2020-05-29 10:14:21 +00:00
plugin . al . save ( target ) ;
2020-01-25 06:27:16 +00:00
plugin . al . updateTables ( ) ;
2016-05-12 19:40:39 +00:00
2020-06-30 07:25:38 +00:00
plugin . pl . syncIps ( target ) ;
2016-05-12 19:40:39 +00:00
msg ( counter + " IPs removed. " ) ;
msg ( targetPlayer , target . getIps ( ) . get ( 0 ) + " is now your only IP address " ) ;
return true ;
}
case " clearip " :
{
if ( args . length ! = 2 )
{
return false ; // Double check: the player might mean "clearips"
}
if ( ! target . getIps ( ) . contains ( args [ 1 ] ) )
{
if ( init = = null )
{
msg ( " That IP is not registered to you. " ) ;
}
else
{
msg ( " That IP does not belong to that player. " ) ;
}
return true ;
}
if ( targetIp . equals ( args [ 1 ] ) )
{
if ( init = = null )
{
msg ( " You cannot remove your current IP. " ) ;
}
else
{
msg ( " You cannot remove that admin's current IP. " ) ;
}
return true ;
}
FUtil . adminAction ( sender . getName ( ) , " Removing a supered IP " + ( init = = null ? " " : " from " + targetPlayer . getName ( ) + " 's IPs " ) , true ) ;
target . removeIp ( args [ 1 ] ) ;
2020-05-29 10:14:21 +00:00
plugin . al . save ( target ) ;
2016-05-12 19:40:39 +00:00
plugin . al . updateTables ( ) ;
2020-06-30 07:25:38 +00:00
plugin . pl . syncIps ( target ) ;
2016-05-12 19:40:39 +00:00
msg ( " Removed IP " + args [ 1 ] ) ;
msg ( " Current IPs: " + StringUtils . join ( target . getIps ( ) , " , " ) ) ;
return true ;
}
case " setlogin " :
{
if ( args . length < 2 )
{
return false ;
}
2020-04-23 11:18:03 +00:00
String message = StringUtils . join ( args , " " , 1 , args . length ) ;
if ( ! message . contains ( " %rank% " ) & & ! message . contains ( " %coloredrank% " ) )
2019-08-07 04:33:12 +00:00
{
2019-08-07 04:41:31 +00:00
msg ( " Your login message must contain your rank. Use either %rank% or %coloredrank% to specify where you want the rank " , ChatColor . RED ) ;
2019-08-07 04:33:12 +00:00
return true ;
}
2020-04-23 11:18:03 +00:00
int length = message . replace ( " %name% " , " " ) . replace ( " %rank% " , " " ) . replace ( " %coloredrank% " , " " ) . length ( ) ;
2020-07-16 04:45:44 +00:00
if ( length > 100 )
2020-04-23 11:18:03 +00:00
{
2020-07-16 04:45:44 +00:00
msg ( " Your login message cannot be more than 100 characters (excluding your rank and your name) " , ChatColor . RED ) ;
2020-04-23 11:18:03 +00:00
return true ;
}
2016-05-12 19:40:39 +00:00
FUtil . adminAction ( sender . getName ( ) , " Setting personal login message " + ( init = = null ? " " : " for " + targetPlayer . getName ( ) ) , false ) ;
2020-04-23 11:18:03 +00:00
target . setLoginMessage ( message ) ;
2020-07-02 00:29:06 +00:00
String previewMessage = plugin . rm . craftLoginMessage ( targetPlayer , message ) ;
2016-05-12 19:40:39 +00:00
msg ( ( init = = null ? " Your " : targetPlayer . getName ( ) + " 's " ) + " login message is now: " ) ;
2020-04-23 11:18:03 +00:00
msg ( " > " + previewMessage ) ;
2020-05-29 10:14:21 +00:00
plugin . al . save ( target ) ;
2016-05-12 19:40:39 +00:00
plugin . al . updateTables ( ) ;
return true ;
}
case " clearlogin " :
{
FUtil . adminAction ( sender . getName ( ) , " Clearing personal login message " + ( init = = null ? " " : " for " + targetPlayer . getName ( ) ) , false ) ;
target . setLoginMessage ( null ) ;
2020-05-29 10:14:21 +00:00
plugin . al . save ( target ) ;
2016-05-12 19:40:39 +00:00
plugin . al . updateTables ( ) ;
return true ;
}
2018-07-30 07:23:01 +00:00
case " setacformat " :
2018-06-01 22:40:25 +00:00
{
String format = StringUtils . join ( args , " " , 1 , args . length ) ;
target . setAcFormat ( format ) ;
2020-05-29 10:14:21 +00:00
plugin . al . save ( target ) ;
2018-06-01 22:40:25 +00:00
plugin . al . updateTables ( ) ;
msg ( " Set admin chat format to \" " + format + " \" . " , ChatColor . GRAY ) ;
2018-06-02 20:08:35 +00:00
String example = format . replace ( " %name% " , " ExampleAdmin " ) . replace ( " %rank% " , Rank . TELNET_ADMIN . getAbbr ( ) ) . replace ( " %rankcolor% " , Rank . TELNET_ADMIN . getColor ( ) . toString ( ) ) . replace ( " %msg% " , " The quick brown fox jumps over the lazy dog. " ) ;
2018-06-01 22:40:25 +00:00
msg ( ChatColor . GRAY + " Example: " + FUtil . colorize ( example ) ) ;
return true ;
}
case " clearacformat " :
{
target . setAcFormat ( null ) ;
2020-05-29 10:14:21 +00:00
plugin . al . save ( target ) ;
2018-06-01 22:40:25 +00:00
plugin . al . updateTables ( ) ;
msg ( " Cleared admin chat format. " , ChatColor . GRAY ) ;
return true ;
}
case " oldtags " :
{
target . setOldTags ( ! target . getOldTags ( ) ) ;
2020-05-29 10:14:21 +00:00
plugin . al . save ( target ) ;
2018-06-01 22:40:25 +00:00
plugin . al . updateTables ( ) ;
2018-06-02 20:45:05 +00:00
msg ( ( target . getOldTags ( ) ? " Enabled " : " Disabled " ) + " old tags. " ) ;
2018-06-01 22:40:25 +00:00
return true ;
}
2018-06-28 18:06:13 +00:00
case " logstick " :
{
target . setLogStick ( ! target . getLogStick ( ) ) ;
2020-05-29 10:14:21 +00:00
plugin . al . save ( target ) ;
2018-06-28 18:06:13 +00:00
plugin . al . updateTables ( ) ;
msg ( ( target . getLogStick ( ) ? " Enabled " : " Disabled " ) + " log-stick lookup. " ) ;
return true ;
}
2018-02-22 01:22:13 +00:00
2019-04-21 00:16:00 +00:00
case " syncroles " :
{
if ( plugin . dc . enabled )
{
if ( ! ConfigEntry . DISCORD_ROLE_SYNC . getBoolean ( ) )
{
msg ( " Role syncing is not enabled. " , ChatColor . RED ) ;
return true ;
}
2020-06-30 07:25:38 +00:00
PlayerData playerData = plugin . pl . getData ( target . getName ( ) ) ;
if ( playerData . getDiscordID ( ) = = null )
2019-04-21 00:16:00 +00:00
{
msg ( " Please run /linkdiscord first! " , ChatColor . RED ) ;
return true ;
}
2020-06-30 07:25:38 +00:00
boolean synced = plugin . dc . syncRoles ( target , playerData . getDiscordID ( ) ) ;
2019-04-21 00:16:00 +00:00
if ( synced )
{
msg ( " Successfully synced your roles. " , ChatColor . GREEN ) ;
}
else
{
msg ( " Failed to sync your roles, please check the console. " , ChatColor . RED ) ;
}
}
return true ;
}
2020-01-25 06:27:16 +00:00
case " genbackupcodes " :
2020-06-30 07:25:38 +00:00
msg ( " Moved to /pv genbackupcodes " , ChatColor . RED ) ;
2020-01-25 06:27:16 +00:00
return true ;
2016-05-12 19:40:39 +00:00
default :
{
return false ;
}
}
}
2020-01-25 06:27:16 +00:00
@Override
public List < String > getTabCompleteOptions ( CommandSender sender , Command command , String alias , String [ ] args )
{
if ( ! plugin . al . isAdmin ( sender ) )
{
return Collections . emptyList ( ) ;
}
List < String > singleArguments = Arrays . asList ( " clearips " , " setlogin " , " setacformat " ) ;
2020-06-30 07:25:38 +00:00
List < String > doubleArguments = Arrays . asList ( " clearip " , " clearlogin " , " clearacformat " , " oldtags " , " logstick " , " syncroles " ) ;
2020-01-25 06:27:16 +00:00
if ( args . length = = 1 )
{
List < String > options = new ArrayList < > ( ) ;
options . add ( " -o " ) ;
options . addAll ( singleArguments ) ;
options . addAll ( doubleArguments ) ;
return options ;
}
else if ( args . length = = 2 )
{
if ( args [ 0 ] . equals ( " -o " ) )
{
return FUtil . getPlayerList ( ) ;
}
else
{
if ( doubleArguments . contains ( args [ 0 ] ) )
{
if ( args [ 0 ] . equals ( " clearip " ) )
{
List < String > ips = plugin . al . getAdmin ( sender ) . getIps ( ) ;
2020-07-01 01:51:06 +00:00
ips . remove ( FUtil . getIp ( ( Player ) sender ) ) ;
2020-01-25 06:27:16 +00:00
return ips ;
}
}
}
}
else if ( args . length = = 3 )
{
if ( args [ 0 ] . equals ( " -o " ) )
{
List < String > options = new ArrayList < > ( ) ;
options . addAll ( singleArguments ) ;
options . addAll ( doubleArguments ) ;
return options ;
}
}
else if ( args . length = = 4 )
{
if ( args [ 0 ] . equals ( " -o " ) & & args [ 2 ] . equals ( " clearip " ) )
{
Admin admin = plugin . al . getEntryByName ( args [ 1 ] ) ;
if ( admin ! = null )
{
return admin . getIps ( ) ;
}
}
}
return FUtil . getPlayerList ( ) ;
}
2016-05-12 19:40:39 +00:00
}