diff --git a/build.gradle.kts b/build.gradle.kts index d4d0e36..013d047 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,7 +6,7 @@ plugins { } group = "dev.plex" -version = "2.0" +version = "2.0-SNAPSHOT" description = "Module-HTTPD" repositories { diff --git a/src/main/java/dev/plex/request/impl/PlayerInventoryBroadcaster.java b/src/main/java/dev/plex/request/impl/PlayerInventoryBroadcaster.java index 118fecc..8bff426 100644 --- a/src/main/java/dev/plex/request/impl/PlayerInventoryBroadcaster.java +++ b/src/main/java/dev/plex/request/impl/PlayerInventoryBroadcaster.java @@ -1,6 +1,7 @@ package dev.plex.request.impl; import com.google.gson.GsonBuilder; +import de.tr7zw.changeme.nbtapi.NBT; import dev.plex.HTTPDModule; import jakarta.servlet.AsyncContext; import io.papermc.paper.threadedregions.scheduler.ScheduledTask; @@ -23,9 +24,7 @@ import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; -import java.lang.reflect.Method; import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.Function; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.KeybindComponent; @@ -94,7 +93,7 @@ public final class PlayerInventoryBroadcaster try { - NbtApiBridge.preload(); + NBT.preloadApi(); } catch (Throwable t) { @@ -444,7 +443,10 @@ public final class PlayerInventoryBroadcaster try { - String snbt = NbtApiBridge.toSnbt(item); + String snbt = NBT.get(item, nbt -> + { + return nbt.toString(); + }); if (snbt != null && !snbt.isEmpty() && !"{}".equals(snbt)) { putLimited(m, "nbt", snbt, MAX_NBT_CHARS); @@ -457,42 +459,6 @@ public final class PlayerInventoryBroadcaster private record LimitedText(String text, int totalChars, boolean truncated) {} - private static final class NbtApiBridge - { - private static volatile Method getMethod; - private static volatile Method preloadMethod; - static void preload() throws Exception - { - Method method = preloadMethod; - if (method == null) - { - Class nbt = nbtClass(); - method = nbt.getMethod("preloadApi"); - preloadMethod = method; - } - method.invoke(null); - } - - static String toSnbt(ItemStack item) throws Exception - { - Method method = getMethod; - if (method == null) - { - Class nbt = nbtClass(); - method = nbt.getMethod("get", ItemStack.class, Function.class); - getMethod = method; - } - Function stringify = Object::toString; - Object result = method.invoke(null, item, stringify); - return result instanceof String s ? s : null; - } - - private static Class nbtClass() throws ClassNotFoundException - { - return Class.forName("de.tr7zw.changeme.nbtapi.NBT", true, PlayerInventoryBroadcaster.class.getClassLoader()); - } - } - private static final class Subscriber { final AsyncContext ctx; diff --git a/src/main/resources/module.yml b/src/main/resources/module.yml index 8ae7dd0..0237ec2 100644 --- a/src/main/resources/module.yml +++ b/src/main/resources/module.yml @@ -1,5 +1,5 @@ name: Module-HTTPD -version: 2.0 +version: 2.0-SNAPSHOT description: HTTPD server for Plex main: dev.plex.HTTPDModule apiCompatibility: 1 \ No newline at end of file