diff options
author | HacktheTime <l4bg0jb7@duck.com> | 2023-07-08 23:19:42 +0200 |
---|---|---|
committer | hackthetime <l4bg0jb7@duck.com> | 2023-09-05 08:20:23 +0200 |
commit | d1484a138c1a91b61f6f8bb72cb1855d6b12a523 (patch) | |
tree | 9a62fa8c300fe8fa93219b03f5935547be9fbddf /src/main/java/de/hype/bbsentials/api/FromChatSocket.java | |
parent | cdd951d912e172ea42fc9707a786db6e69ba2901 (diff) | |
download | BBsentials-d1484a138c1a91b61f6f8bb72cb1855d6b12a523.tar.gz BBsentials-d1484a138c1a91b61f6f8bb72cb1855d6b12a523.tar.bz2 BBsentials-d1484a138c1a91b61f6f8bb72cb1855d6b12a523.zip |
Initial commit
Diffstat (limited to 'src/main/java/de/hype/bbsentials/api/FromChatSocket.java')
-rw-r--r-- | src/main/java/de/hype/bbsentials/api/FromChatSocket.java | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/src/main/java/de/hype/bbsentials/api/FromChatSocket.java b/src/main/java/de/hype/bbsentials/api/FromChatSocket.java new file mode 100644 index 0000000..2af25a6 --- /dev/null +++ b/src/main/java/de/hype/bbsentials/api/FromChatSocket.java @@ -0,0 +1,91 @@ +package de.hype.bbsentials.api; + +import net.minecraft.client.MinecraftClient; + +import java.io.IOException; +import java.io.PrintWriter; +import java.net.Socket; + +public class FromChatSocket implements Runnable { + private Socket socket; + private Thread thread; + private PrintWriter out; + + // Konstruktor, um den Client-Thread zu starten + public FromChatSocket() { + // Starte den Client-Thread + /*thread = new Thread(this); + thread.start(); + System.out.println("Thread started");*/ + } + + // Implementierung der run() Methode des Runnable-Interfaces + public void run() { + try { + boolean connected = false; + // Endlosschleife, um auf Verbindung zum Server zu warten + while (true) { + try { + // Verbinden zum Server auf Port 8001 + socket = new Socket("localhost", 8001); + connected = true; + } catch (IOException e) { + System.out.println("Waiting for server on port 8001..."); + Thread.sleep(1000); // Warte 1 Sekunde, bevor erneut versucht wird, eine Verbindung aufzubauen + } + } + /*if (socket != null) { + // Erstelle einen BufferedReader, um Daten vom Socket zu lesen + BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream())); + boolean notNull = true; + // Endlosschleife, um auf eingehende Nachrichten zu warten + while (MinecraftClient.getInstance().isRunning() && socket.isConnected() && notNull) { + + } + + // Schließen des BufferedReader und des Sockets + in.close(); + socket.close(); + }*/ + } catch (Exception e) { + e.printStackTrace(); + } + } + + public boolean isInGame() { + MinecraftClient minecraft = MinecraftClient.getInstance(); + if (minecraft.world != null || minecraft.getNetworkHandler() != null) { + // Das Spiel befindet sich in einer Welt oder auf einem Server + return true; + } else { + // Das Spiel befindet sich im Hauptmenü oder in einem anderen Menü + return false; + } + } +} +/* +* try { + Thread.sleep(500); + } catch (InterruptedException e) { + } + String plOutput = mc.getNetworkHandler().onChat.getChatGUI().getChatComponent(0).getUnformattedText(); + List<String> partyMembers = Arrays.asList(plOutput.split("\\r?\\n")).stream() + .filter(s -> s.startsWith("Party Members:")) + .map(s -> s.substring(16).replaceAll(" ●", "")) + .collect(Collectors.toList()); + + mc.player.networkHandler.sendChatMessage("/p disband"); + try { + Thread.sleep(500); + } catch (InterruptedException e) { + } + String currentPlayer = String.valueOf(mc.player.getName()); + partyMembers.stream() + .filter(s -> !s.equals(currentPlayer)) + .forEach(s -> { + mc.player.networkHandler.sendChatMessage("/p invite " + s); + try { + Thread.sleep(300); + } catch (InterruptedException e) { + } + });*/
\ No newline at end of file |