2016-03-02 19:28:01 +00:00
package me.totalfreedom.totalfreedommod.command ;
2014-08-14 23:07:52 +00:00
import java.util.regex.Matcher ;
import java.util.regex.Pattern ;
2017-12-23 04:07:36 +00:00
import me.totalfreedom.totalfreedommod.config.ConfigEntry ;
2016-03-06 15:56:15 +00:00
import me.totalfreedom.totalfreedommod.rank.Rank ;
2015-10-19 17:43:46 +00:00
import me.totalfreedom.totalfreedommod.util.FUtil ;
2019-07-28 06:04:16 +00:00
import org.apache.commons.lang.StringUtils ;
2014-08-14 23:07:52 +00:00
import org.bukkit.ChatColor ;
import org.bukkit.command.Command ;
import org.bukkit.command.CommandSender ;
import org.bukkit.entity.Player ;
2016-03-06 15:56:15 +00:00
@CommandPermissions ( level = Rank . SUPER_ADMIN , source = SourceType . BOTH )
2020-06-30 07:25:38 +00:00
@CommandParameters ( description = " Essentials Interface Command - Remove illegal chatcodes from nicknames of one or all players on server. " , usage = " /<command> [player] " , aliases = " nc " )
2015-10-19 17:43:46 +00:00
public class Command_nickclean extends FreedomCommand
2014-08-14 23:07:52 +00:00
{
2015-11-22 18:26:47 +00:00
2017-12-23 04:07:36 +00:00
private static final String [ ] BLOCK = ConfigEntry . BLOCKED_CHATCODES . getString ( ) . split ( " , " ) ;
private static final Pattern REGEX = Pattern . compile ( FUtil . colorize ( ChatColor . COLOR_CHAR + " [ " + StringUtils . join ( BLOCK , " " ) + " ] " ) , Pattern . CASE_INSENSITIVE ) ;
2014-08-14 23:07:52 +00:00
@Override
2015-11-22 18:26:47 +00:00
public boolean run ( CommandSender sender , Player playerSender , Command cmd , String commandLabel , String [ ] args , boolean senderIsConsole )
2014-08-14 23:07:52 +00:00
{
2016-05-12 19:40:39 +00:00
FUtil . adminAction ( sender . getName ( ) , " Cleaning all nicknames " , false ) ;
2014-08-14 23:07:52 +00:00
2020-06-30 07:25:38 +00:00
if ( args . length > 1 )
2014-08-14 23:07:52 +00:00
{
2020-06-30 07:25:38 +00:00
Player player = getPlayer ( args [ 0 ] ) ;
if ( player = = null )
2014-08-14 23:07:52 +00:00
{
2020-06-30 07:25:38 +00:00
msg ( PLAYER_NOT_FOUND ) ;
return true ;
2014-08-14 23:07:52 +00:00
}
2020-06-30 07:25:38 +00:00
FUtil . adminAction ( sender . getName ( ) , " Cleaning " + player . getName ( ) + " 's nickname " , false ) ;
cleanNickname ( player ) ;
return true ;
}
FUtil . adminAction ( sender . getName ( ) , " Cleaning all nicknames " , false ) ;
for ( final Player player : server . getOnlinePlayers ( ) )
{
cleanNickname ( player ) ;
2014-08-14 23:07:52 +00:00
}
return true ;
}
2020-06-30 07:25:38 +00:00
public void cleanNickname ( Player player )
{
final String playerName = player . getName ( ) ;
final String nickName = plugin . esb . getNickname ( playerName ) ;
if ( nickName ! = null & & ! nickName . isEmpty ( ) & & ! nickName . equalsIgnoreCase ( playerName ) )
{
final Matcher matcher = REGEX . matcher ( nickName ) ;
if ( matcher . find ( ) )
{
final String newNickName = matcher . replaceAll ( " " ) ;
msg ( ChatColor . RESET + playerName + " : \" " + nickName + ChatColor . RESET + " \" -> \" " + newNickName + ChatColor . RESET + " \" . " ) ;
plugin . esb . setNickname ( playerName , newNickName ) ;
}
}
}
2014-08-14 23:07:52 +00:00
}