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;
|
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;
|
2022-11-14 06:20:46 +00:00
|
|
|
import java.util.Arrays;
|
2013-09-24 14:13:38 +00:00
|
|
|
|
2016-03-06 15:56:15 +00:00
|
|
|
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
|
2020-03-30 23:43:57 +00:00
|
|
|
@CommandParameters(description = "Essentials Interface Command - Randomize the colors of 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
|
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
|
|
|
{
|
2022-11-14 06:20:46 +00:00
|
|
|
if (!server.getPluginManager().isPluginEnabled("Essentials"))
|
|
|
|
{
|
|
|
|
msg("Essentials is not enabled on this server.");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-09-24 14:13:38 +00:00
|
|
|
if (args.length != 1)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-12-04 00:28:53 +00:00
|
|
|
if (args[0].equalsIgnoreCase("off"))
|
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;
|
|
|
|
}
|
2019-10-20 22:02:11 +00:00
|
|
|
else if (nickPlain.length() < 3 || nickPlain.length() > 30)
|
2013-09-24 14:13:38 +00:00
|
|
|
{
|
2019-10-20 22:02:11 +00:00
|
|
|
msg("Your nickname must be between 3 and 30 characters long.");
|
2013-09-24 14:13:38 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-11-14 06:20:46 +00:00
|
|
|
|
|
|
|
if (server.getOnlinePlayers().stream().anyMatch(player -> player != playerSender
|
|
|
|
&& (player.getName().equalsIgnoreCase(nickPlain)
|
|
|
|
|| ChatColor.stripColor(plugin.esb.getNickname(player.getName())).trim().equalsIgnoreCase(nickPlain))))
|
2013-09-24 14:13:38 +00:00
|
|
|
{
|
2022-11-14 06:20:46 +00:00
|
|
|
msg("That nickname is already in use.");
|
|
|
|
return true;
|
2013-09-24 14:13:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
final StringBuilder newNick = new StringBuilder();
|
2022-11-14 06:20:46 +00:00
|
|
|
Arrays.stream(nickPlain.chars().toArray()).forEach(character -> newNick.append(FUtil.randomChatColor())
|
|
|
|
.append(Character.toString(character)));
|
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
|
|
|
|
2022-11-14 06:20:46 +00:00
|
|
|
msg("Your nickname is now: " + newNick);
|
2013-09-24 14:13:38 +00:00
|
|
|
return true;
|
|
|
|
}
|
2020-12-04 00:28:53 +00:00
|
|
|
}
|