diff --git a/pom.xml b/pom.xml index b8b536a..f5ec452 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ StreamerVSChat StreamerVSChat - 2.1 + 2.2 jar Streamer vs Chat diff --git a/src/main/java/nl/corwindev/streamervschat/commands.java b/src/main/java/nl/corwindev/streamervschat/commands.java index 64bce84..9533b55 100644 --- a/src/main/java/nl/corwindev/streamervschat/commands.java +++ b/src/main/java/nl/corwindev/streamervschat/commands.java @@ -43,13 +43,14 @@ public static void startCommand(){ runCmd(command, UserList.get(randomCommand)); } public static void runCmd(String command, String random) { - System.out.println(command); if (Objects.requireNonNull(plugin.getConfig().getList("blacklist")).contains(command)) { return; } + int index = commandList.indexOf(command); if(plugin.getConfig().getString("cooldowns." + command) != null){ if(cooldowns.contains(command)){ - commandList.remove(command); + commandList.remove(index); + UserList.remove(index); startCommand(); return; }else{ @@ -85,9 +86,9 @@ public void run() { } else if (Objects.equals(command, "witherscare") || Objects.equals(command, "wither")) { commands.wither(); } else if (Objects.equals(command, "creeper")) { - commands.creeper(); + commands.creeper(UserList.get(index)); } else if (Objects.equals(command, "zombie")) { - commands.zombie(); + commands.zombie(UserList.get(index)); } else if (Objects.equals(command, "illness") || Objects.equals(command, "nausea")) { commands.nausea(); } else if (Objects.equals(command, "slowness")) { @@ -111,13 +112,13 @@ public void run() { } else if (Objects.equals(command, "drop")) { commands.drop(); } else if (Objects.equals(command, "silverfish")) { - commands.silverfish(); + commands.silverfish(UserList.get(index)); } else if (Objects.equals(command, "vex")) { - commands.vex(); + commands.vex(UserList.get(index)); } else if (Objects.equals(command, "chicken")) { - commands.chicken(); + commands.chicken(UserList.get(index)); } else if (Objects.equals(command, "bee")) { - commands.bee(); + commands.bee(UserList.get(index)); }else if(Objects.equals(command, "day")){ commands.day(); }else if(Objects.equals(command, "night")) { @@ -131,7 +132,9 @@ public void run() { }else if(command.startsWith("rename")){ commands.rename(command); } else { - if(!commands.custom(command)){ + if(!commands.custom(command, UserList.get(index))){ + commandList.remove(index); + UserList.remove(index); startCommand(); return; } @@ -224,15 +227,15 @@ public static void lightning() { } } - public static void creeper() { + public static void creeper(String user) { for (Player player : getPlayers()) { - player.getWorld().spawn(player.getLocation(), org.bukkit.entity.Creeper.class); + player.getWorld().spawn(player.getLocation(), org.bukkit.entity.Creeper.class).setCustomName("§c§l" + user); } } - public static void zombie() { + public static void zombie(String user) { for (Player player : getPlayers()) { - player.getWorld().spawn(player.getLocation(), org.bukkit.entity.Zombie.class); + player.getWorld().spawn(player.getLocation(), org.bukkit.entity.Zombie.class).setCustomName("§c§l" + user); } } @@ -317,7 +320,7 @@ public static void fly() { } } - public static boolean custom(String command) { + public static boolean custom(String command, String user) { String command1 = plugin.getConfig().getString("customcommands." + command + ".command"); if (command1 != null) { Integer cooldown = plugin.getConfig().getInt("customcommands." + command + ".cooldown"); @@ -336,7 +339,8 @@ public void run() { } for (Player player : getPlayers()) { String command2 = command1.replace("%player%", player.getName()); - plugin.getLogger().info(command2); + String command3 = command2.replace("%user%", user); + plugin.getLogger().info(command3); Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command2); } return true; @@ -370,30 +374,31 @@ public static void drop() { } } - public static void silverfish() { + public static void silverfish(String user) { for (Player player : getPlayers()) { - player.getWorld().spawn(player.getLocation(), org.bukkit.entity.Silverfish.class); + player.getWorld().spawn(player.getLocation(), org.bukkit.entity.Silverfish.class).setCustomName("§c§l" + user);; } } - public static void vex() { + public static void vex(String user) { for (Player player : getPlayers()) { - player.getWorld().spawn(player.getLocation(), org.bukkit.entity.Vex.class); + player.getWorld().spawn(player.getLocation(), org.bukkit.entity.Vex.class).setCustomName("§c§l" + user);; } } - public static void bee() { + public static void bee(String user) { for (Player player : getPlayers()) { // Make bee angry Bee bee = (Bee) player.getWorld().spawn(player.getLocation(), org.bukkit.entity.Bee.class); bee.setAnger(1000000); + bee.setCustomName("§c§l" + user); bee.attack(player); } } - public static void chicken() { + public static void chicken(String user) { for (Player player : getPlayers()) { - player.getWorld().spawn(player.getLocation(), org.bukkit.entity.Chicken.class); + player.getWorld().spawn(player.getLocation(), org.bukkit.entity.Chicken.class).setCustomName("§c§l" + user);; } } diff --git a/src/main/java/nl/corwindev/streamervschat/main.java b/src/main/java/nl/corwindev/streamervschat/main.java index 1aaf123..dda1a1b 100644 --- a/src/main/java/nl/corwindev/streamervschat/main.java +++ b/src/main/java/nl/corwindev/streamervschat/main.java @@ -37,12 +37,11 @@ public void onEnable() { }); if (!plugin.getConfig().getBoolean("twitch.enabled") && !plugin.getConfig().getBoolean("discord.enabled") && !plugin.getConfig().getBoolean("youtube.enabled")) { getLogger().info("No services enabled..."); - } else { - try { - commands.start(); - } catch (Exception e) { - e.printStackTrace(); - } + } + try { + commands.start(); + } catch (Exception e) { + e.printStackTrace(); } boolean serverIsLog4jCapable = false; boolean serverIsLog4j21Capable = false; diff --git a/src/main/java/nl/corwindev/streamervschat/youtube/YouTubeConnectionHelper.java b/src/main/java/nl/corwindev/streamervschat/youtube/YouTubeConnectionHelper.java index 19b0f0c..9dcf7c1 100644 --- a/src/main/java/nl/corwindev/streamervschat/youtube/YouTubeConnectionHelper.java +++ b/src/main/java/nl/corwindev/streamervschat/youtube/YouTubeConnectionHelper.java @@ -5,6 +5,7 @@ import com.google.api.client.http.javanet.NetHttpTransport; import com.google.api.client.json.jackson2.JacksonFactory; +import com.google.api.client.util.DateTime; import com.google.api.services.youtube.YouTube; import com.google.api.services.youtube.model.*; import nl.corwindev.streamervschat.commands; @@ -18,9 +19,8 @@ public class YouTubeConnectionHelper { "items(authorDetails(channelId,displayName,isChatModerator,isChatOwner,isChatSponsor," + "profileImageUrl),snippet(displayMessage,superChatDetails,publishedAt))," + "nextPageToken,pollingIntervalMillis"; - + public static boolean started = false; private static YouTube youtube; - public static void main(String args) { // This OAuth 2.0 access scope allows for read-only access to the @@ -74,20 +74,23 @@ public void run() { // Display messages and super chat details List messages = response.getItems(); - for (int i = 0; i < messages.size(); i++) { - LiveChatMessage message = messages.get(i); - LiveChatMessageSnippet snippet = message.getSnippet(); - System.out.println(buildOutput( - snippet.getDisplayMessage(), - message.getAuthorDetails(), - snippet.getSuperChatDetails())); - } - - // Request the next page of messages - listChatMessages( - liveChatId, - response.getNextPageToken(), - response.getPollingIntervalMillis()); + // Skip first run + for (int i = 0; i < messages.size(); i++) { + LiveChatMessage message = messages.get(i); + LiveChatMessageSnippet snippet = message.getSnippet(); + buildOutput( + snippet.getDisplayMessage(), + message.getAuthorDetails(), + snippet.getSuperChatDetails(), + snippet.getPublishedAt()); + } + + // Request the next page of messages + listChatMessages( + liveChatId, + response.getNextPageToken(), + response.getPollingIntervalMillis()); + } catch (Throwable t) { main.plugin.getLogger().warning("[YouTube] Error: " + t.getMessage()); } @@ -106,7 +109,12 @@ public void run() { private static String buildOutput( String message, LiveChatMessageAuthorDetails author, - LiveChatSuperChatDetails superChatDetails) { + LiveChatSuperChatDetails superChatDetails, + DateTime publishedAt) { + // Check if message is older then 5 minutes + if (publishedAt.getValue() < System.currentTimeMillis() - (main.plugin.getConfig().getInt("commands.delay") * 1000 + 1000)) { + return ""; + } StringBuilder output = new StringBuilder(); if (superChatDetails != null) { output.append(superChatDetails.getAmountDisplayString()); @@ -124,7 +132,6 @@ private static String buildOutput( if (author.getIsChatSponsor()) { roles.add("SPONSOR"); } - commands.UserList.add(author.getDisplayName()); if (roles.size() > 0) { output.append(" ("); String delim = ""; @@ -139,6 +146,7 @@ private static String buildOutput( output.append(message); } if (message.contains(main.plugin.getConfig().getString("commands.prefix"))) { + commands.UserList.add(author.getDisplayName()); commands.commandList.add(message.replace(main.plugin.getConfig().getString("commands.prefix"), "")); }else{ main.plugin.getServer().broadcastMessage(output.toString()); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index e9d3448..7d2e671 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: StreamerVsChat -version: '2.1' +version: '2.2' main: nl.corwindev.streamervschat.main api-version: 1.13 commands: