diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/BlockEventListener.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/BlockEventListener.java index 88c6c4617..f8879f586 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/BlockEventListener.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/BlockEventListener.java @@ -70,7 +70,7 @@ public class BlockEventListener implements Listener { try { Object soundType = Reflections.field$BlockBehaviour$soundType.get(ownerBlock); Object placeSound = Reflections.field$SoundType$placeSound.get(soundType); - player.playSound(block.getLocation(), Reflections.field$SoundEvent$location.get(placeSound).toString(), SoundCategory.BLOCKS, 1f, 0.8f); + player.playSound(block.getLocation(), FastNMS.INSTANCE.field$SoundEvent$location(placeSound).toString(), SoundCategory.BLOCKS, 1f, 0.8f); } catch (ReflectiveOperationException e) { this.plugin.logger().warn("Failed to get sound type", e); } @@ -87,7 +87,7 @@ public class BlockEventListener implements Listener { Object ownerBlock = BlockStateUtils.getBlockOwner(blockState); Object soundType = Reflections.field$BlockBehaviour$soundType.get(ownerBlock); Object placeSound = Reflections.field$SoundType$placeSound.get(soundType); - player.playSound(block.getLocation(), Reflections.field$SoundEvent$location.get(placeSound).toString(), SoundCategory.BLOCKS, 1f, 0.8f); + player.playSound(block.getLocation(), FastNMS.INSTANCE.field$SoundEvent$location(placeSound).toString(), SoundCategory.BLOCKS, 1f, 0.8f); } catch (ReflectiveOperationException e) { this.plugin.logger().warn("Failed to get sound type", e); } @@ -179,7 +179,7 @@ public class BlockEventListener implements Listener { try { Object soundType = Reflections.field$BlockBehaviour$soundType.get(ownerBlock); Object breakSound = Reflections.field$SoundType$breakSound.get(soundType); - block.getWorld().playSound(block.getLocation(), Reflections.field$SoundEvent$location.get(breakSound).toString(), SoundCategory.BLOCKS, 1f, 0.8f); + block.getWorld().playSound(block.getLocation(), FastNMS.INSTANCE.field$SoundEvent$location(breakSound).toString(), SoundCategory.BLOCKS, 1f, 0.8f); } catch (ReflectiveOperationException e) { this.plugin.logger().warn("Failed to get sound type", e); } @@ -251,7 +251,7 @@ public class BlockEventListener implements Listener { try { Object soundType = Reflections.field$BlockBehaviour$soundType.get(ownerBlock); Object stepSound = Reflections.field$SoundType$stepSound.get(soundType); - player.playSound(playerLocation, Reflections.field$SoundEvent$location.get(stepSound).toString(), SoundCategory.BLOCKS, 0.15f, 1f); + player.playSound(playerLocation, FastNMS.INSTANCE.field$SoundEvent$location(stepSound).toString(), SoundCategory.BLOCKS, 0.15f, 1f); } catch (ReflectiveOperationException e) { plugin.logger().warn("Failed to get sound type", e); } diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/BukkitBlockManager.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/BukkitBlockManager.java index 9f60f3af1..01b2c7495 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/BukkitBlockManager.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/BukkitBlockManager.java @@ -8,6 +8,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import dev.dejvokep.boostedyaml.YamlDocument; import net.momirealms.craftengine.bukkit.compatibility.worldedit.WorldEditBlockRegister; +import net.momirealms.craftengine.bukkit.nms.FastNMS; import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine; import net.momirealms.craftengine.bukkit.plugin.injector.BukkitInjector; import net.momirealms.craftengine.bukkit.plugin.network.PacketConsumers; @@ -327,7 +328,7 @@ public class BukkitBlockManager extends AbstractBlockManager { for (Object soundType : affectedSounds) { for (Field field : List.of(Reflections.field$SoundType$placeSound, Reflections.field$SoundType$fallSound, Reflections.field$SoundType$hitSound, Reflections.field$SoundType$stepSound, Reflections.field$SoundType$breakSound)) { Object soundEvent = field.get(soundType); - Key previousId = Key.of(Reflections.field$SoundEvent$location.get(soundEvent).toString()); + Key previousId = Key.of(FastNMS.INSTANCE.field$SoundEvent$location(soundEvent).toString()); soundMapperBuilder.put(previousId, Key.of(previousId.namespace(), "replaced." + previousId.value())); } } @@ -832,8 +833,8 @@ public class BukkitBlockManager extends AbstractBlockManager { return counter; } - private Object createResourceLocation(Key key) throws Exception { - return Reflections.method$ResourceLocation$fromNamespaceAndPath.invoke(null, key.namespace(), key.value()); + private Object createResourceLocation(Key key) { + return FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath(key.namespace(), key.value()); } private Object getBlockFromRegistry(Object resourceLocation) throws Exception { diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/LeavesBlockBehavior.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/LeavesBlockBehavior.java index 99b543466..5c4ec7e41 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/LeavesBlockBehavior.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/LeavesBlockBehavior.java @@ -117,7 +117,7 @@ public class LeavesBlockBehavior extends WaterLoggedBlockBehavior { if (event.isCancelled()) { return; } - Reflections.method$Level$removeBlock.invoke(level, blockPos, false); + FastNMS.INSTANCE.method$Level$removeBlock(level, blockPos, false); if (isWaterLogged(immutableBlockState)) { bukkitWorld.setBlockData(pos.x(), pos.y(), pos.z(), Material.WATER.createBlockData()); } diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/SugarCaneBlockBehavior.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/SugarCaneBlockBehavior.java index c11a5d511..f819125c8 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/SugarCaneBlockBehavior.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/block/behavior/SugarCaneBlockBehavior.java @@ -59,7 +59,7 @@ public class SugarCaneBlockBehavior extends BushBlockBehavior { ImmutableBlockState currentState = BukkitBlockManager.instance().getImmutableBlockState(stateId); if (currentState != null && !currentState.isEmpty()) { // break the sugar cane - Reflections.method$Level$removeBlock.invoke(level, blockPos, false); + FastNMS.INSTANCE.method$Level$removeBlock(level, blockPos, false); Vec3d vec3d = Vec3d.atCenterOf(LocationUtils.fromBlockPos(blockPos)); net.momirealms.craftengine.core.world.World world = new BukkitWorld(FastNMS.INSTANCE.method$Level$getCraftWorld(level)); ContextHolder.Builder builder = ContextHolder.builder() diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/font/BukkitFontManager.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/font/BukkitFontManager.java index 866bff3f0..91eb5f378 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/font/BukkitFontManager.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/font/BukkitFontManager.java @@ -32,9 +32,7 @@ import org.bukkit.inventory.meta.BookMeta; import org.bukkit.inventory.view.AnvilView; import java.lang.reflect.InvocationTargetException; -import java.util.List; -import java.util.Map; -import java.util.UUID; +import java.util.*; public class BukkitFontManager extends AbstractFontManager implements Listener { private final BukkitCraftEngine plugin; @@ -57,11 +55,11 @@ public class BukkitFontManager extends AbstractFontManager implements Listener { @Override public void delayedLoad() { - Map oldCachedEmojiSuggestions = this.oldCachedEmojiSuggestions(); + List oldCachedEmojiSuggestions = this.oldCachedEmojiSuggestions(); super.delayedLoad(); - this.oldCachedEmojiSuggestions.putAll(this.cachedEmojiSuggestions()); + this.oldCachedEmojiSuggestions.addAll(this.cachedEmojiSuggestions()); Bukkit.getOnlinePlayers().forEach(player -> { - FastNMS.INSTANCE.method$ChatSuggestions$remove(oldCachedEmojiSuggestions.keySet(), player); + player.removeCustomChatCompletions(oldCachedEmojiSuggestions); this.addEmojiSuggestions(player); }); } @@ -73,18 +71,17 @@ public class BukkitFontManager extends AbstractFontManager implements Listener { } private void addEmojiSuggestions(Player player) { - Map hasPermissions = new HashMap<>(); - Map cachedEmojiSuggestions = this.cachedEmojiSuggestions(); - for (UUID uuid : cachedEmojiSuggestions.keySet()) { - String keyword = cachedEmojiSuggestions.get(uuid); + List hasPermissions = new ArrayList<>(); + List cachedEmojiSuggestions = this.cachedEmojiSuggestions(); + for (String keyword : cachedEmojiSuggestions) { Emoji emoji = super.emojiMapper.get(keyword); if (emoji == null) continue; if (emoji.permission() != null && !player.hasPermission(Objects.requireNonNull(emoji.permission()))) { continue; } - hasPermissions.put(uuid, keyword); + hasPermissions.add(keyword); } - FastNMS.INSTANCE.method$ChatSuggestions$add(hasPermissions, player); + player.addCustomChatCompletions(hasPermissions); } @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/recipe/BukkitRecipeManager.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/recipe/BukkitRecipeManager.java index bd548bb67..663ec5371 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/recipe/BukkitRecipeManager.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/item/recipe/BukkitRecipeManager.java @@ -655,7 +655,7 @@ public class BukkitRecipeManager extends AbstractRecipeManager { jsonObject.add("components", result.components()); Object nmsStack = ItemObject.newItem(TagCompound.newTag(jsonObject.toString())); try { - itemStack = (ItemStack) Reflections.method$CraftItemStack$asCraftMirror.invoke(null, nmsStack); + itemStack = FastNMS.INSTANCE.method$CraftItemStack$asCraftMirror(nmsStack); } catch (Exception e) { this.plugin.logger().warn("Failed to create ItemStack mirror", e); return new ItemStack(Material.STICK); diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/network/PacketConsumers.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/network/PacketConsumers.java index 85708dc2a..a618c49df 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/network/PacketConsumers.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/network/PacketConsumers.java @@ -43,7 +43,6 @@ import java.lang.reflect.InvocationTargetException; import java.nio.charset.StandardCharsets; import java.util.*; import java.util.function.BiConsumer; -import java.util.function.Consumer; public class PacketConsumers { private static int[] mappings; @@ -1118,7 +1117,7 @@ public class PacketConsumers { if (!user.isOnline()) return; BukkitServerPlayer player = (BukkitServerPlayer) user; if (!player.isMiningBlock()) return; - Object hand = Reflections.field$ServerboundSwingPacket$hand.get(packet); + Object hand = FastNMS.INSTANCE.field$ServerboundSwingPacket$hand(packet); if (hand == Reflections.instance$InteractionHand$MAIN_HAND) { player.onSwingHand(); } @@ -1150,7 +1149,7 @@ public class PacketConsumers { Object commonInfo = Reflections.field$ClientboundRespawnPacket$commonPlayerSpawnInfo.get(packet); dimensionKey = Reflections.field$CommonPlayerSpawnInfo$dimension.get(commonInfo); } - Object location = Reflections.field$ResourceKey$location.get(dimensionKey); + Object location = FastNMS.INSTANCE.field$ResourceKey$location(dimensionKey); World world = Bukkit.getWorld(Objects.requireNonNull(NamespacedKey.fromString(location.toString()))); if (world != null) { int sectionCount = (world.getMaxHeight() - world.getMinHeight()) / 16; @@ -1175,7 +1174,7 @@ public class PacketConsumers { Object commonInfo = Reflections.field$ClientboundLoginPacket$commonPlayerSpawnInfo.get(packet); dimensionKey = Reflections.field$CommonPlayerSpawnInfo$dimension.get(commonInfo); } - Object location = Reflections.field$ResourceKey$location.get(dimensionKey); + Object location = FastNMS.INSTANCE.field$ResourceKey$location(dimensionKey); World world = Bukkit.getWorld(Objects.requireNonNull(NamespacedKey.fromString(location.toString()))); if (world != null) { int sectionCount = (world.getMaxHeight() - world.getMinHeight()) / 16; @@ -1219,7 +1218,7 @@ public class PacketConsumers { if (bukkitPlayer.getGameMode() != GameMode.CREATIVE) return; int slot = VersionHelper.isVersionNewerThan1_20_5() ? Reflections.field$ServerboundSetCreativeModeSlotPacket$slotNum.getShort(packet) : Reflections.field$ServerboundSetCreativeModeSlotPacket$slotNum.getInt(packet); if (slot < 36 || slot > 44) return; - ItemStack item = (ItemStack) Reflections.method$CraftItemStack$asCraftMirror.invoke(null, Reflections.field$ServerboundSetCreativeModeSlotPacket$itemStack.get(packet)); + ItemStack item = FastNMS.INSTANCE.method$CraftItemStack$asCraftMirror(Reflections.field$ServerboundSetCreativeModeSlotPacket$itemStack.get(packet)); if (ItemUtils.isEmpty(item)) return; if (slot - 36 != bukkitPlayer.getInventory().getHeldItemSlot()) { return; diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/user/BukkitServerPlayer.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/user/BukkitServerPlayer.java index d1f9487b3..398b5528b 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/user/BukkitServerPlayer.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/plugin/user/BukkitServerPlayer.java @@ -424,7 +424,7 @@ public class BukkitServerPlayer extends Player { Object blockOwner = Reflections.field$StateHolder$owner.get(this.destroyedState); Object soundType = Reflections.field$BlockBehaviour$soundType.get(blockOwner); Object soundEvent = Reflections.field$SoundType$hitSound.get(soundType); - Object soundId = Reflections.field$SoundEvent$location.get(soundEvent); + Object soundId = FastNMS.INSTANCE.field$SoundEvent$location(soundEvent); player.playSound(location, soundId.toString(), SoundCategory.BLOCKS, 0.5F, 0.5F); this.lastHitBlockTime = currentTick; } diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/util/BlockStateUtils.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/util/BlockStateUtils.java index 0869b5437..bbce5ef50 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/util/BlockStateUtils.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/util/BlockStateUtils.java @@ -128,7 +128,7 @@ public class BlockStateUtils { public static int physicsEventToId(BlockPhysicsEvent event) throws ReflectiveOperationException { Object blockData = Reflections.field$BlockPhysicsEvent$changed.get(event); Object blockState = Reflections.field$CraftBlockData$data.get(blockData); - return (int) Reflections.method$IdMapper$getId.invoke(Reflections.instance$BLOCK_STATE_REGISTRY, blockState); + return FastNMS.INSTANCE.method$IdMapper$getId(Reflections.instance$BLOCK_STATE_REGISTRY, blockState); } public static Object physicsEventToState(BlockPhysicsEvent event) throws ReflectiveOperationException { diff --git a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/util/Reflections.java b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/util/Reflections.java index ba09578a0..fdb961d06 100644 --- a/bukkit/src/main/java/net/momirealms/craftengine/bukkit/util/Reflections.java +++ b/bukkit/src/main/java/net/momirealms/craftengine/bukkit/util/Reflections.java @@ -11,6 +11,7 @@ import io.netty.handler.codec.ByteToMessageDecoder; import io.netty.handler.codec.MessageToByteEncoder; import io.papermc.paper.event.player.AsyncChatDecorateEvent; import net.kyori.adventure.text.Component; +import net.momirealms.craftengine.bukkit.nms.FastNMS; import net.momirealms.craftengine.core.util.ReflectionUtils; import net.momirealms.craftengine.core.util.VersionHelper; import org.bukkit.Location; @@ -405,18 +406,21 @@ public class Reflections { BukkitReflectionUtils.assembleMCClass("core.HolderLookup$b") ); + @Deprecated public static final Method method$Component$Serializer$fromJson0 = ReflectionUtils.getMethod( clazz$Component$Serializer, new String[] { "fromJson" }, String.class, clazz$HolderLookup$Provider ); + @Deprecated public static final Method method$Component$Serializer$fromJson1 = ReflectionUtils.getMethod( clazz$Component$Serializer, new String[] { "fromJson" }, JsonElement.class, clazz$HolderLookup$Provider ); + @Deprecated public static final Method method$Component$Serializer$toJson = ReflectionUtils.getMethod( clazz$Component$Serializer, new String[] { "toJson" }, @@ -488,6 +492,7 @@ public class Reflections { ReflectionUtils.getInstanceDeclaredField(clazz$ServerPlayer, clazz$ServerGamePacketListenerImpl, 0) ); + @Deprecated public static final Method method$ServerGamePacketListenerImpl$sendPacket = requireNonNull( ReflectionUtils.getMethods(clazz$ServerGamePacketListenerImpl, void.class, clazz$Packet).get(0) ); @@ -547,12 +552,14 @@ public class Reflections { ) ); + @Deprecated public static final Field field$ClientboundAddEntityPacket$data = requireNonNull( ReflectionUtils.getDeclaredField( clazz$ClientboundAddEntityPacket, int.class, 4 ) ); + @Deprecated public static final Field field$ClientboundAddEntityPacket$type = requireNonNull( ReflectionUtils.getDeclaredField( clazz$ClientboundAddEntityPacket, clazz$EntityType, 0 @@ -577,6 +584,7 @@ public class Reflections { // ) // ); + @Deprecated public static final Field field$ClientboundAddEntityPacket$entityId = requireNonNull( ReflectionUtils.getDeclaredField( clazz$ClientboundAddEntityPacket, int.class, 0 @@ -595,18 +603,21 @@ public class Reflections { ) ); + @Deprecated public static final Field field$Vec3$x = requireNonNull( ReflectionUtils.getInstanceDeclaredField( clazz$Vec3, double.class, 0 ) ); + @Deprecated public static final Field field$Vec3$y = requireNonNull( ReflectionUtils.getInstanceDeclaredField( clazz$Vec3, double.class, 1 ) ); + @Deprecated public static final Field field$Vec3$z = requireNonNull( ReflectionUtils.getInstanceDeclaredField( clazz$Vec3, double.class, 2 @@ -1086,6 +1097,7 @@ public class Reflections { ) ); + @Deprecated public static final Field field$ResourceKey$location = requireNonNull( ReflectionUtils.getDeclaredField( clazz$ResourceKey, clazz$ResourceLocation, 1 @@ -1454,10 +1466,12 @@ public class Reflections { ReflectionUtils.getMethod(clazz$IdMapper, int.class) ); + @Deprecated public static final Method method$IdMapper$getId = requireNonNull( ReflectionUtils.getMethod(clazz$IdMapper, int.class, Object.class) ); + @Deprecated public static final Method method$IdMapper$byId = requireNonNull( ReflectionUtils.getMethod(clazz$IdMapper, Object.class, int.class) ); @@ -1643,6 +1657,7 @@ public class Reflections { BukkitReflectionUtils.assembleMCClass("network.RegistryFriendlyByteBuf") ); + @Deprecated public static final Constructor constructor$RegistryFriendlyByteBuf = Optional.ofNullable(clazz$RegistryFriendlyByteBuf) .map(it -> ReflectionUtils.getConstructor(it, 0)) .orElse(null); @@ -1751,6 +1766,7 @@ public class Reflections { ) ); + @Deprecated public static final Field field$ClientboundLevelChunkWithLightPacket$chunkData = requireNonNull( ReflectionUtils.getDeclaredField( clazz$ClientboundLevelChunkWithLightPacket, clazz$ClientboundLevelChunkPacketData, 0 @@ -1787,6 +1803,7 @@ public class Reflections { ) ); + @Deprecated public static final Field field$CraftChunk$worldServer = requireNonNull( ReflectionUtils.getDeclaredField( clazz$CraftChunk, clazz$ServerLevel, 0 @@ -2165,6 +2182,7 @@ public class Reflections { } } + @Deprecated public static final Method method$ResourceLocation$fromNamespaceAndPath = requireNonNull( ReflectionUtils.getStaticMethod( clazz$ResourceLocation, clazz$ResourceLocation, String.class, String.class @@ -2443,6 +2461,7 @@ public class Reflections { ) ); + @Deprecated public static final Constructor constructor$AABB = requireNonNull( ReflectionUtils.getConstructor( clazz$AABB, double.class, double.class, double.class, double.class, double.class, double.class @@ -2562,12 +2581,14 @@ public class Reflections { ) ); + @Deprecated public static final Field field$ClientboundLevelParticlesPacket$particle = requireNonNull( ReflectionUtils.getDeclaredField( clazz$ClientboundLevelParticlesPacket, clazz$ParticleOptions, 0 ) ); + @Deprecated public static final Field field$BlockParticleOption$blockState = requireNonNull( ReflectionUtils.getDeclaredField( clazz$BlockParticleOption, clazz$BlockState, 0 @@ -2634,6 +2655,7 @@ public class Reflections { ) ); + @Deprecated public static final Field field$SoundEvent$location = requireNonNull( ReflectionUtils.getInstanceDeclaredField( clazz$SoundEvent, clazz$ResourceLocation, 0 @@ -2673,6 +2695,7 @@ public class Reflections { ) ); + @Deprecated public static final Constructor constructor$ClientboundLightUpdatePacket = requireNonNull( ReflectionUtils.getConstructor( clazz$ClientboundLightUpdatePacket, clazz$ChunkPos, clazz$LevelLightEngine, BitSet.class, BitSet.class @@ -2713,6 +2736,7 @@ public class Reflections { ); // 1.20 ~ 1.21.4 moonrise + @Deprecated public static final Method method$ChunkHolder$getPlayers = ReflectionUtils.getMethod( clazz$ChunkHolder, List.class, boolean.class @@ -2792,12 +2816,14 @@ public class Reflections { ) ); + @Deprecated public static final Field field$ServerboundPlayerActionPacket$pos = requireNonNull( ReflectionUtils.getDeclaredField( clazz$ServerboundPlayerActionPacket, clazz$BlockPos, 0 ) ); + @Deprecated public static final Field field$ServerboundPlayerActionPacket$action = requireNonNull( ReflectionUtils.getDeclaredField( clazz$ServerboundPlayerActionPacket, clazz$ServerboundPlayerActionPacket$Action, 0 @@ -2832,17 +2858,17 @@ public class Reflections { static { try { if (VersionHelper.isVersionNewerThan1_20_5()) { - Object block_break_speed = method$ResourceLocation$fromNamespaceAndPath.invoke(null, "minecraft", VersionHelper.isVersionNewerThan1_21_2() ? "block_break_speed" : "player.block_break_speed"); + Object block_break_speed = FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", VersionHelper.isVersionNewerThan1_21_2() ? "block_break_speed" : "player.block_break_speed"); @SuppressWarnings("unchecked") Optional breakSpeedHolder = (Optional) method$Registry$getHolder0.invoke(instance$BuiltInRegistries$ATTRIBUTE, block_break_speed); instance$Holder$Attribute$block_break_speed = breakSpeedHolder.orElse(null); - Object block_interaction_range = method$ResourceLocation$fromNamespaceAndPath.invoke(null, "minecraft", VersionHelper.isVersionNewerThan1_21_2() ? "block_interaction_range" : "player.block_interaction_range"); + Object block_interaction_range = FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", VersionHelper.isVersionNewerThan1_21_2() ? "block_interaction_range" : "player.block_interaction_range"); @SuppressWarnings("unchecked") Optional blockInteractionRangeHolder = (Optional) method$Registry$getHolder0.invoke(instance$BuiltInRegistries$ATTRIBUTE, block_interaction_range); instance$Holder$Attribute$block_interaction_range = blockInteractionRangeHolder.orElse(null); - Object scale = method$ResourceLocation$fromNamespaceAndPath.invoke(null, "minecraft", VersionHelper.isVersionNewerThan1_21_2() ? "scale" : "generic.scale"); + Object scale = FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", VersionHelper.isVersionNewerThan1_21_2() ? "scale" : "generic.scale"); @SuppressWarnings("unchecked") Optional scaleHolder = (Optional) method$Registry$getHolder0.invoke(instance$BuiltInRegistries$ATTRIBUTE, scale); instance$Holder$Attribute$scale = scaleHolder.orElse(null); @@ -2986,6 +3012,7 @@ public class Reflections { ) ); + @Deprecated public static final Field field$ServerboundSwingPacket$hand = requireNonNull( ReflectionUtils.getDeclaredField( clazz$ServerboundSwingPacket, clazz$InteractionHand, 0 @@ -3198,11 +3225,11 @@ public class Reflections { // for 1.20.1-1.20.4 static { try { - Object mining_fatigue = method$ResourceLocation$fromNamespaceAndPath.invoke(null, "minecraft", "mining_fatigue"); + Object mining_fatigue = FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", "mining_fatigue"); instance$MobEffecr$mining_fatigue = method$Registry$get.invoke(instance$BuiltInRegistries$MOB_EFFECT, mining_fatigue); - Object haste = method$ResourceLocation$fromNamespaceAndPath.invoke(null, "minecraft", "haste"); + Object haste = FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", "haste"); instance$MobEffecr$haste = method$Registry$get.invoke(instance$BuiltInRegistries$MOB_EFFECT, haste); - Object invisibility = method$ResourceLocation$fromNamespaceAndPath.invoke(null, "minecraft", "invisibility"); + Object invisibility = FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", "invisibility"); instance$MobEffecr$invisibility = method$Registry$get.invoke(instance$BuiltInRegistries$MOB_EFFECT, invisibility); } catch (ReflectiveOperationException e) { throw new RuntimeException(e); @@ -3289,7 +3316,7 @@ public class Reflections { static { try { - Object key = method$ResourceLocation$fromNamespaceAndPath.invoke(null, "minecraft", "intentionally_empty"); + Object key = FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", "intentionally_empty"); instance$SoundEvent$EMPTY = method$Registry$get.invoke(instance$BuiltInRegistries$SOUND_EVENT, key); } catch (ReflectiveOperationException e) { throw new RuntimeException(e); @@ -3361,6 +3388,7 @@ public class Reflections { ) ); + @Deprecated public static final Method method$CraftItemStack$asCraftMirror = requireNonNull( ReflectionUtils.getStaticMethod( clazz$CraftItemStack, clazz$CraftItemStack, new String[]{"asCraftMirror"}, clazz$ItemStack @@ -3531,17 +3559,17 @@ public class Reflections { static { try { - Object air = method$ResourceLocation$fromNamespaceAndPath.invoke(null, "minecraft", "air"); + Object air = FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", "air"); instance$Blocks$AIR = method$Registry$get.invoke(instance$BuiltInRegistries$BLOCK, air); instance$Blocks$AIR$defaultState = method$Block$defaultBlockState.invoke(instance$Blocks$AIR); - Object fire = method$ResourceLocation$fromNamespaceAndPath.invoke(null, "minecraft", "fire"); + Object fire = FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", "fire"); instance$Blocks$FIRE = method$Registry$get.invoke(instance$BuiltInRegistries$BLOCK, fire); - Object soulFire = method$ResourceLocation$fromNamespaceAndPath.invoke(null, "minecraft", "soul_fire"); + Object soulFire = FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", "soul_fire"); instance$Blocks$SOUL_FIRE = method$Registry$get.invoke(instance$BuiltInRegistries$BLOCK, soulFire); - Object stone = method$ResourceLocation$fromNamespaceAndPath.invoke(null, "minecraft", "stone"); + Object stone = FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", "stone"); instance$Blocks$STONE = method$Registry$get.invoke(instance$BuiltInRegistries$BLOCK, stone); instance$Blocks$STONE$defaultState = method$Block$defaultBlockState.invoke(instance$Blocks$STONE); - Object ice = method$ResourceLocation$fromNamespaceAndPath.invoke(null, "minecraft", "ice"); + Object ice = FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", "ice"); instance$Blocks$ICE = method$Registry$get.invoke(instance$BuiltInRegistries$BLOCK, ice); } catch (ReflectiveOperationException e) { throw new RuntimeException(e); @@ -3554,6 +3582,7 @@ public class Reflections { ) ); + @Deprecated public static final Method method$Level$removeBlock = requireNonNull( ReflectionUtils.getMethod( clazz$Level, boolean.class, clazz$BlockPos, boolean.class @@ -3723,19 +3752,19 @@ public class Reflections { static { try { - Object textDisplay = method$ResourceLocation$fromNamespaceAndPath.invoke(null, "minecraft", "text_display"); + Object textDisplay = FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", "text_display"); instance$EntityType$TEXT_DISPLAY = Reflections.method$Registry$get.invoke(Reflections.instance$BuiltInRegistries$ENTITY_TYPE, textDisplay); - Object itemDisplay = method$ResourceLocation$fromNamespaceAndPath.invoke(null, "minecraft", "item_display"); + Object itemDisplay = FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", "item_display"); instance$EntityType$ITEM_DISPLAY = Reflections.method$Registry$get.invoke(Reflections.instance$BuiltInRegistries$ENTITY_TYPE, itemDisplay); - Object blockDisplay = method$ResourceLocation$fromNamespaceAndPath.invoke(null, "minecraft", "block_display"); + Object blockDisplay = FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", "block_display"); instance$EntityType$BLOCK_DISPLAY = Reflections.method$Registry$get.invoke(Reflections.instance$BuiltInRegistries$ENTITY_TYPE, blockDisplay); - Object fallingBlock = method$ResourceLocation$fromNamespaceAndPath.invoke(null, "minecraft", "falling_block"); + Object fallingBlock = FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", "falling_block"); instance$EntityType$FALLING_BLOCK = Reflections.method$Registry$get.invoke(Reflections.instance$BuiltInRegistries$ENTITY_TYPE, fallingBlock); - Object interaction = method$ResourceLocation$fromNamespaceAndPath.invoke(null, "minecraft", "interaction"); + Object interaction = FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", "interaction"); instance$EntityType$INTERACTION = Reflections.method$Registry$get.invoke(Reflections.instance$BuiltInRegistries$ENTITY_TYPE, interaction); - Object shulker = method$ResourceLocation$fromNamespaceAndPath.invoke(null, "minecraft", "shulker"); + Object shulker = FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", "shulker"); instance$EntityType$SHULKER = Reflections.method$Registry$get.invoke(Reflections.instance$BuiltInRegistries$ENTITY_TYPE, shulker); - Object armorStand = method$ResourceLocation$fromNamespaceAndPath.invoke(null, "minecraft", "armor_stand"); + Object armorStand = FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", "armor_stand"); instance$EntityType$ARMOR_STAND = Reflections.method$Registry$get.invoke(Reflections.instance$BuiltInRegistries$ENTITY_TYPE, armorStand); } catch (ReflectiveOperationException e) { throw new RuntimeException(e); @@ -3752,13 +3781,13 @@ public class Reflections { static { try { - instance$RecipeType$CRAFTING = Reflections.method$Registry$get.invoke(Reflections.instance$BuiltInRegistries$RECIPE_TYPE, method$ResourceLocation$fromNamespaceAndPath.invoke(null, "minecraft", "crafting")); - instance$RecipeType$SMELTING = Reflections.method$Registry$get.invoke(Reflections.instance$BuiltInRegistries$RECIPE_TYPE, method$ResourceLocation$fromNamespaceAndPath.invoke(null, "minecraft", "smelting")); - instance$RecipeType$BLASTING = Reflections.method$Registry$get.invoke(Reflections.instance$BuiltInRegistries$RECIPE_TYPE, method$ResourceLocation$fromNamespaceAndPath.invoke(null, "minecraft", "blasting")); - instance$RecipeType$SMOKING = Reflections.method$Registry$get.invoke(Reflections.instance$BuiltInRegistries$RECIPE_TYPE, method$ResourceLocation$fromNamespaceAndPath.invoke(null, "minecraft", "smoking")); - instance$RecipeType$CAMPFIRE_COOKING = Reflections.method$Registry$get.invoke(Reflections.instance$BuiltInRegistries$RECIPE_TYPE, method$ResourceLocation$fromNamespaceAndPath.invoke(null, "minecraft", "campfire_cooking")); - instance$RecipeType$STONECUTTING = Reflections.method$Registry$get.invoke(Reflections.instance$BuiltInRegistries$RECIPE_TYPE, method$ResourceLocation$fromNamespaceAndPath.invoke(null, "minecraft", "stonecutting")); - instance$RecipeType$SMITHING = Reflections.method$Registry$get.invoke(Reflections.instance$BuiltInRegistries$RECIPE_TYPE, method$ResourceLocation$fromNamespaceAndPath.invoke(null, "minecraft", "smithing")); + instance$RecipeType$CRAFTING = Reflections.method$Registry$get.invoke(Reflections.instance$BuiltInRegistries$RECIPE_TYPE, FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", "crafting")); + instance$RecipeType$SMELTING = Reflections.method$Registry$get.invoke(Reflections.instance$BuiltInRegistries$RECIPE_TYPE, FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", "smelting")); + instance$RecipeType$BLASTING = Reflections.method$Registry$get.invoke(Reflections.instance$BuiltInRegistries$RECIPE_TYPE, FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", "blasting")); + instance$RecipeType$SMOKING = Reflections.method$Registry$get.invoke(Reflections.instance$BuiltInRegistries$RECIPE_TYPE, FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", "smoking")); + instance$RecipeType$CAMPFIRE_COOKING = Reflections.method$Registry$get.invoke(Reflections.instance$BuiltInRegistries$RECIPE_TYPE, FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", "campfire_cooking")); + instance$RecipeType$STONECUTTING = Reflections.method$Registry$get.invoke(Reflections.instance$BuiltInRegistries$RECIPE_TYPE, FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", "stonecutting")); + instance$RecipeType$SMITHING = Reflections.method$Registry$get.invoke(Reflections.instance$BuiltInRegistries$RECIPE_TYPE, FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", "smithing")); } catch (ReflectiveOperationException e) { throw new RuntimeException(e); } @@ -3813,6 +3842,7 @@ public class Reflections { ) ); + @Deprecated public static final Method method$BlockStateBase$onPlace = requireNonNull( ReflectionUtils.getMethod( clazz$BlockStateBase, void.class, clazz$Level, clazz$BlockPos, clazz$BlockState, boolean.class @@ -3858,10 +3888,10 @@ public class Reflections { static { try { - Object air = method$ResourceLocation$fromNamespaceAndPath.invoke(null, "minecraft", "air"); + Object air = FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", "air"); instance$Items$AIR = method$Registry$get.invoke(Reflections.instance$BuiltInRegistries$ITEM, air); instance$ItemStack$Air = constructor$ItemStack.newInstance(instance$Items$AIR); - Object waterBucket = method$ResourceLocation$fromNamespaceAndPath.invoke(null, "minecraft", "water_bucket"); + Object waterBucket = FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", "water_bucket"); instance$Items$WATER_BUCKET = method$Registry$get.invoke(Reflections.instance$BuiltInRegistries$ITEM, waterBucket); } catch (ReflectiveOperationException e) { throw new RuntimeException(e); @@ -4088,15 +4118,15 @@ public class Reflections { static { try { - Object waterId = method$ResourceLocation$fromNamespaceAndPath.invoke(null, "minecraft", "water"); + Object waterId = FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", "water"); instance$Fluids$WATER = method$Registry$get.invoke(instance$BuiltInRegistries$FLUID, waterId); - Object flowingWaterId = method$ResourceLocation$fromNamespaceAndPath.invoke(null, "minecraft", "flowing_water"); + Object flowingWaterId = FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", "flowing_water"); instance$Fluids$FLOWING_WATER = method$Registry$get.invoke(instance$BuiltInRegistries$FLUID, flowingWaterId); - Object lavaId = method$ResourceLocation$fromNamespaceAndPath.invoke(null, "minecraft", "lava"); + Object lavaId = FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", "lava"); instance$Fluids$LAVA = method$Registry$get.invoke(instance$BuiltInRegistries$FLUID, lavaId); - Object flowingLavaId = method$ResourceLocation$fromNamespaceAndPath.invoke(null, "minecraft", "flowing_lava"); + Object flowingLavaId = FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", "flowing_lava"); instance$Fluids$FLOWING_LAVA = method$Registry$get.invoke(instance$BuiltInRegistries$FLUID, flowingLavaId); - Object emptyId = method$ResourceLocation$fromNamespaceAndPath.invoke(null, "minecraft", "empty"); + Object emptyId = FastNMS.INSTANCE.method$ResourceLocation$fromNamespaceAndPath("minecraft", "empty"); instance$Fluids$EMPTY = method$Registry$get.invoke(instance$BuiltInRegistries$FLUID, emptyId); } catch (ReflectiveOperationException e) { throw new RuntimeException(e); @@ -4509,6 +4539,7 @@ public class Reflections { .map(it -> ReflectionUtils.getDeclaredField(it, 1)) .orElse(null); + @Deprecated public static final Field field$RecipeHolder$id = Optional.ofNullable(clazz$RecipeHolder) .map(it -> ReflectionUtils.getDeclaredField(it, 0)) .orElse(null); @@ -5967,6 +5998,7 @@ public class Reflections { ) ); + @Deprecated public static final Method method$Entity$getId = requireNonNull( VersionHelper.isVersionNewerThan1_20_5() ? ReflectionUtils.getMethod(clazz$Entity, int.class, new String[]{"getId"}) diff --git a/core/src/main/java/net/momirealms/craftengine/core/font/AbstractFontManager.java b/core/src/main/java/net/momirealms/craftengine/core/font/AbstractFontManager.java index d2dd94945..a8f466d99 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/font/AbstractFontManager.java +++ b/core/src/main/java/net/momirealms/craftengine/core/font/AbstractFontManager.java @@ -42,8 +42,8 @@ public abstract class AbstractFontManager implements FontManager { protected Map tagMapper; protected Map emojiMapper; // tab补全 - protected final Map cachedEmojiSuggestions = new HashMap<>(); - protected final Map oldCachedEmojiSuggestions = new HashMap<>(); + protected final List cachedEmojiSuggestions = new ArrayList<>(); + protected final List oldCachedEmojiSuggestions = new ArrayList<>(); public AbstractFontManager(CraftEngine plugin) { this.plugin = plugin; @@ -68,13 +68,13 @@ public abstract class AbstractFontManager implements FontManager { } @Override - public Map cachedEmojiSuggestions() { - return ImmutableMap.copyOf(this.cachedEmojiSuggestions); + public List cachedEmojiSuggestions() { + return List.copyOf(this.cachedEmojiSuggestions); } @Override - public Map oldCachedEmojiSuggestions() { - return ImmutableMap.copyOf(this.oldCachedEmojiSuggestions); + public List oldCachedEmojiSuggestions() { + return List.copyOf(this.oldCachedEmojiSuggestions); } @Override @@ -372,8 +372,7 @@ public abstract class AbstractFontManager implements FontManager { return; } String keyword = keywords.get(0); - UUID uuid = UUID.nameUUIDFromBytes(keyword.getBytes(StandardCharsets.UTF_8)); - cachedEmojiSuggestions.put(uuid, keyword); + cachedEmojiSuggestions.add(keyword); String content = section.getOrDefault("content", "").toString(); String image = null; if (section.containsKey("image")) { diff --git a/core/src/main/java/net/momirealms/craftengine/core/font/FontManager.java b/core/src/main/java/net/momirealms/craftengine/core/font/FontManager.java index 8da06423e..e685fc7a3 100644 --- a/core/src/main/java/net/momirealms/craftengine/core/font/FontManager.java +++ b/core/src/main/java/net/momirealms/craftengine/core/font/FontManager.java @@ -12,10 +12,7 @@ import net.momirealms.craftengine.core.util.Key; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Collection; -import java.util.Map; -import java.util.Optional; -import java.util.UUID; +import java.util.*; public interface FontManager extends Manageable { Key DEFAULT_FONT = Key.of("minecraft:default"); @@ -105,7 +102,7 @@ public interface FontManager extends Manageable { Map matchTags(String json); - Map cachedEmojiSuggestions(); + List cachedEmojiSuggestions(); - Map oldCachedEmojiSuggestions(); + List oldCachedEmojiSuggestions(); } diff --git a/gradle.properties b/gradle.properties index c2f32fe2c..4d122a98e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -51,7 +51,7 @@ byte_buddy_version=1.17.5 ahocorasick_version=0.6.3 snake_yaml_version=2.4 anti_grief_version=0.13 -nms_helper_version=0.54 +nms_helper_version=0.55 # Ignite Dependencies mixinextras_version=0.4.1 mixin_version=0.15.2+mixin.0.8.7