mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-18 05:16:12 +00:00
293ea04c56
* rename everything containing staff back to admin (as requested by ryan i've renamed commands like slconfig to saconfig but left "slconfig" as an alias) * format almost every file correctly * a few other improvements
72 lines
2.3 KiB
Java
72 lines
2.3 KiB
Java
package me.totalfreedom.totalfreedommod.command;
|
|
|
|
import me.totalfreedom.totalfreedommod.rank.Rank;
|
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.ChatColor;
|
|
import org.bukkit.command.Command;
|
|
import org.bukkit.command.CommandSender;
|
|
import org.bukkit.entity.Player;
|
|
|
|
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
|
|
@CommandParameters(description = "Essentials Interface Command - Randomize the colors of your nickname.", usage = "/<command> <<nick> | off>")
|
|
public class Command_nicknyan extends FreedomCommand
|
|
{
|
|
|
|
@Override
|
|
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
|
{
|
|
if (args.length != 1)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (args[0].equalsIgnoreCase("off"))
|
|
{
|
|
plugin.esb.setNickname(sender.getName(), null);
|
|
msg("Nickname cleared.");
|
|
return true;
|
|
}
|
|
|
|
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;
|
|
}
|
|
else if (nickPlain.length() < 3 || nickPlain.length() > 30)
|
|
{
|
|
msg("Your nickname must be between 3 and 30 characters long.");
|
|
return true;
|
|
}
|
|
|
|
for (Player player : Bukkit.getOnlinePlayers())
|
|
{
|
|
if (player == playerSender)
|
|
{
|
|
continue;
|
|
}
|
|
if (player.getName().equalsIgnoreCase(nickPlain) || ChatColor.stripColor(player.getDisplayName()).trim().equalsIgnoreCase(nickPlain))
|
|
{
|
|
msg("That nickname is already in use.");
|
|
return true;
|
|
}
|
|
}
|
|
|
|
final StringBuilder newNick = new StringBuilder();
|
|
|
|
final char[] chars = nickPlain.toCharArray();
|
|
for (char c : chars)
|
|
{
|
|
newNick.append(FUtil.randomChatColor()).append(c);
|
|
}
|
|
|
|
newNick.append(ChatColor.WHITE);
|
|
|
|
plugin.esb.setNickname(sender.getName(), newNick.toString());
|
|
|
|
msg("Your nickname is now: " + newNick.toString());
|
|
return true;
|
|
}
|
|
} |