package com.github.niwaniwa.we.core.command;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.bukkit.Sound;
import org.bukkit.command.Command;

import com.github.niwaniwa.we.core.api.WhiteEggAPI;
import com.github.niwaniwa.we.core.command.abs.ConsoleCancellable;
import com.github.niwaniwa.we.core.command.abs.core.WhiteEggCoreLowCommandExecutor;
import com.github.niwaniwa.we.core.player.WhitePlayer;
import com.github.niwaniwa.we.core.player.commad.WhiteCommandSender;
import com.github.niwaniwa.we.core.util.Util;

/**
 * Whisperのコマンドクラス
 * @author nwianiwa
 *
 */
public class WhiteEggWhisperCommand extends WhiteEggCoreLowCommandExecutor implements ConsoleCancellable{

	private static final Map<WhitePlayer, WhitePlayer> replay = new HashMap<>();

	private final String key = commandMessageKey + ".whisper";
	private final String permission = commandPermission + ".whisper";

	@Override
	public boolean onCommand(WhiteCommandSender sender, Command cmd, String label, String[] args) {
		if(!sender.hasPermission(permission)){
			sender.sendMessage(msg.getMessage(sender, error_Permission, "", true));
			return true;
		}
		if(args.length <= 1){
			sendUsing((WhitePlayer) sender);
			return true;
		}
		WhitePlayer player = (WhitePlayer) sender;
		WhitePlayer target = WhiteEggAPI.getPlayer(args[0]);
		if(target == null){
			sender.sendMessage(msg.getMessage(player, error_Player, msgPrefix, true));
			return true;
		}
		if(player.getUniqueId().equals(target.getUniqueId())){
			return true;
		}
		String message = Util.build(args, 1);
		target.sendMessage(replace(msg.getMessage(target, key + ".format", "", true), player, target, message));
		player.sendMessage(replace(msg.getMessage(player, key + ".format", "", true), player, target, message));
		target.getPlayer().playSound(target.getPlayer().getLocation(), Sound.CHICKEN_EGG_POP, 1, 1);
		replay.put(target, player);
		return true;
	}

	private String replace(String s, WhitePlayer from, WhitePlayer to, String message){
		return s.replace("%from", from.getName()).replace("%to", to.getName()).replace("%message", message);
	}

	@Override
	public void sendUsing(WhitePlayer sender) {
		sender.sendMessage("");
	}

	@Override
	public String getPermission() {
		return permission;
	}

	public static Map<WhitePlayer, WhitePlayer> getPlayer(){
		return replay;
	}

	@Override
	public String getCommandName() {
		return "whisper";
	}

	@Override
	public List<String> getUsing() {
		return Arrays.asList("");
	}

}

@@ -2064,16 +2064,17 @@
 e(%22%25from
+%25
 %22, from.
@@ -2096,16 +2096,17 @@
 ace(%22%25to
+%25
 %22, to.ge
@@ -2131,16 +2131,17 @@
 %25message
+%25
 %22, messa
@@ -2227,16 +2227,23 @@
 essage(%22
+&6! %CF%89 !
 %22);%0A%09%7D%0A%0A

Change message