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 ;
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 ;
2014-11-29 19:16:00 +00:00
import org.apache.commons.lang3.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 )
2014-08-14 23:07:52 +00:00
@CommandParameters ( description = " Essentials Interface Command - Remove distracting things from nicknames of all players on server. " , usage = " /<command> " , 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
2014-08-14 23:07:52 +00:00
private static final ChatColor [ ] BLOCKED = new ChatColor [ ]
{
ChatColor . MAGIC ,
ChatColor . STRIKETHROUGH ,
ChatColor . ITALIC ,
ChatColor . UNDERLINE ,
ChatColor . BLACK
} ;
2016-05-12 19:40:39 +00:00
private static final Pattern REGEX = Pattern . compile ( ChatColor . COLOR_CHAR + " [ " + StringUtils . join ( BLOCKED , " " ) + " ] " , 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
for ( final Player player : server . getOnlinePlayers ( ) )
{
final String playerName = player . getName ( ) ;
2015-10-19 17:43:46 +00:00
final String nickName = plugin . esb . getNickname ( playerName ) ;
2014-08-14 23:07:52 +00:00
if ( nickName ! = null & & ! nickName . isEmpty ( ) & & ! nickName . equalsIgnoreCase ( playerName ) )
{
final Matcher matcher = REGEX . matcher ( nickName ) ;
if ( matcher . find ( ) )
{
final String newNickName = matcher . replaceAll ( " " ) ;
2016-03-02 19:28:01 +00:00
msg ( ChatColor . RESET + playerName + " : \" " + nickName + ChatColor . RESET + " \" -> \" " + newNickName + ChatColor . RESET + " \" . " ) ;
2015-10-19 17:43:46 +00:00
plugin . esb . setNickname ( playerName , newNickName ) ;
2014-08-14 23:07:52 +00:00
}
}
}
return true ;
}
}