11package dev .plex .request .impl ;
22
33import com .google .gson .GsonBuilder ;
4+ import de .tr7zw .changeme .nbtapi .NBT ;
45import dev .plex .HTTPDModule ;
56import jakarta .servlet .AsyncContext ;
67import io .papermc .paper .threadedregions .scheduler .ScheduledTask ;
2324import java .util .concurrent .ConcurrentHashMap ;
2425import java .util .concurrent .Executors ;
2526import java .util .concurrent .ScheduledExecutorService ;
26- import java .lang .reflect .Method ;
2727import java .util .concurrent .atomic .AtomicInteger ;
28- import java .util .function .Function ;
2928
3029import net .kyori .adventure .text .Component ;
3130import 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 ;
0 commit comments