Skip to content
Snippets Groups Projects
Commit 6202fc07 authored by Sofiane Lasri's avatar Sofiane Lasri
Browse files

Problème éclairci et suppresion du champs ip.

parent 692abb22
Branches
Tags
No related merge requests found
<?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
<?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
......@@ -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();
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()) {
players.add(p.getName());
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;
}
}
......
#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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment