2017-11-16 22:32:09 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.command;
|
|
|
|
|
2017-11-27 07:06:39 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.rank.Rank;
|
|
|
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
2017-11-16 22:32:09 +00:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
2017-11-27 07:06:39 +00:00
|
|
|
import org.bukkit.entity.Player;
|
2017-11-16 22:32:09 +00:00
|
|
|
|
|
|
|
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
|
2017-11-27 07:06:39 +00:00
|
|
|
@CommandParameters(description = "Essentials Interface Command - Rainbowify your nickname.", usage = "/<command> <nick>")
|
2017-11-16 22:32:09 +00:00
|
|
|
public class Command_rainbownick extends FreedomCommand
|
|
|
|
{
|
|
|
|
|
2017-11-27 07:06:39 +00:00
|
|
|
@Override
|
|
|
|
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
2017-11-16 22:32:09 +00:00
|
|
|
{
|
|
|
|
if (args.length != 1)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
final String nickPlain = ChatColor.stripColor(FUtil.colorize(args[0].trim()));
|
|
|
|
|
|
|
|
if (!nickPlain.matches("^[a-zA-Z_0-9" + ChatColor.COLOR_CHAR + "]+$"))
|
|
|
|
{
|
|
|
|
msg("That nickname contains invalid characters.");
|
|
|
|
return true;
|
|
|
|
}
|
2018-07-31 06:41:56 +00:00
|
|
|
|
2019-10-20 22:02:11 +00:00
|
|
|
if (nickPlain.length() < 3 || nickPlain.length() > 30)
|
2017-11-16 22:32:09 +00:00
|
|
|
{
|
2019-10-20 22:02:11 +00:00
|
|
|
msg("Your nickname must be between 3 and 30 characters long.");
|
2017-11-16 22:32:09 +00:00
|
|
|
return true;
|
|
|
|
}
|
2017-11-27 07:06:39 +00:00
|
|
|
|
|
|
|
for (Player player : Bukkit.getOnlinePlayers())
|
2017-11-16 22:32:09 +00:00
|
|
|
{
|
|
|
|
if (player == playerSender)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (player.getName().equalsIgnoreCase(nickPlain) || ChatColor.stripColor(player.getDisplayName()).trim().equalsIgnoreCase(nickPlain))
|
|
|
|
{
|
2017-11-27 07:06:39 +00:00
|
|
|
msg("That nickname is already in use.");
|
2017-11-16 22:32:09 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2018-07-31 06:41:56 +00:00
|
|
|
|
2017-11-27 07:06:39 +00:00
|
|
|
final String newNick = FUtil.rainbowify(ChatColor.stripColor(FUtil.colorize(nickPlain)));
|
2018-07-31 06:41:56 +00:00
|
|
|
|
2017-11-27 07:06:39 +00:00
|
|
|
plugin.esb.setNickname(sender.getName(), newNick);
|
|
|
|
|
|
|
|
msg("Your nickname is now: " + newNick);
|
|
|
|
|
2017-11-16 22:32:09 +00:00
|
|
|
return true;
|
|
|
|
}
|
2019-10-20 22:02:11 +00:00
|
|
|
}
|