diff --git a/backend/src/main/resources/configs/custom-placeholders.yml b/backend/src/main/resources/configs/custom-placeholders.yml index 469beff..840c623 100644 --- a/backend/src/main/resources/configs/custom-placeholders.yml +++ b/backend/src/main/resources/configs/custom-placeholders.yml @@ -70,31 +70,31 @@ nameplate-text: background-text: location: background: bedrock_1 - text: '%np_image_compass% %np_shift_location%' + text: '%np_image_compass% %np_shift_location%' shadow: false left-margin: 1 right-margin: 1 time: background: bedrock_1 - text: '%np_image_clock% %np_shift_time%' + text: '%np_image_clock% %np_shift_time%' shadow: false left-margin: 1 right-margin: 1 weather: background: bedrock_1 - text: '%np_image_weather% %np_shift_weather%' + text: '%np_image_weather% %np_shift_weather%' shadow: false left-margin: 1 right-margin: 1 hello: background: bedrock_1 - text: '%np_image_bubble% %np_shift_hello%' + text: '%np_image_bubble% %np_shift_hello%' shadow: false left-margin: 1 right-margin: 1 update: background: bedrock_1 - text: '%np_image_bell% %np_shift_update%' + text: '%np_image_bell% %np_shift_update%' shadow: false left-margin: 1 right-margin: 1 diff --git a/gradle.properties b/gradle.properties index 9b63550..da26a59 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,7 +18,7 @@ asm_commons_version=9.7.1 jar_relocator_version=1.7 h2_driver_version=2.3.232 sqlite_driver_version=3.48.0.0 -adventure_bundle_version=4.18.0 +adventure_bundle_version=4.19.0 adventure_platform_version=4.3.5-SNAPSHOT cloud_core_version=2.0.0 cloud_services_version=2.0.0 diff --git a/platforms/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/BukkitNetworkManager.java b/platforms/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/BukkitNetworkManager.java index 3d0a96f..728dabd 100644 --- a/platforms/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/BukkitNetworkManager.java +++ b/platforms/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/BukkitNetworkManager.java @@ -36,6 +36,7 @@ import org.jetbrains.annotations.NotNull; import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; import java.util.function.BiConsumer; diff --git a/platforms/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/util/EntityDataValue.java b/platforms/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/util/EntityDataValue.java index 5da8e8e..6781e59 100644 --- a/platforms/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/util/EntityDataValue.java +++ b/platforms/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/util/EntityDataValue.java @@ -20,6 +20,8 @@ package net.momirealms.customnameplates.bukkit.util; import net.momirealms.customnameplates.api.helper.VersionHelper; import net.momirealms.customnameplates.common.util.ReflectionUtils; +import java.util.Objects; + public class EntityDataValue { private static int internalID = 0; @@ -103,7 +105,7 @@ public class EntityDataValue { } private static Object initSerializersByName(String name) throws ReflectiveOperationException { - return ReflectionUtils.getDeclaredField(Reflections.clazz$EntityDataSerializers, new String[]{fieldsObf[internalID++], name}).get(null); + return Objects.requireNonNull(ReflectionUtils.getDeclaredField(Reflections.clazz$EntityDataSerializers, new String[]{fieldsObf[internalID++], name}).get(null)); } private EntityDataValue() { diff --git a/platforms/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/util/Reflections.java b/platforms/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/util/Reflections.java index 6f4f346..249275a 100644 --- a/platforms/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/util/Reflections.java +++ b/platforms/bukkit/src/main/java/net/momirealms/customnameplates/bukkit/util/Reflections.java @@ -478,34 +478,6 @@ public class Reflections { ) ); - public static final Field field$EntityType$TEXT_DISPLAY; - - static { - if (VersionHelper.isVersionNewerThan1_20_5()) { - field$EntityType$TEXT_DISPLAY = ReflectionUtils.getDeclaredField( - clazz$EntityType, - "TEXT_DISPLAY", "bb"); - } else if (VersionHelper.isVersionNewerThan1_20_4()) { - field$EntityType$TEXT_DISPLAY = ReflectionUtils.getDeclaredField( - clazz$EntityType, - "TEXT_DISPLAY", "aY"); - } else { - field$EntityType$TEXT_DISPLAY = ReflectionUtils.getDeclaredField( - clazz$EntityType, - "TEXT_DISPLAY", "aX"); - } - } - - public static final Object instance$EntityType$TEXT_DISPLAY; - - static { - try { - instance$EntityType$TEXT_DISPLAY = field$EntityType$TEXT_DISPLAY.get(clazz$EntityType); - } catch (IllegalAccessException e) { - throw new AssertionError(e); - } - } - public static final Constructor constructor$ClientboundAddEntityPacket = requireNonNull( ReflectionUtils.getConstructor(clazz$ClientboundAddEntityPacket, int.class, UUID.class, @@ -1130,4 +1102,62 @@ public class Reflections { clazz$AttributeModifier, clazz$AttributeModifier$Operation, 0 ) ); + + public static final Method method$ResourceLocation$fromNamespaceAndPath = requireNonNull( + ReflectionUtils.getStaticMethod( + clazz$ResourceLocation, clazz$ResourceLocation, String.class, String.class + ) + ); + + public static final Object instance$BuiltInRegistries$ENTITY_TYPE; + public static final Object instance$Registries$ENTITY_TYPE; + public static final Object instance$registryAccess; + + static { + Field[] fields = clazz$Registries.getDeclaredFields(); + try { + Object registries$EntityType = null; + for (Field field : fields) { + Type fieldType = field.getGenericType(); + if (fieldType instanceof ParameterizedType paramType) { + if (paramType.getRawType() == clazz$ResourceKey) { + Type[] actualTypeArguments = paramType.getActualTypeArguments(); + if (actualTypeArguments.length == 1 && actualTypeArguments[0] instanceof ParameterizedType registryType) { + Type type = registryType.getActualTypeArguments()[0]; + if (type instanceof ParameterizedType parameterizedType) { + Type rawType = parameterizedType.getRawType(); + if (rawType == clazz$EntityType) { + registries$EntityType = field.get(null); + } + } + } + } + } + } + instance$Registries$ENTITY_TYPE = requireNonNull(registries$EntityType); + Object server = method$MinecraftServer$getServer.invoke(null); + Object registries = field$MinecraftServer$registries.get(server); + instance$registryAccess = field$LayeredRegistryAccess$composite.get(registries); + instance$BuiltInRegistries$ENTITY_TYPE = method$RegistryAccess$registryOrThrow.invoke(instance$registryAccess, registries$EntityType); + } catch (ReflectiveOperationException e) { + throw new RuntimeException(e); + } + } + + public static final Method method$Registry$get = requireNonNull( + ReflectionUtils.getMethods( + clazz$Registry, Object.class, clazz$ResourceLocation + ).stream().filter(m -> m.getReturnType() != Optional.class).findAny().orElse(null) + ); + + public static final Object instance$EntityType$TEXT_DISPLAY; + + static { + try { + Object textDisplay = method$ResourceLocation$fromNamespaceAndPath.invoke(null, "minecraft", "text_display"); + instance$EntityType$TEXT_DISPLAY = Reflections.method$Registry$get.invoke(Reflections.instance$BuiltInRegistries$ENTITY_TYPE, textDisplay); + } catch (ReflectiveOperationException e) { + throw new RuntimeException(e); + } + } }