Skip to content

Commit

Permalink
Version 2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
CorwinDev committed Oct 8, 2022
1 parent 54649c3 commit 86b9577
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 48 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>StreamerVSChat</groupId>
<artifactId>StreamerVSChat</artifactId>
<version>2.1</version>
<version>2.2</version>
<packaging>jar</packaging>

<name>Streamer vs Chat</name>
Expand Down
49 changes: 27 additions & 22 deletions src/main/java/nl/corwindev/streamervschat/commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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")) {
Expand All @@ -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")) {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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");
Expand All @@ -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;
Expand Down Expand Up @@ -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);;
}
}

Expand Down
11 changes: 5 additions & 6 deletions src/main/java/nl/corwindev/streamervschat/main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -74,20 +74,23 @@ public void run() {

// Display messages and super chat details
List<LiveChatMessage> 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());
}
Expand All @@ -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());
Expand All @@ -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 = "";
Expand All @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: StreamerVsChat
version: '2.1'
version: '2.2'
main: nl.corwindev.streamervschat.main
api-version: 1.13
commands:
Expand Down

0 comments on commit 86b9577

Please sign in to comment.