From db9dc346ac04386f24e1e72670d9645182e82a03 Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Sun, 22 Feb 2015 01:09:27 -0500 Subject: [PATCH] =?UTF-8?q?On=20peut=20maintenant=20envoyer=20un=20message?= =?UTF-8?q?=20priv=C3=A9=20de=20la=20console=20vers=20la=20console=20(avec?= =?UTF-8?q?=20le=20NetworkAPI)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RequestExecutorPrivateMessage.java | 43 ++++++++++++++----- 1 file changed, 33 insertions(+), 10 deletions(-) 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, ""); }