diff --git a/pom.xml b/pom.xml
index 930c77e..1d6152a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -14,6 +14,14 @@
21
+
+
+
+ spigot-repo
+ https://hub.spigotmc.org/nexus/content/repositories/snapshots/
+
+
+
diff --git a/src/main/java/MCchatbotyt.java b/src/main/java/MCchatbotyt.java
index 5cb2f77..c8b65ae 100644
--- a/src/main/java/MCchatbotyt.java
+++ b/src/main/java/MCchatbotyt.java
@@ -1,107 +1,50 @@
-import com.google.api.client.googleapis.auth.oauth2.Credential;
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
+import org.bukkit.Bukkit;
+import org.bukkit.Server;
+
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
-import com.google.api.client.googleapis.http.HttpRequest;
-import com.google.api.client.googleapis.http.HttpRequestInitializer;
-import com.google.api.client.googleapis.json.JsonFactory;
-import com.google.api.client.googleapis.json.jackson2.JacksonFactory;
+import com.google.api.client.json.JsonFactory;
+import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.youtube.YouTube;
-import com.google.api.services.youtube.model.LiveChatMessage;
-import com.google.api.services.youtube.model.LiveChatMessageListResponse;
-import com.google.api.services.youtube.model.LiveChatMessageSnippet;
-import com.google.api.services.youtube.model.LiveChatTextMessageDetails;
-import com.google.api.services.youtube.model.LiveChatTextMessageDetails.MessageTextDetails;
-
-import java.io.*;
-import java.net.*;
-import java.security.GeneralSecurityException;
-import java.util.List;
-
-public class MCchatbotyt {
-
- private static final String APPLICATION_NAME = "MC chatbot for YT";
- private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
- private static YouTube youtube;
-
- public static void main(String[] args) throws GeneralSecurityException, IOException {
- // Set up credentials
- Credential credential = authorize();
-
- // Set up YouTube API client
- youtube = new YouTube.Builder(
- GoogleNetHttpTransport.newTrustedTransport(),
- JSON_FACTORY,
- new HttpRequestInitializer() {
- @Override
- public void initialize(HttpRequest request) throws IOException {
- request.setInterceptor(credential);
- }
- })
- .setApplicationName(APPLICATION_NAME)
- .build();
-
- // Get live chat ID for your live stream
- String liveChatId = getLiveChatId("5lAKSeFQS2M");
-
- // Poll for new chat messages every few seconds
- while (true) {
- List messages = getLiveChatMessages(liveChatId);
- for (LiveChatMessage message : messages) {
- String author = message.getSnippet().getAuthorChannelId();
- String text = message.getSnippet().getDisplayMessage();
- System.out.println("New message from " + author + ": " + text);
- // 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();
- }
+import com.google.api.services.youtube.model.VideoListResponse;
+import com.google.api.services.youtube.model.Video;
+public class YouTubeBot {
+ private Server server;
+ private YouTube youtube;
+
+ public YouTubeBot(String apiKey) {
try {
- Thread.sleep(5000); // Poll every 5 seconds
- } catch (InterruptedException e) {
+ this.server = Bukkit.getServer();
+ this.youtube = new YouTube.Builder(
+ GoogleNetHttpTransport.newTrustedTransport(),
+ JacksonFactory.getDefaultInstance(),
+ null)
+ .setApplicationName("Crafty MC")
+ .setYouTubeApiKey()
+ .build();
+ } catch (Exception e) {
e.printStackTrace();
}
}
+
+ public int getOnlinePlayersCount() {
+ return server.getOnlinePlayers().size();
}
- private static Credential authorize() throws IOException, GeneralSecurityException {
- // Load client secrets JSON file (you need to create this file with your OAuth client ID and secret)
- GoogleCredential credential = GoogleCredential.fromStream(
- YouTubeLiveChatBot.class.getResourceAsStream("/client_secrets.json"))
- .createScoped(List.of("https://www.googleapis.com/auth/youtube"));
-
- return credential;
- }
-
- private static String getLiveChatId(String liveStreamId) throws IOException {
- YouTube.LiveChatMessages.List liveChatRequest = youtube.liveChatMessages()
- .list("id,snippet")
- .setLiveChatId(liveStreamId);
- LiveChatMessageListResponse response = liveChatRequest.execute();
- List messages = response.getItems();
- if (messages != null && !messages.isEmpty()) {
- return messages.get(0).getSnippet().getLiveChatId();
+ public void handleCommand(String command) {
+ if (command.equalsIgnoreCase("!stats")) {
+ String stats = getServerStatistics();
+ // Send stats to YouTube chat or log for testing
+ System.out.println(stats); // For testing, replace with actual sending to YouTube chat
}
- return null;
}
- private static List getLiveChatMessages(String liveChatId) throws IOException {
- YouTube.LiveChatMessages.List liveChatRequest = youtube.liveChatMessages()
- .list("id,snippet")
- .setLiveChatId(liveChatId);
- LiveChatMessageListResponse response = liveChatRequest.execute();
- return response.getItems();
+ private String getServerStatistics() {
+ // Use Spigot API or other methods to get server stats
+ int onlinePlayers = server.getOnlinePlayers().size();
+ // Construct and return server stats message
+ return "Online Players: " + onlinePlayers;
}
+
+ // Other methods and bot logic
}
\ No newline at end of file
diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
new file mode 100644
index 0000000..e69de29
diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst
new file mode 100644
index 0000000..a84a05f
--- /dev/null
+++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst
@@ -0,0 +1 @@
+C:\Users\hbmann\Documents\Projects\_MCbotYT\MCyoutube_bot\src\main\java\MCchatbotyt.java