On peut maintenant envoyer un message privé de la console vers la console (avec le NetworkAPI)

This commit is contained in:
Marc Baloup 2015-02-22 01:09:27 -05:00
parent 0c3ca5087a
commit db9dc346ac

View File

@ -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, "");
}