Skip to content

Commit 582084b

Browse files
committed
Dev
1 parent b0f96ce commit 582084b

3 files changed

Lines changed: 8 additions & 42 deletions

File tree

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
}
77

88
group = "dev.plex"
9-
version = "2.0"
9+
version = "2.0-SNAPSHOT"
1010
description = "Module-HTTPD"
1111

1212
repositories {

src/main/java/dev/plex/request/impl/PlayerInventoryBroadcaster.java

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dev.plex.request.impl;
22

33
import com.google.gson.GsonBuilder;
4+
import de.tr7zw.changeme.nbtapi.NBT;
45
import dev.plex.HTTPDModule;
56
import jakarta.servlet.AsyncContext;
67
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
@@ -23,9 +24,7 @@
2324
import java.util.concurrent.ConcurrentHashMap;
2425
import java.util.concurrent.Executors;
2526
import java.util.concurrent.ScheduledExecutorService;
26-
import java.lang.reflect.Method;
2727
import java.util.concurrent.atomic.AtomicInteger;
28-
import java.util.function.Function;
2928

3029
import net.kyori.adventure.text.Component;
3130
import net.kyori.adventure.text.KeybindComponent;
@@ -94,7 +93,7 @@ public synchronized void start()
9493

9594
try
9695
{
97-
NbtApiBridge.preload();
96+
NBT.preloadApi();
9897
}
9998
catch (Throwable t)
10099
{
@@ -444,7 +443,10 @@ private static Map<String, Object> serializeItem(ItemStack item)
444443

445444
try
446445
{
447-
String snbt = NbtApiBridge.toSnbt(item);
446+
String snbt = NBT.get(item, nbt ->
447+
{
448+
return nbt.toString();
449+
});
448450
if (snbt != null && !snbt.isEmpty() && !"{}".equals(snbt))
449451
{
450452
putLimited(m, "nbt", snbt, MAX_NBT_CHARS);
@@ -457,42 +459,6 @@ private static Map<String, Object> serializeItem(ItemStack item)
457459

458460
private record LimitedText(String text, int totalChars, boolean truncated) {}
459461

460-
private static final class NbtApiBridge
461-
{
462-
private static volatile Method getMethod;
463-
private static volatile Method preloadMethod;
464-
static void preload() throws Exception
465-
{
466-
Method method = preloadMethod;
467-
if (method == null)
468-
{
469-
Class<?> nbt = nbtClass();
470-
method = nbt.getMethod("preloadApi");
471-
preloadMethod = method;
472-
}
473-
method.invoke(null);
474-
}
475-
476-
static String toSnbt(ItemStack item) throws Exception
477-
{
478-
Method method = getMethod;
479-
if (method == null)
480-
{
481-
Class<?> nbt = nbtClass();
482-
method = nbt.getMethod("get", ItemStack.class, Function.class);
483-
getMethod = method;
484-
}
485-
Function<Object, String> stringify = Object::toString;
486-
Object result = method.invoke(null, item, stringify);
487-
return result instanceof String s ? s : null;
488-
}
489-
490-
private static Class<?> nbtClass() throws ClassNotFoundException
491-
{
492-
return Class.forName("de.tr7zw.changeme.nbtapi.NBT", true, PlayerInventoryBroadcaster.class.getClassLoader());
493-
}
494-
}
495-
496462
private static final class Subscriber
497463
{
498464
final AsyncContext ctx;

src/main/resources/module.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: Module-HTTPD
2-
version: 2.0
2+
version: 2.0-SNAPSHOT
33
description: HTTPD server for Plex
44
main: dev.plex.HTTPDModule
55
apiCompatibility: 1

0 commit comments

Comments
 (0)