src/com/minecraft/bot folder created
This commit is contained in:
29
.vscode/launch.json
vendored
Normal file
29
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "java",
|
||||||
|
"name": "Current File",
|
||||||
|
"request": "launch",
|
||||||
|
"mainClass": "${file}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "java",
|
||||||
|
"name": "MCbot",
|
||||||
|
"request": "launch",
|
||||||
|
"mainClass": "MCbot",
|
||||||
|
"projectName": "minecraft-chatbot"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "java",
|
||||||
|
"name": "MCchatbotyt",
|
||||||
|
"request": "launch",
|
||||||
|
"mainClass": "MCchatbotyt",
|
||||||
|
"projectName": "minecraft-chatbot"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@@ -42,7 +42,6 @@ public class MCchatbotyt {
|
|||||||
|
|
||||||
// Get live chat ID for your live stream
|
// Get live chat ID for your live stream
|
||||||
String liveChatId = getLiveChatId("5lAKSeFQS2M");
|
String liveChatId = getLiveChatId("5lAKSeFQS2M");
|
||||||
|
|
||||||
|
|
||||||
// Poll for new chat messages every few seconds
|
// Poll for new chat messages every few seconds
|
||||||
while (true) {
|
while (true) {
|
||||||
@@ -53,6 +52,22 @@ public class MCchatbotyt {
|
|||||||
System.out.println("New message from " + author + ": " + text);
|
System.out.println("New message from " + author + ": " + text);
|
||||||
// Add your logic to handle incoming messages here
|
// Add your logic to handle incoming messages here
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Connect to the socket server in MCbot.java and send a command
|
||||||
|
try (Socket socket = new Socket("localhost", 8888);
|
||||||
|
PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
|
||||||
|
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()))) {
|
||||||
|
|
||||||
|
// Send command to MCbot.java
|
||||||
|
out.println("!players");
|
||||||
|
|
||||||
|
// Receive response from MCbot.java
|
||||||
|
String response = in.readLine();
|
||||||
|
System.out.println("Response from MCbot.java: " + response);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Thread.sleep(5000); // Poll every 5 seconds
|
Thread.sleep(5000); // Poll every 5 seconds
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
@@ -89,25 +104,4 @@ public class MCchatbotyt {
|
|||||||
LiveChatMessageListResponse response = liveChatRequest.execute();
|
LiveChatMessageListResponse response = liveChatRequest.execute();
|
||||||
return response.getItems();
|
return response.getItems();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Connect to the socket server in MCbot.java
|
|
||||||
Socket socket = new Socket("localhost", 12345); // Connect to localhost on port 12345
|
|
||||||
|
|
||||||
PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
|
|
||||||
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
|
||||||
|
|
||||||
// Send command to MCbot.java
|
|
||||||
out.println("!players");
|
|
||||||
|
|
||||||
// Receive response from MCbot.java
|
|
||||||
String response = in.readLine();
|
|
||||||
System.out.println("Response from MCbot.java: " + response);
|
|
||||||
|
|
||||||
socket.close();
|
|
||||||
} catch (IOException | GeneralSecurityException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
Binary file not shown.
Reference in New Issue
Block a user