2015-10-19 17:43:46 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.commands;
|
2013-09-24 14:13:38 +00:00
|
|
|
|
2015-11-15 23:32:04 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
|
2015-10-19 17:43:46 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
2014-12-21 09:23:50 +00:00
|
|
|
import org.bukkit.Bukkit;
|
2013-09-24 14:13:38 +00:00
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
@CommandPermissions(level = PlayerRank.OP, source = SourceType.ONLY_IN_GAME)
|
2013-09-24 14:13:38 +00:00
|
|
|
@CommandParameters(description = "Essentials Interface Command - Nyanify your nickname.", usage = "/<command> <<nick> | off>")
|
2015-10-19 17:43:46 +00:00
|
|
|
public class Command_nicknyan extends FreedomCommand
|
2013-09-24 14:13:38 +00:00
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
|
|
|
{
|
|
|
|
if (args.length != 1)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-05 13:31:12 +00:00
|
|
|
if ("off".equals(args[0]))
|
2013-09-24 14:13:38 +00:00
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
plugin.esb.setNickname(sender.getName(), null);
|
2013-09-24 14:13:38 +00:00
|
|
|
playerMsg("Nickname cleared.");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
final String nickPlain = ChatColor.stripColor(FUtil.colorize(args[0].trim()));
|
2013-09-24 14:13:38 +00:00
|
|
|
|
|
|
|
if (!nickPlain.matches("^[a-zA-Z_0-9\u00a7]+$"))
|
|
|
|
{
|
|
|
|
playerMsg("That nickname contains invalid characters.");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (nickPlain.length() < 4 || nickPlain.length() > 30)
|
|
|
|
{
|
|
|
|
playerMsg("Your nickname must be between 4 and 30 characters long.");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-12-21 09:23:50 +00:00
|
|
|
for (Player player : Bukkit.getOnlinePlayers())
|
2013-09-24 14:13:38 +00:00
|
|
|
{
|
|
|
|
if (player == sender_p)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2013-09-25 00:32:04 +00:00
|
|
|
if (player.getName().equalsIgnoreCase(nickPlain) || ChatColor.stripColor(player.getDisplayName()).trim().equalsIgnoreCase(nickPlain))
|
2013-09-24 14:13:38 +00:00
|
|
|
{
|
|
|
|
playerMsg("That nickname is already in use.");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
final StringBuilder newNick = new StringBuilder();
|
|
|
|
|
|
|
|
final char[] chars = nickPlain.toCharArray();
|
|
|
|
for (char c : chars)
|
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
newNick.append(FUtil.randomChatColor()).append(c);
|
2013-09-24 14:13:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
newNick.append(ChatColor.WHITE);
|
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
plugin.esb.setNickname(sender.getName(), newNick.toString());
|
2013-09-24 14:13:38 +00:00
|
|
|
|
|
|
|
playerMsg("Your nickname is now: " + newNick.toString());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|