diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml deleted file mode 100644 index 797acea53eb091cf5b30518802c3073f544adeed..0000000000000000000000000000000000000000 --- 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 0000000000000000000000000000000000000000..f5de878b032bd6930370a575e7ca458c9c77e1bf --- /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 267ac51d7ca70fc9009eefcb5b0dc192a116a840..563c28bc47f0de0d02f9885d0a0081d7344819ac 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 ae5e44b9d9605462ea01f144c96bc6a689b69cd1..6e9b8e5775f6a68f622cb286a46e6ca6a50b637d 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