From 87df9c6e6e5e5ace54199431c56d81a50d2faf1c Mon Sep 17 00:00:00 2001
From: Sofiane Lasri-Trienpont <alasri250@gmail.com>
Date: Sun, 6 Mar 2022 22:55:53 +0100
Subject: [PATCH] 1.5

---
 .idea/compiler.xml                            |  1 +
 pom.xml                                       |  5 ---
 .../tachesParalleles/waitForDiscordMsg.java   | 41 ++++++++++++++++++-
 target/maven-archiver/pom.properties          |  2 +-
 4 files changed, 41 insertions(+), 8 deletions(-)

diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index bda5e65..25ac271 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -7,6 +7,7 @@
         <sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
         <outputRelativeToContentRoot value="true" />
         <module name="SLCraftPlugin" />
+        <module name="SL-Craft Plugin" />
       </profile>
     </annotationProcessing>
   </component>
diff --git a/pom.xml b/pom.xml
index 527b3ae..8855c8e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -88,10 +88,5 @@
             <version>2.11.1</version>
             <scope>provided</scope>
         </dependency>
-        <dependency>
-            <groupId>io.vertx</groupId>
-            <artifactId>vertx-web</artifactId>
-            <version>4.2.5</version>
-        </dependency>
     </dependencies>
 </project>
diff --git a/src/main/java/com/slprojects/slcraftplugin/tachesParalleles/waitForDiscordMsg.java b/src/main/java/com/slprojects/slcraftplugin/tachesParalleles/waitForDiscordMsg.java
index 756a17b..432d5ca 100644
--- a/src/main/java/com/slprojects/slcraftplugin/tachesParalleles/waitForDiscordMsg.java
+++ b/src/main/java/com/slprojects/slcraftplugin/tachesParalleles/waitForDiscordMsg.java
@@ -2,6 +2,10 @@ package com.slprojects.slcraftplugin.tachesParalleles;
 
 import com.slprojects.slcraftplugin.Main;
 import org.bukkit.ChatColor;
+import org.bukkit.entity.Player;
+import org.json.simple.JSONObject;
+import org.json.simple.parser.JSONParser;
+import org.json.simple.parser.ParseException;
 
 import java.io.BufferedReader;
 import java.io.IOException;
@@ -9,6 +13,7 @@ import java.io.InputStreamReader;
 import java.io.PrintWriter;
 import java.net.ServerSocket;
 import java.net.Socket;
+import java.net.URLDecoder;
 
 public class waitForDiscordMsg {
     public static void startServer(Main plugin){
@@ -45,8 +50,38 @@ public class waitForDiscordMsg {
                         while ((line = in.readLine()) != null) {
                             if (line.length() == 0)
                                 break;
-                            out.print(line + "\r\n");
-                            plugin.getLogger().info(line);
+                            //out.print(line + "\r\n");
+                            //plugin.getLogger().info(line);
+
+                            // On va regarder si la ligne commence par GET
+                            if (line.startsWith("GET")) {
+                                // On split par les espaces
+                                String[] split = line.split(" ");
+                                // Et on récupère le nom de la commande
+                                String command = split[1];
+
+                                // On split par des /
+                                String[] split2 = command.split("/");
+                                // On récupère le nom de la commande
+                                String commandName = split2[1];
+
+                                switch (commandName) {
+                                    case "discordMsg":
+                                        // On récupère le message
+                                        JSONObject json = (JSONObject) new JSONParser().parse(URLDecoder.decode(split2[2], "UTF-8"));
+                                        String message = json.get("message").toString();
+                                        String playerName = json.get("playerName").toString();
+
+                                        // On envoie le message aux joueurs
+                                        for(Player p : plugin.getServer().getOnlinePlayers()){
+                                            p.sendMessage(ChatColor.DARK_PURPLE + playerName + " : " + ChatColor.WHITE + message);
+                                        }
+                                        out.print("Message envoyé !");
+                                        break;
+                                    default:
+                                        out.print("La commande \""+commandName + "\" n'est pas reconnue.\r\n");
+                                }
+                            }
                         }
 
                         // Close socket, breaking the connection to the client, and
@@ -58,6 +93,8 @@ public class waitForDiscordMsg {
                 } catch (IOException e) {
                     plugin.getLogger().info(ChatColor.RED + "Erreur lors de l'écoute du port " + ChatColor.GOLD  + serverPort);
                     e.printStackTrace();
+                } catch (ParseException e) {
+                    e.printStackTrace();
                 }
             }
         };
diff --git a/target/maven-archiver/pom.properties b/target/maven-archiver/pom.properties
index d5775f3..c717738 100644
--- a/target/maven-archiver/pom.properties
+++ b/target/maven-archiver/pom.properties
@@ -1,5 +1,5 @@
 #Generated by Maven
-#Sun Mar 06 17:00:16 CET 2022
+#Sun Mar 06 22:53:05 CET 2022
 groupId=com.slprojects
 artifactId=SLCraftPlugin
 version=1.5
-- 
GitLab