From 152d279e177cf0571a4e40c4c1797b318cc3acef Mon Sep 17 00:00:00 2001 From: Tristan Vermeesch Date: Fri, 25 Oct 2024 22:35:22 +0200 Subject: [PATCH] feat: add bungeecord support --- build.gradle | 11 ++-- docs/docs/configuration/commands.md | 1 + java17-build.gradle | 4 +- java8-build.gradle | 4 +- .../playbosswar/com/CommandTimerPlugin.java | 2 +- .../java/me/playbosswar/com/enums/Gender.java | 6 +- .../me/playbosswar/com/tasks/TaskCommand.java | 5 ++ .../playbosswar/com/tasks/TasksManager.java | 62 +++++++++++++++---- src/main/resources/languages/default.json | 2 +- src/main/resources/languages/en.json | 2 +- 10 files changed, 76 insertions(+), 23 deletions(-) diff --git a/build.gradle b/build.gradle index abf4cba..2fa343b 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,7 @@ java { group = 'me.playbosswar.com' -version = '8.9.1' +version = '8.10.0' description = 'CommandTimer' repositories { @@ -27,6 +27,9 @@ repositories { maven { url = 'https://repo.codemc.io/repository/maven-snapshots/' } + maven { + url = 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/' + } } shadowJar { @@ -54,7 +57,8 @@ dependencies { implementation 'io.sentry:sentry:7.0.0' implementation 'com.j256.ormlite:ormlite-jdbc:6.1' implementation 'org.apache.commons:commons-pool2:2.12.0' - compileOnly 'io.papermc.paper:paper-api:1.21-R0.1-SNAPSHOT' + implementation 'org.apache.commons:commons-lang3:3.17.0' + compileOnly 'org.spigotmc:spigot-api:1.21-R0.1-SNAPSHOT' compileOnly 'me.clip:placeholderapi:2.11.6' compileOnly 'org.jetbrains:annotations:23.1.0' } @@ -64,8 +68,7 @@ publishing { maven(MavenPublication) { groupId = 'me.playbosswar.com' artifactId = 'commandtimer-java21' - version = '8.9.1' - + version = '8.10.0' from components.java } } diff --git a/docs/docs/configuration/commands.md b/docs/docs/configuration/commands.md index a7e0412..b3151c9 100644 --- a/docs/docs/configuration/commands.md +++ b/docs/docs/configuration/commands.md @@ -42,6 +42,7 @@ Genders define for whom the command will be executed. the [conditions engine](conditions.md) to check if the player has the permission before executing it. - `CONSOLE_PER_USER_OFFLINE`: Same as `CONSOLE_PER_USER` but also executed for all offline players that every joined. * *Please note that the conditions engine is currently not compatible with this gender** +- `CONSOLE_PROXY`: Execute commands on your proxy. You need the [CommandTimer Proxy Extension](https://www.spigotmc.org/resources/commandtimer-proxy-extension.120439/) for this. Depending on which version of the extension you use the commands may only be executed when a player is connected to the proxy network ## Command iteration interval diff --git a/java17-build.gradle b/java17-build.gradle index 718e0c7..667da66 100644 --- a/java17-build.gradle +++ b/java17-build.gradle @@ -10,7 +10,7 @@ java { group = 'me.playbosswar.com' -version = '8.9.1' +version = '8.10.0' description = 'CommandTimer' repositories { @@ -63,7 +63,7 @@ publishing { maven(MavenPublication) { groupId = 'me.playbosswar.com' artifactId = 'commandtimer-java17' - version = '8.9.1' + version = '8.10.0' from components.java } diff --git a/java8-build.gradle b/java8-build.gradle index 5b0935e..04d6fef 100644 --- a/java8-build.gradle +++ b/java8-build.gradle @@ -9,7 +9,7 @@ java { } group = 'me.playbosswar.com' -version = '8.9.1' +version = '8.10.0' description = 'CommandTimer' repositories { @@ -70,7 +70,7 @@ publishing { maven(MavenPublication) { groupId = 'me.playbosswar.com' artifactId = 'commandtimer-java8' - version = '8.9.1' + version = '8.10.0' from components.java } diff --git a/src/main/java/me/playbosswar/com/CommandTimerPlugin.java b/src/main/java/me/playbosswar/com/CommandTimerPlugin.java index 55e0e18..f16b47a 100644 --- a/src/main/java/me/playbosswar/com/CommandTimerPlugin.java +++ b/src/main/java/me/playbosswar/com/CommandTimerPlugin.java @@ -59,7 +59,6 @@ public void onEnable() { options.setTracesSampleRate(0.3); options.setRelease(getDescription().getVersion()); }); - Sentry.configureScope(scope -> { scope.setExtra("bukkit_version", getServer().getBukkitVersion()); scope.setExtra("server_name", getServer().getName()); @@ -97,6 +96,7 @@ public void onEnable() { conditionEngineManager = new ConditionEngineManager(); eventsManager = new EventsManager(tasksManager); inventoryManager.init(); + getServer().getMessenger().registerOutgoingPluginChannel(plugin, "commandtimer:main"); loadMetrics(); if(getConfig().getBoolean("timeonload")) { diff --git a/src/main/java/me/playbosswar/com/enums/Gender.java b/src/main/java/me/playbosswar/com/enums/Gender.java index ec99b44..3078332 100644 --- a/src/main/java/me/playbosswar/com/enums/Gender.java +++ b/src/main/java/me/playbosswar/com/enums/Gender.java @@ -21,5 +21,9 @@ public enum Gender { /** * Commands are executed for each player that ever joined */ - CONSOLE_PER_USER_OFFLINE; + CONSOLE_PER_USER_OFFLINE, + /** + * Commands are executed in the linked proxy server + */ + CONSOLE_PROXY, } diff --git a/src/main/java/me/playbosswar/com/tasks/TaskCommand.java b/src/main/java/me/playbosswar/com/tasks/TaskCommand.java index 81fd788..9cf3def 100644 --- a/src/main/java/me/playbosswar/com/tasks/TaskCommand.java +++ b/src/main/java/me/playbosswar/com/tasks/TaskCommand.java @@ -53,6 +53,11 @@ public void toggleGender() { } if(gender.equals(Gender.CONSOLE_PER_USER_OFFLINE)) { + setGender(Gender.CONSOLE_PROXY); + return; + } + + if(gender.equals(Gender.CONSOLE_PROXY)) { setGender(Gender.OPERATOR); } } diff --git a/src/main/java/me/playbosswar/com/tasks/TasksManager.java b/src/main/java/me/playbosswar/com/tasks/TasksManager.java index 2e58673..cd31f0d 100644 --- a/src/main/java/me/playbosswar/com/tasks/TasksManager.java +++ b/src/main/java/me/playbosswar/com/tasks/TasksManager.java @@ -1,22 +1,36 @@ package me.playbosswar.com.tasks; -import me.playbosswar.com.CommandTimerPlugin; -import me.playbosswar.com.enums.CommandExecutionMode; -import me.playbosswar.com.enums.Gender; -import me.playbosswar.com.hooks.PAPIHook; -import me.playbosswar.com.utils.*; -import org.apache.commons.lang.RandomStringUtils; +import java.io.IOException; +import java.nio.file.Paths; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.UUID; +import java.util.stream.Collectors; + +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; + +import org.apache.commons.lang3.RandomStringUtils; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.command.CommandException; import org.bukkit.entity.Player; import org.jetbrains.annotations.Nullable; -import java.io.IOException; -import java.nio.file.Paths; -import java.sql.SQLException; -import java.util.*; -import java.util.stream.Collectors; +import me.playbosswar.com.CommandTimerPlugin; +import me.playbosswar.com.enums.CommandExecutionMode; +import me.playbosswar.com.enums.Gender; +import me.playbosswar.com.hooks.PAPIHook; +import me.playbosswar.com.utils.DatabaseUtils; +import me.playbosswar.com.utils.Files; +import me.playbosswar.com.utils.Messages; +import me.playbosswar.com.utils.StringEnhancer; +import me.playbosswar.com.utils.Tools; public class TasksManager { @@ -288,6 +302,30 @@ private boolean runOperatorCommand(Task task, TaskCommand taskCommand) { return runOperatorCommand(task, taskCommand, new ArrayList<>()); } + private boolean runConsoleProxyCommand(Task task, TaskCommand taskCommand) { + if(task.hasCondition()) { + boolean valid = TaskValidationHelpers.processCondition(task.getCondition(), null); + if(!valid) { + Messages.sendDebugConsole(CONDITION_NO_MATCH); + return false; + } + } + + String command = taskCommand.getCommand(); + ByteArrayOutputStream b = new ByteArrayOutputStream(); + DataOutputStream out = new DataOutputStream(b); + try { + out.writeUTF("executeConsoleCommand"); + out.writeUTF(command); + } catch (IOException e) { + e.printStackTrace(); + } + + Bukkit.getServer().sendPluginMessage(CommandTimerPlugin.getPlugin(), "commandtimer:main", b.toByteArray()); + executionsSinceLastSync++; + return true; + } + public void processCommandExecution(Task task, TaskCommand taskCommand) { if(!task.isActive()) { return; @@ -306,6 +344,8 @@ public void processCommandExecution(Task task, TaskCommand taskCommand) { executed = runConsolePerUserCommand(task, taskCommand); } else if(gender.equals(Gender.CONSOLE_PER_USER_OFFLINE)) { executed = runConsolePerUserOfflineCommand(taskCommand); + } else if(gender.equals(Gender.CONSOLE_PROXY)) { + executed = runConsoleProxyCommand(task, taskCommand); } if(executed) { diff --git a/src/main/resources/languages/default.json b/src/main/resources/languages/default.json index 597ee0d..43ae2e0 100644 --- a/src/main/resources/languages/default.json +++ b/src/main/resources/languages/default.json @@ -47,7 +47,7 @@ "gender_item": "&bGender", "gender": "&7Gender: &e$1", "gender_lore": "\n&7The commands don't need to be executed all\n&7at once. You can decide between one of the\n&7following selection modes:\n\n&7 - &eALL: &7Execute all commands at once\n\n&7 - &eORDERED: &7Execute the commands one by one.\n&7 This works best if you specify seconds. It will\n&7 execute command 1 the first time the task is executed,\n&7 then it will pick command 2 on next execution and so on.\n\n&7 - &eRANDOM: &7Same as above, but will pick a random\n&7 command at each execution.\n\n&7 - &eINTERVAL: &7Execute each command in order with\n&7 an interval in between.\n&7 See ORDERED for more information\n\n", - "gender_selector_lore": "\n&7Genders are one of the core concepts of\n&7CommandTimer. They allow you to specify\n&7how your task is executed.\n\n&7Current: &e$1\n\n&bAvailable genders:\n\n&7 - &eOPERATOR: &7All the commands in the task\n&7 will be executed for each individual player,\n&7 by the player. This means that CommandTimer will\n&7 force the player to execute the commands but ignore\n&7 the permissions linked to them.\n\n&7 - &ePLAYER: &7Same as above. CommandTimer will force\n&7 the player to execute the commands, but will take\n&7 into account the possible permissions the player\n&7 has or is lacking.\n\n&7 - &eCONSOLE: &7Execute the command in the console only\n\n&7 - &eCONSOLE PER USER: &7Execute the command in the console\n&7 for each individual player. This works very well with\n&7 placeholders\n\n&7 - &eCONSOLE_PER_USER_OFFLINE: &7Same as above but also takes into account offline players", + "gender_selector_lore": "\n&7Genders are one of the core concepts of\n&7CommandTimer. They allow you to specify\n&7how your task is executed.\n\n&7Current: &e$1\n\n&bAvailable genders:\n\n&7 - &eOPERATOR: &7All the commands in the task\n&7 will be executed for each individual player,\n&7 by the player. This means that CommandTimer will\n&7 force the player to execute the commands but ignore\n&7 the permissions linked to them.\n\n&7 - &ePLAYER: &7Same as above. CommandTimer will force\n&7 the player to execute the commands, but will take\n&7 into account the possible permissions the player\n&7 has or is lacking.\n\n&7 - &eCONSOLE: &7Execute the command in the console only\n\n&7 - &eCONSOLE PER USER: &7Execute the command in the console\n&7 for each individual player. This works very well with\n&7 placeholders\n\n&7 - &eCONSOLE_PER_USER_OFFLINE: &7Same as above but also takes into account offline players\n\n&7 - &eCONSOLE_PROXY: &7Execute commands on proxy (requires proxy extension", "add_command": "&bAdd command", "add_command_lore": "\n&7Add a new command that will be\n&7executed on your specified schedule\n", "command_interval_lore": "\n&7Define the delay between each player command execution.\n&7This only works when you have a gender that runs\n&7for all the players.\n\n&7Current: &e$1", diff --git a/src/main/resources/languages/en.json b/src/main/resources/languages/en.json index 597ee0d..43ae2e0 100644 --- a/src/main/resources/languages/en.json +++ b/src/main/resources/languages/en.json @@ -47,7 +47,7 @@ "gender_item": "&bGender", "gender": "&7Gender: &e$1", "gender_lore": "\n&7The commands don't need to be executed all\n&7at once. You can decide between one of the\n&7following selection modes:\n\n&7 - &eALL: &7Execute all commands at once\n\n&7 - &eORDERED: &7Execute the commands one by one.\n&7 This works best if you specify seconds. It will\n&7 execute command 1 the first time the task is executed,\n&7 then it will pick command 2 on next execution and so on.\n\n&7 - &eRANDOM: &7Same as above, but will pick a random\n&7 command at each execution.\n\n&7 - &eINTERVAL: &7Execute each command in order with\n&7 an interval in between.\n&7 See ORDERED for more information\n\n", - "gender_selector_lore": "\n&7Genders are one of the core concepts of\n&7CommandTimer. They allow you to specify\n&7how your task is executed.\n\n&7Current: &e$1\n\n&bAvailable genders:\n\n&7 - &eOPERATOR: &7All the commands in the task\n&7 will be executed for each individual player,\n&7 by the player. This means that CommandTimer will\n&7 force the player to execute the commands but ignore\n&7 the permissions linked to them.\n\n&7 - &ePLAYER: &7Same as above. CommandTimer will force\n&7 the player to execute the commands, but will take\n&7 into account the possible permissions the player\n&7 has or is lacking.\n\n&7 - &eCONSOLE: &7Execute the command in the console only\n\n&7 - &eCONSOLE PER USER: &7Execute the command in the console\n&7 for each individual player. This works very well with\n&7 placeholders\n\n&7 - &eCONSOLE_PER_USER_OFFLINE: &7Same as above but also takes into account offline players", + "gender_selector_lore": "\n&7Genders are one of the core concepts of\n&7CommandTimer. They allow you to specify\n&7how your task is executed.\n\n&7Current: &e$1\n\n&bAvailable genders:\n\n&7 - &eOPERATOR: &7All the commands in the task\n&7 will be executed for each individual player,\n&7 by the player. This means that CommandTimer will\n&7 force the player to execute the commands but ignore\n&7 the permissions linked to them.\n\n&7 - &ePLAYER: &7Same as above. CommandTimer will force\n&7 the player to execute the commands, but will take\n&7 into account the possible permissions the player\n&7 has or is lacking.\n\n&7 - &eCONSOLE: &7Execute the command in the console only\n\n&7 - &eCONSOLE PER USER: &7Execute the command in the console\n&7 for each individual player. This works very well with\n&7 placeholders\n\n&7 - &eCONSOLE_PER_USER_OFFLINE: &7Same as above but also takes into account offline players\n\n&7 - &eCONSOLE_PROXY: &7Execute commands on proxy (requires proxy extension", "add_command": "&bAdd command", "add_command_lore": "\n&7Add a new command that will be\n&7executed on your specified schedule\n", "command_interval_lore": "\n&7Define the delay between each player command execution.\n&7This only works when you have a gender that runs\n&7for all the players.\n\n&7Current: &e$1",