Skip to content

Commit

Permalink
2.0.4 (#40)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
WildBamaBoy authored Feb 26, 2024
1 parent 6a3478a commit aead7df
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 14 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
=====

Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
defaultTasks("shadowJar")

group = "io.tebex"
version = "2.0.3"
version = "2.0.4"

subprojects {
plugins.apply("java")
Expand Down
7 changes: 6 additions & 1 deletion bukkit/src/main/java/io/tebex/plugin/TebexPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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();
Expand Down
7 changes: 6 additions & 1 deletion bungeecord/src/main/java/io/tebex/plugin/TebexPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion fabric/src/main/java/io/tebex/plugin/TebexPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public void executeBlockingLater(Runnable runnable, long time, TimeUnit unit) {
private Optional<ServerPlayerEntity> 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));
}

Expand Down Expand Up @@ -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) {
Expand Down
10 changes: 6 additions & 4 deletions sdk/src/main/java/io/tebex/sdk/SDK.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ public CompletableFuture<OfflineCommandsResponse> 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
));
}
Expand Down Expand Up @@ -216,14 +217,15 @@ public CompletableFuture<List<QueuedCommand>> 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
));
}

Expand Down
11 changes: 8 additions & 3 deletions sdk/src/main/java/io/tebex/sdk/obj/QueuedCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}

Expand Down
23 changes: 22 additions & 1 deletion sdk/src/main/java/io/tebex/sdk/platform/Platform.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
*/
Expand Down
2 changes: 1 addition & 1 deletion test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
7 changes: 6 additions & 1 deletion velocity/src/main/java/io/tebex/plugin/TebexPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public void executeBlockingLater(Runnable runnable, long time, TimeUnit unit) {
private Optional<Player> getPlayer(Object player) {
if(player == null) return Optional.empty();

if (isOnlineMode()) {
if (isOnlineMode() && !isGeyser() && player instanceof UUID) {
return proxy.getPlayer((UUID) player);
}

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

0 comments on commit aead7df

Please sign in to comment.