2016-03-02 19:28:01 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.command;
|
2013-09-24 14:13:38 +00:00
|
|
|
|
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-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;
|
|
|
|
|
2016-03-06 15:56:15 +00:00
|
|
|
@CommandPermissions(level = Rank.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
|
|
|
{
|
2015-11-22 18:26:47 +00:00
|
|
|
|
2013-09-24 14:13:38 +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)
|
2013-09-24 14:13:38 +00:00
|
|
|
{
|
|
|
|
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);
|
2016-03-02 19:28:01 +00:00
|
|
|
msg("Nickname cleared.");
|
2013-09-24 14:13:38 +00:00
|
|
|
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
|
|
|
|
2015-11-22 18:26:47 +00:00
|
|
|
if (!nickPlain.matches("^[a-zA-Z_0-9" + ChatColor.COLOR_CHAR + "]+$"))
|
2013-09-24 14:13:38 +00:00
|
|
|
{
|
2016-03-02 19:28:01 +00:00
|
|
|
msg("That nickname contains invalid characters.");
|
2013-09-24 14:13:38 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (nickPlain.length() < 4 || nickPlain.length() > 30)
|
|
|
|
{
|
2016-03-02 19:28:01 +00:00
|
|
|
msg("Your nickname must be between 4 and 30 characters long.");
|
2013-09-24 14:13:38 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-12-21 09:23:50 +00:00
|
|
|
for (Player player : Bukkit.getOnlinePlayers())
|
2013-09-24 14:13:38 +00:00
|
|
|
{
|
2015-11-22 18:26:47 +00:00
|
|
|
if (player == playerSender)
|
2013-09-24 14:13:38 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
{
|
2016-03-02 19:28:01 +00:00
|
|
|
msg("That nickname is already in use.");
|
2013-09-24 14:13:38 +00:00
|
|
|
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
|
|
|
|
2016-03-02 19:28:01 +00:00
|
|
|
msg("Your nickname is now: " + newNick.toString());
|
2013-09-24 14:13:38 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|