2020-07-14 00:52:53 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.command;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
import me.totalfreedom.totalfreedommod.rank.Rank;
|
|
|
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.Color;
|
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
|
2020-07-14 21:56:36 +00:00
|
|
|
@CommandParameters(description = "Essentials Interface Command - Rainbowify your nickname.", usage = "/<command> <hex> <hex> <nick>", aliases = "nickgr")
|
2020-07-14 00:52:53 +00:00
|
|
|
public class Command_nickgradient extends FreedomCommand
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
|
|
|
{
|
2022-11-14 06:20:46 +00:00
|
|
|
if (!server.getPluginManager().isPluginEnabled("Essentials"))
|
|
|
|
{
|
|
|
|
msg("Essentials is not enabled on this server.");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-07-14 00:52:53 +00:00
|
|
|
if (args.length != 3)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
String nick = args[2].trim();
|
|
|
|
|
|
|
|
if (nick.length() < 3 || nick.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(nick) || ChatColor.stripColor(player.getDisplayName()).trim().equalsIgnoreCase(nick))
|
|
|
|
{
|
|
|
|
msg("That nickname is already in use.");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-15 04:23:26 +00:00
|
|
|
String from = "", to = "";
|
2020-07-14 00:52:53 +00:00
|
|
|
java.awt.Color awt1, awt2;
|
|
|
|
try
|
|
|
|
{
|
2020-07-15 04:23:26 +00:00
|
|
|
if (args[0].equalsIgnoreCase("random") ||
|
|
|
|
args[0].equalsIgnoreCase("r"))
|
|
|
|
{
|
|
|
|
awt1 = FUtil.getRandomAWTColor();
|
|
|
|
from = " (From: " + FUtil.getHexStringOfAWTColor(awt1) + ")";
|
|
|
|
}
|
|
|
|
else
|
2020-12-04 00:28:53 +00:00
|
|
|
{
|
2020-07-15 04:23:26 +00:00
|
|
|
awt1 = java.awt.Color.decode(args[0]);
|
2020-12-04 00:28:53 +00:00
|
|
|
}
|
2020-07-15 04:23:26 +00:00
|
|
|
if (args[1].equalsIgnoreCase("random") ||
|
|
|
|
args[1].equalsIgnoreCase("r"))
|
|
|
|
{
|
|
|
|
awt2 = FUtil.getRandomAWTColor();
|
|
|
|
to = " (To: " + FUtil.getHexStringOfAWTColor(awt2) + ")";
|
|
|
|
}
|
|
|
|
else
|
2020-12-04 00:28:53 +00:00
|
|
|
{
|
2020-07-15 04:23:26 +00:00
|
|
|
awt2 = java.awt.Color.decode(args[1]);
|
2020-12-04 00:28:53 +00:00
|
|
|
}
|
2020-07-14 00:52:53 +00:00
|
|
|
}
|
|
|
|
catch (NumberFormatException ex)
|
|
|
|
{
|
|
|
|
msg("Invalid hex values.");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
Color c1 = FUtil.fromAWT(awt1);
|
|
|
|
Color c2 = FUtil.fromAWT(awt2);
|
|
|
|
List<Color> gradient = FUtil.createColorGradient(c1, c2, nick.length());
|
|
|
|
String[] splitNick = nick.split("");
|
|
|
|
for (int i = 0; i < splitNick.length; i++)
|
|
|
|
{
|
|
|
|
splitNick[i] = net.md_5.bungee.api.ChatColor.of(FUtil.toAWT(gradient.get(i))) + splitNick[i];
|
|
|
|
}
|
|
|
|
nick = StringUtils.join(splitNick, "");
|
|
|
|
final String outputNick = FUtil.colorize(nick);
|
|
|
|
|
|
|
|
plugin.esb.setNickname(sender.getName(), outputNick);
|
|
|
|
|
2020-07-15 04:23:26 +00:00
|
|
|
msg("Your nickname is now: '" + outputNick + ChatColor.GRAY + "'" + from + to);
|
2020-07-14 00:52:53 +00:00
|
|
|
return true;
|
|
|
|
}
|
2020-12-04 00:28:53 +00:00
|
|
|
}
|