From aead7dfb14cc9ba71a881825d040023c2b2a79ae Mon Sep 17 00:00:00 2001 From: Dusty A Date: Mon, 26 Feb 2024 08:28:24 -0600 Subject: [PATCH] 2.0.4 (#40) * fix: ensure received player uuid is string before casting #37 * fix: geyser/offline servers properly replace all name variable tags #34 For Geyser, the UUID returned from Tebex will not be valid. {id} in this case will be replaced with the username as an identifier. Otherwise {id} will contain the user's true valid UUID. * chore: bump versions --- CHANGELOG.md | 9 ++++++++ build.gradle.kts | 2 +- .../java/io/tebex/plugin/TebexPlugin.java | 7 +++++- .../java/io/tebex/plugin/TebexPlugin.java | 7 +++++- .../java/io/tebex/plugin/TebexPlugin.java | 7 +++++- sdk/src/main/java/io/tebex/sdk/SDK.java | 10 ++++---- .../java/io/tebex/sdk/obj/QueuedCommand.java | 11 ++++++--- .../java/io/tebex/sdk/platform/Platform.java | 23 ++++++++++++++++++- test.sh | 2 +- .../java/io/tebex/plugin/TebexPlugin.java | 7 +++++- 10 files changed, 71 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index baa1553..cafb4e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +2.0.4 +===== + +### Fixes +- The `{id}` parameter is now properly replaced on Geyser and Minecraft Offline/Geyser store types. For offline servers, it will be replaced with the user's name. For online servers, this will be the player's UUID. +- Fix for `java.lang.String cannot be cast to class java.util.UUID` on Offline/Geyser servers +- Fixed the use of deprecated characters directly in components in the Velocity module +- Relocated Adventure to prevent conflicts with older Adventure APIs on the server + 2.0.3 ===== diff --git a/build.gradle.kts b/build.gradle.kts index 8571910..bf605a7 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,7 +9,7 @@ plugins { defaultTasks("shadowJar") group = "io.tebex" -version = "2.0.3" +version = "2.0.4" subprojects { plugins.apply("java") diff --git a/bukkit/src/main/java/io/tebex/plugin/TebexPlugin.java b/bukkit/src/main/java/io/tebex/plugin/TebexPlugin.java index 4d017d8..7bbf057 100644 --- a/bukkit/src/main/java/io/tebex/plugin/TebexPlugin.java +++ b/bukkit/src/main/java/io/tebex/plugin/TebexPlugin.java @@ -331,7 +331,7 @@ public void executeBlockingLater(Runnable runnable, long time, TimeUnit unit) { public Player getPlayer(Object player) { if(player == null) return null; - if (isOnlineMode()) { + if (isOnlineMode() && !isGeyser() && player instanceof UUID) { return getServer().getPlayer((UUID) player); } @@ -368,6 +368,11 @@ public String getVersion() { return getDescription().getVersion(); } + @Override + public String getStoreType() { + return storeInformation == null ? "" : storeInformation.getStore().getGameType(); + } + @Override public PlatformTelemetry getTelemetry() { String serverVersion = getServer().getVersion(); diff --git a/bungeecord/src/main/java/io/tebex/plugin/TebexPlugin.java b/bungeecord/src/main/java/io/tebex/plugin/TebexPlugin.java index 7ddbb30..3340d4a 100644 --- a/bungeecord/src/main/java/io/tebex/plugin/TebexPlugin.java +++ b/bungeecord/src/main/java/io/tebex/plugin/TebexPlugin.java @@ -247,7 +247,7 @@ public void executeBlockingLater(Runnable runnable, long time, TimeUnit unit) { private ProxiedPlayer getPlayer(Object player) { if(player == null) return null; - if (isOnlineMode()) { + if (isOnlineMode() && !isGeyser() && player instanceof UUID) { return getProxy().getPlayer((UUID) player); } @@ -270,6 +270,11 @@ public String getVersion() { return getDescription().getVersion(); } + @Override + public String getStoreType() { + return storeInformation == null ? "" : storeInformation.getStore().getGameType(); + } + @Override public void log(Level level, String message) { getLogger().log(level, message); diff --git a/fabric/src/main/java/io/tebex/plugin/TebexPlugin.java b/fabric/src/main/java/io/tebex/plugin/TebexPlugin.java index 2d61ff7..aa811ea 100644 --- a/fabric/src/main/java/io/tebex/plugin/TebexPlugin.java +++ b/fabric/src/main/java/io/tebex/plugin/TebexPlugin.java @@ -237,7 +237,7 @@ public void executeBlockingLater(Runnable runnable, long time, TimeUnit unit) { private Optional getPlayer(Object player) { if(player == null) return Optional.empty(); - if(isOnlineMode()) { + if (isOnlineMode() && !isGeyser() && player instanceof UUID) { return Optional.ofNullable(server.getPlayerManager().getPlayer((UUID) player)); } @@ -265,6 +265,11 @@ public String getVersion() { return MOD_VERSION; } + @Override + public String getStoreType() { + return storeInformation == null ? "" : storeInformation.getStore().getGameType(); + } + @Override public void log(Level level, String message) { if(level == Level.INFO) { diff --git a/sdk/src/main/java/io/tebex/sdk/SDK.java b/sdk/src/main/java/io/tebex/sdk/SDK.java index 133eb0f..12dfd94 100644 --- a/sdk/src/main/java/io/tebex/sdk/SDK.java +++ b/sdk/src/main/java/io/tebex/sdk/SDK.java @@ -172,7 +172,8 @@ public CompletableFuture getOfflineCommands() { platform.getPlaceholderManager().handlePlaceholders(queuedPlayer, commandJson.get("command").getAsString()), paymentId, packageId, - conditions.get("delay").getAsInt(), + conditions.has("delay") ? conditions.get("delay").getAsInt() : 0, + conditions.has("slots") ? conditions.get("slots").getAsInt() : 0, queuedPlayer )); } @@ -216,14 +217,15 @@ public CompletableFuture> getOnlineCommands(QueuedPlayer pla int packageId = commandJson.get("package").isJsonNull() ? 0 : commandJson.get("package").getAsInt(); int paymentId = commandJson.get("payment").isJsonNull() ? 0 : commandJson.get("payment").getAsInt(); + queuedCommands.add(new QueuedCommand( commandJson.get("id").getAsInt(), platform.getPlaceholderManager().handlePlaceholders(player, commandJson.get("command").getAsString()), paymentId, packageId, - conditions.get("delay").getAsInt(), - conditions.get("slots").getAsInt() - + conditions.has("delay") ? conditions.get("delay").getAsInt() : 0, + conditions.has("slots") ? conditions.get("slots").getAsInt() : 0, + player )); } diff --git a/sdk/src/main/java/io/tebex/sdk/obj/QueuedCommand.java b/sdk/src/main/java/io/tebex/sdk/obj/QueuedCommand.java index eee6b1d..07c8984 100644 --- a/sdk/src/main/java/io/tebex/sdk/obj/QueuedCommand.java +++ b/sdk/src/main/java/io/tebex/sdk/obj/QueuedCommand.java @@ -21,13 +21,13 @@ public QueuedCommand(int id, String command, int payment, int packageId, int del this.online = true; } - public QueuedCommand(int id, String command, int payment, int packageId, int delay, QueuedPlayer player) { + public QueuedCommand(int id, String command, int payment, int packageId, int delay, int requiredSlots, QueuedPlayer player) { this.id = id; this.command = command; this.payment = payment; this.packageId = packageId; this.delay = delay; - this.requiredSlots = 0; + this.requiredSlots = requiredSlots; this.player = player; this.online = false; } @@ -42,14 +42,19 @@ public String getCommand() { public String getParsedCommand() { String parsedCommand = command; + if (player != null) { parsedCommand = parsedCommand.replace("{username}", player.getName()); parsedCommand = parsedCommand.replace("{name}", player.getName()); - if (player.getUuid() != null) { // offline servers will return null uuid here + + if (player.getUuid() != null) { // offline servers will return null uuid here as these uuids are not verified parsedCommand = parsedCommand.replace("{id}", player.getUuid()); parsedCommand = parsedCommand.replace("{uuid}", player.getUuid()); + } else { // {id} must still be replaced with username if uuid is not present + parsedCommand = parsedCommand.replace("{id}", player.getName()); } } + return parsedCommand; } diff --git a/sdk/src/main/java/io/tebex/sdk/platform/Platform.java b/sdk/src/main/java/io/tebex/sdk/platform/Platform.java index 7b25d95..4eefdb9 100644 --- a/sdk/src/main/java/io/tebex/sdk/platform/Platform.java +++ b/sdk/src/main/java/io/tebex/sdk/platform/Platform.java @@ -1,6 +1,5 @@ package io.tebex.sdk.platform; -import com.google.common.base.Strings; import dev.dejvokep.boostedyaml.YamlDocument; import io.tebex.sdk.SDK; import io.tebex.sdk.exception.ServerNotFoundException; @@ -44,6 +43,13 @@ public interface Platform { */ PlatformType getType(); + /** + * Gets the store's type from store info. This info should be cached and not fetched on each request + * + * @return Store info string ex. "Minecraft (Offline/Geyser)" + */ + String getStoreType(); + /** * Gets the SDK instance associated with this platform. * @@ -77,6 +83,21 @@ public interface Platform { */ boolean isOnlineMode(); + /** + * Checks if the configured store is Geyser/Offline + * + * @return Whether the store is a Offline/Geyser type webstore + */ + default boolean isGeyser() { + if (!isSetup()) return false; + + if (getStoreType() == null || getStoreType().isEmpty()) { + return false; + } + + return getStoreType().contains("Offline/Geyser"); + } + /** * Configures the platform for use. */ diff --git a/test.sh b/test.sh index efd2cb2..3adb90c 100755 --- a/test.sh +++ b/test.sh @@ -82,7 +82,7 @@ function installPluginToFolder() { toFolder="$2" # root minecraft server folder containing /plugins mkdir -p "$toFolder/plugins" - cp "../build/libs/tebex-$pluginType-2.0.2.jar" "$toFolder/plugins" + cp "../build/libs/tebex-$pluginType-2.0.4.jar" "$toFolder/plugins" } function copyWorlds() { diff --git a/velocity/src/main/java/io/tebex/plugin/TebexPlugin.java b/velocity/src/main/java/io/tebex/plugin/TebexPlugin.java index ec26412..7e6ebd8 100644 --- a/velocity/src/main/java/io/tebex/plugin/TebexPlugin.java +++ b/velocity/src/main/java/io/tebex/plugin/TebexPlugin.java @@ -256,7 +256,7 @@ public void executeBlockingLater(Runnable runnable, long time, TimeUnit unit) { private Optional getPlayer(Object player) { if(player == null) return Optional.empty(); - if (isOnlineMode()) { + if (isOnlineMode() && !isGeyser() && player instanceof UUID) { return proxy.getPlayer((UUID) player); } @@ -279,6 +279,11 @@ public String getVersion() { return "@VERSION@"; } + @Override + public String getStoreType() { + return storeInformation == null ? "" : storeInformation.getStore().getGameType(); + } + @Override public void log(Level level, String message) { logger.log(level, message);