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 ;
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 ;
2020-08-15 22:58:48 +00:00
import me.totalfreedom.totalfreedommod.staff.StaffMember ;
2016-05-12 19:40:39 +00:00
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-09-28 03:17:01 +00:00
@CommandPermissions ( level = Rank . ADMIN , source = SourceType . ONLY_IN_GAME )
2020-08-15 16:35:48 +00:00
@CommandParameters ( description = " Manage your staff entry. " , usage = " /<command> [-o <staff member>] <clearips | clearip <ip> | setlogin <message> | clearlogin | setscformat <format> | clearscformat> | oldtags | logstick | syncroles> " )
2020-10-02 09:27:06 +00:00
public class Command_myadmin extends FreedomCommand
2016-05-12 19:40:39 +00:00
{
@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 ;
2020-09-14 09:36:25 +00:00
StaffMember target = getStaffMember ( playerSender ) ;
2016-05-12 19:40:39 +00:00
Player targetPlayer = playerSender ;
// -o switch
if ( args [ 0 ] . equals ( " -o " ) )
{
2020-09-28 02:51:15 +00:00
checkRank ( Rank . SENIOR_ADMIN ) ;
2016-05-12 19:40:39 +00:00
init = playerSender ;
targetPlayer = getPlayer ( args [ 1 ] ) ;
if ( targetPlayer = = null )
{
msg ( FreedomCommand . PLAYER_NOT_FOUND ) ;
return true ;
}
2016-08-26 09:42:13 +00:00
2020-09-14 09:36:25 +00:00
target = getStaffMember ( targetPlayer ) ;
2016-05-12 19:40:39 +00:00
if ( target = = null )
{
2020-08-15 22:42:46 +00:00
msg ( " That player is not a staff member " , 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 )
{
2020-08-15 22:42:46 +00:00
FUtil . staffAction ( sender . getName ( ) , " Clearing my IPs " , true ) ;
2016-05-12 19:40:39 +00:00
}
else
{
2020-08-15 22:42:46 +00:00
FUtil . staffAction ( sender . getName ( ) , " Clearing " + target . getName ( ) + " ' IPs " , true ) ;
2016-05-12 19:40:39 +00:00
}
int counter = target . getIps ( ) . size ( ) - 1 ;
target . clearIPs ( ) ;
target . addIp ( targetIp ) ;
2020-08-15 22:42:46 +00:00
plugin . sl . save ( target ) ;
plugin . sl . 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
{
2020-08-15 22:42:46 +00:00
msg ( " You cannot remove that staff members's current IP. " ) ;
2016-05-12 19:40:39 +00:00
}
return true ;
}
2020-08-15 22:42:46 +00:00
FUtil . staffAction ( sender . getName ( ) , " Removing an IP " + ( init = = null ? " " : " from " + targetPlayer . getName ( ) + " 's IPs " ) , true ) ;
2016-05-12 19:40:39 +00:00
target . removeIp ( args [ 1 ] ) ;
2020-08-15 22:42:46 +00:00
plugin . sl . save ( target ) ;
plugin . sl . 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 ( " Removed IP " + args [ 1 ] ) ;
msg ( " Current IPs: " + StringUtils . join ( target . getIps ( ) , " , " ) ) ;
return true ;
}
2020-08-15 22:42:46 +00:00
case " setscformat " :
2018-06-01 22:40:25 +00:00
{
String format = StringUtils . join ( args , " " , 1 , args . length ) ;
target . setAcFormat ( format ) ;
2020-08-15 22:42:46 +00:00
plugin . sl . save ( target ) ;
plugin . sl . updateTables ( ) ;
msg ( " Set staff chat format to \" " + format + " \" . " , ChatColor . GRAY ) ;
2020-09-28 03:17:01 +00:00
String example = format . replace ( " %name% " , " ExampleStaff " ) . replace ( " %rank% " , Rank . ADMIN . getAbbr ( ) ) . replace ( " %rankcolor% " , Rank . 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 ;
}
2020-08-15 16:35:48 +00:00
2020-08-15 22:42:46 +00:00
case " clearscformat " :
2018-06-01 22:40:25 +00:00
{
target . setAcFormat ( null ) ;
2020-08-15 22:42:46 +00:00
plugin . sl . save ( target ) ;
plugin . sl . updateTables ( ) ;
msg ( " Cleared staff chat format. " , ChatColor . GRAY ) ;
2018-06-01 22:40:25 +00:00
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 ;
}
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 )
{
2020-08-15 22:42:46 +00:00
if ( ! plugin . sl . isStaff ( sender ) )
2020-01-25 06:27:16 +00:00
{
return Collections . emptyList ( ) ;
}
2020-10-02 09:27:06 +00:00
List < String > singleArguments = Arrays . asList ( " clearips " , " setscformat " ) ;
List < String > doubleArguments = Arrays . asList ( " clearip " , " clearscformat " , " 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 " ) )
{
2020-08-15 22:42:46 +00:00
List < String > ips = plugin . sl . getAdmin ( sender ) . getIps ( ) ;
2020-08-15 16:35:48 +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 " ) )
{
2020-08-15 22:42:46 +00:00
StaffMember staffMember = plugin . sl . getEntryByName ( args [ 1 ] ) ;
if ( staffMember ! = null )
2020-01-25 06:27:16 +00:00
{
2020-08-15 22:42:46 +00:00
return staffMember . getIps ( ) ;
2020-01-25 06:27:16 +00:00
}
}
}
return FUtil . getPlayerList ( ) ;
}
2016-05-12 19:40:39 +00:00
}