code
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class NameColorCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
// Check if the sender has OP permission
if (!(sender instanceof Player) || !sender.isOp()) {
sender.sendMessage(ChatColor.RED + "You do not have permission to use this command.");
return true;
}
// Check if the command has enough arguments
if (args.length < 2) {
sender.sendMessage(ChatColor.RED + "Usage: /namecolor <player> <color>");
return true;
}
// Get the target player
Player target = sender.getServer().getPlayer(args[0]);
// Check if the target player is online
if (target == null) {
sender.sendMessage(ChatColor.RED + "Player not found or is not online.");
return true;
}
// Get the color argument
String color = args[1];
// Set the target player's name color in chat and tab list
target.setPlayerListName(ChatColor.translateAlternateColorCodes('&', color) + target.getName());
target.setDisplayName(ChatColor.translateAlternateColorCodes('&', color) + target.getName());
sender.sendMessage(ChatColor.GREEN + "Successfully changed " + target.getName() + "'s name color to " + color);
return true;
}
}