diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/network_api/request_executors/RequestExecutorPrivateMessage.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/network_api/request_executors/RequestExecutorPrivateMessage.java index c7d3d2b..9a10023 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/network_api/request_executors/RequestExecutorPrivateMessage.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/network_api/request_executors/RequestExecutorPrivateMessage.java @@ -1,6 +1,7 @@ package net.mc_pandacraft.java.plugin.pandacraftutils.network_api.request_executors; import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import com.earth2me.essentials.CommandSource; @@ -25,34 +26,56 @@ public class RequestExecutorPrivateMessage extends AbstractRequestExecutor { if (dataSplit.length != 3) return new Response(false, "bad_data : at least two space"); + PermissionUser permUser = PermissionsEx.getUser(dataSplit[0]); if (permUser == null) return new Response(false, "user_src_not_exist : user is not registered in permission plugin"); - Player p = plugin.getServer().getPlayer(dataSplit[1]); + CommandSender cible; + String cibleName; - if (p == null || !p.isOnline()) { - plugin.getLogger().warning(ChatColor.RED+dataSplit[1]+" n'est pas en ligne"); - return new Response(false, "user_dest_not_online"); + if (dataSplit[1].equalsIgnoreCase("console")) { + cible = plugin.getServer().getConsoleSender(); + cibleName = cible.getName(); } + else { + Player p = plugin.getServer().getPlayer(dataSplit[1]); + + if (p == null || !p.isOnline()) { + plugin.getLogger().warning(ChatColor.RED+dataSplit[1]+" n'est pas en ligne"); + return new Response(false, "user_dest_not_online"); + } + + cible = p; + cibleName = p.getDisplayName(); + } + + String displayName = "["+ChatColor.GRAY+"Console"+ChatColor.GOLD+"]"+permUser.getPrefix() + permUser.getName() + permUser.getSuffix(); String finalMessageToUser = ChatColor.GOLD+"["+displayName+ChatColor.GOLD+" -> moi] "+ChatColor.RESET+dataSplit[2]; - String finalMessageToConsole = ChatColor.GOLD+"["+displayName+ChatColor.GOLD+" -> "+p.getDisplayName()+ChatColor.GOLD+"] "+ChatColor.RESET+dataSplit[2]; + String finalMessageToConsole = ChatColor.GOLD+"["+displayName+ChatColor.GOLD+" -> "+cibleName+ChatColor.GOLD+"] "+ChatColor.RESET+dataSplit[2]; plugin.getServer().getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', finalMessageToConsole)); - p.sendMessage(ChatColor.translateAlternateColorCodes('&', finalMessageToUser)); - if (!OnlinePlayerManager.get(p).hasReceiveMessageFromNetworkAPI()) { - p.sendMessage(ChatColor.GREEN+"Répondez à un message venant de la console avec "+ChatColor.GRAY+"/m console"); + + + if (cible instanceof Player) { + Player p = (Player) cible; + p.sendMessage(ChatColor.translateAlternateColorCodes('&', finalMessageToUser)); + + if (!OnlinePlayerManager.get(p).hasReceiveMessageFromNetworkAPI()) { + p.sendMessage(ChatColor.GREEN+"Répondez à un message venant de la console avec "+ChatColor.GRAY+"/m console"); + } + EssentialsInterface.getPlayer(p).setReplyTo(new CommandSource(plugin.getServer().getConsoleSender())); } - EssentialsInterface.getPlayer(p).setReplyTo(new CommandSource(plugin.getServer().getConsoleSender())); - Console.getConsoleReplyTo().setReplyTo(new CommandSource(p)); + Console.getConsoleReplyTo().setReplyTo(new CommandSource(cible)); + return new Response(true, ""); }