From 6202fc07207ed47a3eb4324c39ff703d4708d729 Mon Sep 17 00:00:00 2001 From: SofianeLasri <alasri250@gmail.com> Date: Mon, 2 May 2022 23:06:28 +0200 Subject: [PATCH] =?UTF-8?q?Probl=C3=A8me=20=C3=A9clairci=20et=20suppresion?= =?UTF-8?q?=20du=20champs=20ip.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/runConfigurations.xml | 10 ------- SLCraftPlugin.iml | 13 +++++++++ .../tachesParalleles/internalWebServer.java | 29 ++++++++++++++----- target/maven-archiver/pom.properties | 4 +-- 4 files changed, 37 insertions(+), 19 deletions(-) delete mode 100644 .idea/runConfigurations.xml create mode 100644 SLCraftPlugin.iml diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml deleted file mode 100644 index 797acea..0000000 --- a/.idea/runConfigurations.xml +++ /dev/null @@ -1,10 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<project version="4"> - <component name="RunConfigurationProducerService"> - <option name="ignoredProducers"> - <set> - <option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" /> - </set> - </option> - </component> -</project> \ No newline at end of file diff --git a/SLCraftPlugin.iml b/SLCraftPlugin.iml new file mode 100644 index 0000000..f5de878 --- /dev/null +++ b/SLCraftPlugin.iml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module version="4"> + <component name="FacetManager"> + <facet type="minecraft" name="Minecraft"> + <configuration> + <autoDetectTypes> + <platformType>PAPER</platformType> + <platformType>ADVENTURE</platformType> + </autoDetectTypes> + </configuration> + </facet> + </component> +</module> \ No newline at end of file diff --git a/src/main/java/com/slprojects/slcraftplugin/tachesParalleles/internalWebServer.java b/src/main/java/com/slprojects/slcraftplugin/tachesParalleles/internalWebServer.java index 267ac51..563c28b 100644 --- a/src/main/java/com/slprojects/slcraftplugin/tachesParalleles/internalWebServer.java +++ b/src/main/java/com/slprojects/slcraftplugin/tachesParalleles/internalWebServer.java @@ -3,7 +3,6 @@ package com.slprojects.slcraftplugin.tachesParalleles; import com.slprojects.slcraftplugin.Main; import org.bukkit.ChatColor; import org.bukkit.entity.Player; -import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; @@ -27,13 +26,15 @@ public class internalWebServer { while (true) { Socket client = serverSocket.accept(); + //plugin.getServer().getConsoleSender().sendMessage("Nouvelle connexion sur le port " + ChatColor.GOLD + serverPort); + // Get input and output streams to talk to the client BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream())); PrintWriter out = new PrintWriter(client.getOutputStream()); // Start sending our reply, using the HTTP 1.1 protocol out.print("HTTP/1.1 200 \r\n"); // Version & status code - out.print("Content-Type: text/plain\r\n"); // The type of data + out.print("Content-Type: application/json\r\n"); // The type of data out.print("Connection: close\r\n"); // Will close stream out.print("\r\n"); // End of headers @@ -64,6 +65,7 @@ public class internalWebServer { // On récupère le nom de la commande String commandName = split2[1]; + JSONObject answer = new JSONObject(); switch (commandName) { case "discordMsg": JSONObject json = (JSONObject) new JSONParser().parse(URLDecoder.decode(split2[2], "UTF-8")); @@ -75,20 +77,33 @@ public class internalWebServer { p.sendMessage(ChatColor.DARK_PURPLE + playerName + ChatColor.WHITE + ": " + message); } plugin.getServer().getConsoleSender().sendMessage(ChatColor.DARK_PURPLE + playerName + ": " + message); - out.print("Message envoyé !"); + answer.put("status", "ok"); + out.print(answer.toJSONString()); break; case "getPlayers": + plugin.getServer().getConsoleSender().sendMessage("getPlayers"); // On renvoie la liste des joueurs JSONObject listToReturn = new JSONObject(); - JSONArray players = new JSONArray(); - for (Player p : plugin.getServer().getOnlinePlayers()) { - players.add(p.getName()); + JSONObject players = new JSONObject(); + + // On vérifie qu'il y a des joueurs -> pas vraiment utile vu que le timeout ne viens pas d'ici + //TODO: Corriger le timeout et supprimer la condition + if( plugin.getServer().getOnlinePlayers().size() > 0 ) { + for (Player p : plugin.getServer().getOnlinePlayers()) { + JSONObject playerInfos = new JSONObject(); + playerInfos.put("username", p.getName()); + playerInfos.put("uuid", p.getUniqueId().toString()); + players.put(p.getName(), playerInfos); + } + } listToReturn.put("players", players); out.print(listToReturn.toJSONString()); break; default: - out.print("La commande \"" + commandName + "\" n'est pas reconnue.\r\n"); + answer.put("status", "error"); + answer.put("message", "Commande "+commandName+" inconnue"); + out.print(answer.toJSONString()); break; } } diff --git a/target/maven-archiver/pom.properties b/target/maven-archiver/pom.properties index ae5e44b..6e9b8e5 100644 --- a/target/maven-archiver/pom.properties +++ b/target/maven-archiver/pom.properties @@ -1,5 +1,5 @@ #Generated by Maven -#Thu Apr 07 19:00:13 CEST 2022 -artifactId=SLCraftPlugin +#Mon May 02 23:05:52 CEST 2022 groupId=com.slprojects +artifactId=SLCraftPlugin version=1.6.0 -- GitLab