aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/hype/bbsentials/api
diff options
context:
space:
mode:
authorHacktheTime <l4bg0jb7@duck.com>2023-07-08 23:19:42 +0200
committerhackthetime <l4bg0jb7@duck.com>2023-09-05 08:20:23 +0200
commitd1484a138c1a91b61f6f8bb72cb1855d6b12a523 (patch)
tree9a62fa8c300fe8fa93219b03f5935547be9fbddf /src/main/java/de/hype/bbsentials/api
parentcdd951d912e172ea42fc9707a786db6e69ba2901 (diff)
downloadBBsentials-d1484a138c1a91b61f6f8bb72cb1855d6b12a523.tar.gz
BBsentials-d1484a138c1a91b61f6f8bb72cb1855d6b12a523.tar.bz2
BBsentials-d1484a138c1a91b61f6f8bb72cb1855d6b12a523.zip
Initial commit
Diffstat (limited to 'src/main/java/de/hype/bbsentials/api')
-rw-r--r--src/main/java/de/hype/bbsentials/api/FromChatSocket.java91
-rw-r--r--src/main/java/de/hype/bbsentials/api/receiveChatSocket.java111
2 files changed, 202 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
diff --git a/src/main/java/de/hype/bbsentials/api/receiveChatSocket.java b/src/main/java/de/hype/bbsentials/api/receiveChatSocket.java
new file mode 100644
index 0000000..7015810
--- /dev/null
+++ b/src/main/java/de/hype/bbsentials/api/receiveChatSocket.java
@@ -0,0 +1,111 @@
+package de.hype.bbsentials.api;
+
+import de.hype.bbsentials.client.BBsentials;
+import net.minecraft.client.MinecraftClient;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.net.ServerSocket;
+import java.net.Socket;
+
+public class receiveChatSocket implements Runnable {
+ private Thread thread;
+ private ServerSocket serverSocket;
+
+ // Konstruktor, um den Server-Thread zu starten
+ public receiveChatSocket() {
+ try {
+ // Erstelle einen Socket auf Port 8000
+ serverSocket = new ServerSocket(8000);
+ System.out.println("Server started");
+ // Starte den Server-Thread
+ thread = new Thread(this);
+ thread.start();
+ System.out.println("Thread startet");
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void sendServerMessage(String message) {
+ // Stellen Sie eine Verbindung zum Server her
+ if (message == null) {
+ System.out.println("Message is null: " + message);
+ } else {
+ BBsentials.getConfig().sender.addSendTask(message);
+ try {
+ Thread.sleep(50);
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ // Implementierung der run() Methode des Runnable-Interfaces
+ public void run() {
+ try {
+ // Endlosschleife, um auf eingehende Verbindungen zu warten
+ while (true) {
+ // Warten auf eine eingehende Verbindung
+ System.out.println("Waiting for incoming Chat Gen connection...");
+ Socket clientSocket = serverSocket.accept();
+ System.out.println("Chat Gen Client connected.");
+
+ // Erstelle einen BufferedReader, um Daten vom Socket zu lesen
+ BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
+ PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
+ boolean notNull = true;
+ // Endlosschleife, um auf eingehende Nachrichten zu warten
+ while (MinecraftClient.getInstance().isRunning() && clientSocket.isConnected() && notNull) {
+ System.out.println("running");
+ // Lesen der Nachricht vom Socket
+ String message = in.readLine();
+ out.println("Recieved the following message: " + message);
+
+ if (message.contains("fov")) {
+ Options.setFov(130);
+ }
+ // Senden der Nachricht an den Minecraft-Chat
+ while (!isInGame()) {
+ try {
+ Thread.sleep(1000); // Wartezeit in Millisekunden
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ sendServerMessage(message);
+ System.out.println("Message received and sent to Minecraft chat: " + message);
+ if (message == null) {
+ notNull = false;
+ } else {
+ Thread.sleep(300);
+ }
+ }
+
+
+ // Schließen des BufferedReader und des Sockets
+ in.close();
+ clientSocket.close();
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ 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;
+ }
+ }
+
+} \ No newline at end of file