package com.enjin.averian_roleplay.core;

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 SetNameCommand implements CommandExecutor {

	private AverianCore plugin;

	public SetNameCommand(AverianCore plugin) {
		this.plugin = plugin;
	}

	@Override
	public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
		if (sender instanceof Player) {
			if (args.length >= 1) {
				Player player = (Player) sender;
				plugin.getCharacterCard(player).setName(args[0]);
				player.setDisplayName(args[0]);
				player.setCustomName(args[0]);
				player.setCustomNameVisible(true);
				sender.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("messages.setname.success")));
			} else {
				sender.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("messages.setname.more-arguments-needed")));
			}
		} else {
			sender.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("messages.setname.not-a-player")));
		}
		return true;
	}

}

@@ -554,201 +554,330 @@
 %09%09%09%09
-Player player = (Player) sen
+StringBuilder nameBuilder = new StringBuil
 der
+()
 ;%0A%09%09%09%09
-plugin.getCharacterCard(player).setName(args%5B0%5D
+for (int i = 0; i %3C args.length; i++) %7B%0A%09%09%09%09%09nameBuilder.append(args%5Bi%5D);%0A%09%09%09%09%09nameBuilder.append(%22 %22);%0A%09%09%09%09%7D%0A%09%09%09%09String name = nameBuilder.toString(
 );%0A%09%09%09%09
-p
+P
 layer
-.setDisplayName(args%5B0%5D);%0A%09%09%09%09
+ player = (Player) sender;%0A%09%09%09%09plugin.getCharacterCard(
 player
+)
 .set
-CustomName(args%5B0%5D);%0A%09%09%09%09player.setCustomNameVisible(tru
+Name(name);%0A%09%09%09%09player.setDisplayName(nam
 e);%0A

Allow names with more than one word