diff --git a/NetworkAPI protocole.md b/NetworkAPI protocole.md index b2e59f3..b1b70b9 100644 --- a/NetworkAPI protocole.md +++ b/NetworkAPI protocole.md @@ -43,6 +43,10 @@ Pareil que `command` mais cette fois, celle-ci n'est pas forcément exécutée d Affiche un message sur le chat pour tout le monde connecté. Le message passé dans la partie **donnée** est diffusé en convertissant les codes couleurs `&x` en `§x` +#### `chat_send` +Affiche un message en tant qu'un joueur donné, sur le chat du serveur +La partie **donnée** de la requête contient d'abord le pseudo du joueur concerné, suivi d'un espace, suivi du message. + #### `player_list` Renvoi la liste des joueurs connectés, avec quelques infos utiles. diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/network_api/NetworkAPI.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/network_api/NetworkAPI.java index 797a90d..125a361 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/network_api/NetworkAPI.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/network_api/NetworkAPI.java @@ -1,6 +1,7 @@ package net.mc_pandacraft.java.plugin.pandacraftutils.network_api; import net.mc_pandacraft.java.plugin.pandacraftutils.network_api.request_executors.RequestExecutorBroadcast; +import net.mc_pandacraft.java.plugin.pandacraftutils.network_api.request_executors.RequestExecutorChatSend; import net.mc_pandacraft.java.plugin.pandacraftutils.network_api.request_executors.RequestExecutorCommand; import net.mc_pandacraft.java.plugin.pandacraftutils.network_api.request_executors.RequestExecutorCommandAsync; import net.mc_pandacraft.java.plugin.pandacraftutils.network_api.request_executors.RequestExecutorPlayerList; @@ -20,6 +21,7 @@ public class NetworkAPI { new RequestExecutorBroadcast(); new RequestExecutorCommandAsync(); new RequestExecutorPlayerList(); + new RequestExecutorChatSend(); } diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/network_api/NetworkAPIListener.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/network_api/NetworkAPIListener.java index 4f32f1e..0bf9938 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/network_api/NetworkAPIListener.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/network_api/NetworkAPIListener.java @@ -52,7 +52,6 @@ public class NetworkAPIListener extends Thread { private NetworkAPIListener() { super("NetworkAPI Listener"); - System.setProperty("file.encoding", "UTF-8"); plugin.getServer().getLogger().info("System property 'file.encoding' was set to 'UTF-8'"); diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/network_api/request_executors/RequestExecutorBroadcast.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/network_api/request_executors/RequestExecutorBroadcast.java index e24fa59..e159e43 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/network_api/request_executors/RequestExecutorBroadcast.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/network_api/request_executors/RequestExecutorBroadcast.java @@ -16,10 +16,7 @@ public class RequestExecutorBroadcast extends AbstractRequestExecutor { plugin.broadcast(ChatColor.translateAlternateColorCodes('&', data), false); - Response rep = new Response(); - rep.good = true; - rep.data = ""; - return rep; + return new Response(true, ""); } } diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/network_api/request_executors/RequestExecutorChatSend.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/network_api/request_executors/RequestExecutorChatSend.java new file mode 100644 index 0000000..44d4ae7 --- /dev/null +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/network_api/request_executors/RequestExecutorChatSend.java @@ -0,0 +1,39 @@ +package net.mc_pandacraft.java.plugin.pandacraftutils.network_api.request_executors; + +import org.bukkit.ChatColor; + +import ru.tehkode.permissions.PermissionUser; +import ru.tehkode.permissions.bukkit.PermissionsEx; +import net.mc_pandacraft.java.plugin.pandacraftutils.network_api.Response; + +public class RequestExecutorChatSend extends AbstractRequestExecutor { + + public RequestExecutorChatSend() { + super("chat_send"); + } + + @Override + protected Response run(String data) { + + String[] dataSplit = data.split(" ", 2); + if (dataSplit.length != 2) + return new Response(false, "bad_data : at least one space"); + + PermissionUser permUser = PermissionsEx.getUser(dataSplit[0]); + + if (permUser == null) + return new Response(false, "user_not_exist : user is not registered in permission plugin"); + + String displayName = permUser.getPrefix() + permUser.getName() + permUser.getSuffix(); + + + String finalMessage = "["+ChatColor.GRAY+"Console"+ChatColor.RESET+"]<"+displayName+ChatColor.RESET+"> "+dataSplit[1]; + + plugin.broadcast(ChatColor.translateAlternateColorCodes('&', finalMessage), false); + + return new Response(true, ""); + } + + + +}