From 67e4f0c39da030c4c0fd0e371a706b743c2cfadb Mon Sep 17 00:00:00 2001 From: Lumine1909 <133463833+Lumine1909@users.noreply.github.com> Date: Tue, 21 May 2024 23:45:50 -0400 Subject: [PATCH 1/9] fix and rewrite bytebuf api --- patches/api/0011-Bytebuf-API.patch | 310 +++++++ patches/server/0135-Bytebuf-API.patch | 1144 +++++++++++++++++++++++++ 2 files changed, 1454 insertions(+) create mode 100644 patches/api/0011-Bytebuf-API.patch create mode 100644 patches/server/0135-Bytebuf-API.patch diff --git a/patches/api/0011-Bytebuf-API.patch b/patches/api/0011-Bytebuf-API.patch new file mode 100644 index 00000000..9db7387e --- /dev/null +++ b/patches/api/0011-Bytebuf-API.patch @@ -0,0 +1,310 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Lumine1909 <133463833+Lumine1909@users.noreply.github.com> +Date: Wed, 22 May 2024 10:12:04 _0800 +Subject: [PATCH] Bytebuf API + + +diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java +index 3c2b252243c1fa0d3adcc9c860c24af73165de33..acb3d0bb285b489f19fc7b1743f0b8f8f7ff1fbc 100644 +--- a/src/main/java/org/bukkit/Bukkit.java ++++ b/src/main/java/org/bukkit/Bukkit.java +@@ -2918,6 +2918,11 @@ public final class Bukkit { + return server.getPhotographerManager(); + } + // Leaves end - Photographer API ++ // Leaves start - Bytebuf API ++ public static org.leavesmc.leaves.bytebuf.BytebufManager getBytebufManager() { ++ return server.getBytebufManager(); ++ } ++ // Leaves end - Bytebuf API + + @NotNull + public static Server.Spigot spigot() { +diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java +index 4a03044938630e4a0e701bc481f15da5a3323115..66a3de19167e7c1052ae1ed6230aaa250e21503d 100644 +--- a/src/main/java/org/bukkit/Server.java ++++ b/src/main/java/org/bukkit/Server.java +@@ -2564,4 +2564,7 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi + // Leaves start - Photographer API + @NotNull PhotographerManager getPhotographerManager(); + // Leaves end - Photographer API ++ // Leaves start - Bytebuf API ++ org.leavesmc.leaves.bytebuf.BytebufManager getBytebufManager(); ++ // Leaves end - Bytebuf API + } +diff --git a/src/main/java/org/bukkit/entity/Player.java b/src/main/java/org/bukkit/entity/Player.java +index 6c327a07bf8a6aa11a2d7dad12b2830acc539484..939bdc02b917ad72a8b7e6640067da1966337e2a 100644 +--- a/src/main/java/org/bukkit/entity/Player.java ++++ b/src/main/java/org/bukkit/entity/Player.java +@@ -3801,7 +3801,10 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM + */ + boolean isChunkSent(long chunkKey); + // Paper end +- ++ // Leaves start - Bytebuf API ++ void sendPacket(org.leavesmc.leaves.bytebuf.packet.Packet packet); ++ void sendPacket(org.leavesmc.leaves.bytebuf.Bytebuf buf, org.leavesmc.leaves.bytebuf.packet.PacketType type); ++ // Leaves end - Bytebuf API + @NotNull + @Override + Spigot spigot(); +diff --git a/src/main/java/org/leavesmc/leaves/bytebuf/Bytebuf.java b/src/main/java/org/leavesmc/leaves/bytebuf/Bytebuf.java +new file mode 100644 +index 0000000000000000000000000000000000000000..fd7b6e2c31aedbb5e58bd15a9a56c30f490d78c9 +--- /dev/null ++++ b/src/main/java/org/leavesmc/leaves/bytebuf/Bytebuf.java +@@ -0,0 +1,25 @@ ++package org.leavesmc.leaves.bytebuf; ++ ++import org.bukkit.Bukkit; ++ ++public interface Bytebuf { ++ static Bytebuf buf(int size) { ++ return Bukkit.getBytebufManager().newBytebuf(size); ++ } ++ static Bytebuf buf() { ++ return buf(128); ++ } ++ static Bytebuf of(byte[] bytes) { ++ return Bukkit.getBytebufManager().toBytebuf(bytes); ++ } ++ byte[] toArray(); ++ ++ Bytebuf writeByte(int i); ++ byte readByte(); ++ Bytebuf writeShort(int i); ++ short readShort(); ++ Bytebuf writeInt(int i); ++ int readInt(); ++ Bytebuf writeLong(long i); ++ long readLong(); ++} +diff --git a/src/main/java/org/leavesmc/leaves/bytebuf/BytebufManager.java b/src/main/java/org/leavesmc/leaves/bytebuf/BytebufManager.java +new file mode 100644 +index 0000000000000000000000000000000000000000..b0c759b3ea19ca10be56b232181e56d056cf3a2d +--- /dev/null ++++ b/src/main/java/org/leavesmc/leaves/bytebuf/BytebufManager.java +@@ -0,0 +1,11 @@ ++package org.leavesmc.leaves.bytebuf; ++ ++import org.bukkit.plugin.Plugin; ++import org.leavesmc.leaves.bytebuf.packet.PacketListener; ++ ++public interface BytebufManager { ++ void registerListener(Plugin plugin, PacketListener listener); ++ void unregisterListener(Plugin plugin, PacketListener listener); ++ Bytebuf newBytebuf(int size); ++ Bytebuf toBytebuf(byte[] bytes); ++} +diff --git a/src/main/java/org/leavesmc/leaves/bytebuf/packet/Packet.java b/src/main/java/org/leavesmc/leaves/bytebuf/packet/Packet.java +new file mode 100644 +index 0000000000000000000000000000000000000000..8bb00c16fe3e6089397cc0fcaaec4715960dd724 +--- /dev/null ++++ b/src/main/java/org/leavesmc/leaves/bytebuf/packet/Packet.java +@@ -0,0 +1,6 @@ ++package org.leavesmc.leaves.bytebuf.packet; ++ ++import org.leavesmc.leaves.bytebuf.Bytebuf; ++ ++public record Packet(PacketType type, Bytebuf bytebuf) { ++} +diff --git a/src/main/java/org/leavesmc/leaves/bytebuf/packet/PacketListener.java b/src/main/java/org/leavesmc/leaves/bytebuf/packet/PacketListener.java +new file mode 100644 +index 0000000000000000000000000000000000000000..3a8cb462287498a8b1959f31261ebbca74b62ef5 +--- /dev/null ++++ b/src/main/java/org/leavesmc/leaves/bytebuf/packet/PacketListener.java +@@ -0,0 +1,8 @@ ++package org.leavesmc.leaves.bytebuf.packet; ++ ++import org.bukkit.entity.Player; ++ ++public interface PacketListener { ++ Packet onPacketIn(Player player, Packet packet); ++ Packet onPacketOut(Player player, Packet packet); ++} +diff --git a/src/main/java/org/leavesmc/leaves/bytebuf/packet/PacketType.java b/src/main/java/org/leavesmc/leaves/bytebuf/packet/PacketType.java +new file mode 100644 +index 0000000000000000000000000000000000000000..604a65efc497267db126c6585f806d98bb5783a1 +--- /dev/null ++++ b/src/main/java/org/leavesmc/leaves/bytebuf/packet/PacketType.java +@@ -0,0 +1,180 @@ ++package org.leavesmc.leaves.bytebuf.packet; ++ ++public enum PacketType { ++ //ClientboundBundle, ++ //ClientboundBundleDelimiter, ++ ClientboundAddEntity, ++ ClientboundAddExperienceOrb, ++ ClientboundAnimate, ++ ClientboundAwardStats, ++ ClientboundBlockChangedAck, ++ ClientboundBlockDestruction, ++ ClientboundBlockEntityData, ++ ClientboundBlockEvent, ++ ClientboundBlockUpdate, ++ ClientboundBossEvent, ++ ClientboundChangeDifficulty, ++ ClientboundChunkBatchFinished, ++ ClientboundChunkBatchStart, ++ ClientboundChunksBiomes, ++ ClientboundClearTitles, ++ ClientboundCommandSuggestions, ++ ClientboundCommands, ++ ClientboundContainerClose, ++ ClientboundContainerSetContent, ++ ClientboundContainerSetData, ++ ClientboundContainerSetSlot, ++ ClientboundCooldown, ++ ClientboundCustomChatCompletions, ++ ClientboundDamageEvent, ++ ClientboundDebugSample, ++ ClientboundDeleteChat, ++ ClientboundDisguisedChat, ++ ClientboundEntityEvent, ++ ClientboundExplode, ++ ClientboundForgetLevelChunk, ++ ClientboundGameEvent, ++ ClientboundHorseScreenOpen, ++ ClientboundHurtAnimation, ++ ClientboundInitializeBorder, ++ ClientboundLevelChunkWithLight, ++ ClientboundLevelEvent, ++ ClientboundLevelParticles, ++ ClientboundLightUpdate, ++ ClientboundLogin, ++ ClientboundMapItemData, ++ ClientboundMerchantOffers, ++ ClientboundMoveEntityPos, ++ ClientboundMoveEntityPosRot, ++ ClientboundMoveEntityRot, ++ ClientboundMoveVehicle, ++ ClientboundOpenBook, ++ ClientboundOpenScreen, ++ ClientboundOpenSignEditor, ++ ClientboundPlaceGhostRecipe, ++ ClientboundPlayerAbilities, ++ ClientboundPlayerChat, ++ ClientboundPlayerCombatEnd, ++ ClientboundPlayerCombatEnter, ++ ClientboundPlayerCombatKill, ++ ClientboundPlayerInfoRemove, ++ ClientboundPlayerInfoUpdate, ++ ClientboundPlayerLookAt, ++ ClientboundPlayerPosition, ++ ClientboundRecipe, ++ ClientboundRemoveEntities, ++ ClientboundRemoveMobEffect, ++ ClientboundRespawn, ++ ClientboundRotateHead, ++ ClientboundSectionBlocksUpdate, ++ ClientboundSelectAdvancementsTab, ++ ClientboundServerData, ++ ClientboundSetActionBarText, ++ ClientboundSetBorderCenter, ++ ClientboundSetBorderLerpSize, ++ ClientboundSetBorderSize, ++ ClientboundSetBorderWarningDelay, ++ ClientboundSetBorderWarningDistance, ++ ClientboundSetCamera, ++ ClientboundSetCarriedItem, ++ ClientboundSetChunkCacheCenter, ++ ClientboundSetChunkCacheRadius, ++ ClientboundSetDefaultSpawnPosition, ++ ClientboundSetDisplayObjective, ++ ClientboundSetEntityData, ++ ClientboundSetEntityLink, ++ ClientboundSetEntityMotion, ++ ClientboundSetEquipment, ++ ClientboundSetExperience, ++ ClientboundSetHealth, ++ ClientboundSetObjective, ++ ClientboundSetPassengers, ++ ClientboundSetPlayerTeam, ++ ClientboundSetScore, ++ ClientboundSetSimulationDistance, ++ ClientboundSetSubtitleText, ++ ClientboundSetTime, ++ ClientboundSetTitleText, ++ ClientboundSetTitlesAnimation, ++ ClientboundSoundEntity, ++ ClientboundSound, ++ ClientboundStartConfiguration, ++ ClientboundStopSound, ++ ClientboundSystemChat, ++ ClientboundTabList, ++ ClientboundTagQuery, ++ ClientboundTakeItemEntity, ++ ClientboundTeleportEntity, ++ ClientboundUpdateAdvancements, ++ ClientboundUpdateAttributes, ++ ClientboundUpdateMobEffect, ++ ClientboundUpdateRecipes, ++ ClientboundProjectilePower, ++ ServerboundAcceptTeleportation, ++ ServerboundBlockEntityTagQuery, ++ ServerboundChangeDifficulty, ++ ServerboundChatAck, ++ ServerboundChatCommand, ++ ServerboundChatCommandSigned, ++ ServerboundChat, ++ ServerboundChatSessionUpdate, ++ ServerboundChunkBatchReceived, ++ ServerboundClientCommand, ++ ServerboundCommandSuggestion, ++ ServerboundConfigurationAcknowledged, ++ ServerboundContainerButtonClick, ++ ServerboundContainerClick, ++ ServerboundContainerClose, ++ ServerboundContainerSlotStateChanged, ++ ServerboundDebugSampleSubscription, ++ ServerboundEditBook, ++ ServerboundEntityTagQuery, ++ ServerboundInteract, ++ ServerboundJigsawGenerate, ++ ServerboundLockDifficulty, ++ ServerboundMovePlayerPos, ++ ServerboundMovePlayerPosRot, ++ ServerboundMovePlayerRot, ++ ServerboundMovePlayerStatusOnly, ++ ServerboundMoveVehicle, ++ ServerboundPaddleBoat, ++ ServerboundPickItem, ++ ServerboundPlaceRecipe, ++ ServerboundPlayerAbilities, ++ ServerboundPlayerAction, ++ ServerboundPlayerCommand, ++ ServerboundPlayerInput, ++ ServerboundRecipeBookChangeSettings, ++ ServerboundRecipeBookSeenRecipe, ++ ServerboundRenameItem, ++ ServerboundSeenAdvancements, ++ ServerboundSelectTrade, ++ ServerboundSetBeacon, ++ ServerboundSetCarriedItem, ++ ServerboundSetCommandBlock, ++ ServerboundSetCommandMinecart, ++ ServerboundSetCreativeModeSlot, ++ ServerboundSetJigsawBlock, ++ ServerboundSetStructureBlock, ++ ServerboundSignUpdate, ++ ServerboundSwing, ++ ServerboundTeleportToEntity, ++ ServerboundUseItemOn, ++ ServerboundUseItem, ++ ClientboundResetScore, ++ ClientboundTickingState, ++ ClientboundTickingStep, ++ ClientboundCustomPayload, ++ ClientboundDisconnect, ++ ClientboundKeepAlive, ++ ClientboundResourcePackPop, ++ ClientboundResourcePackPush, ++ ClientboundStoreCookie, ++ ClientboundTransfer, ++ ClientboundUpdateTags, ++ ServerboundClientInformation, ++ ServerboundCustomPayload, ++ ServerboundKeepAlive, ++ ServerboundPong, ++ ServerboundResourcePack ++} diff --git a/patches/server/0135-Bytebuf-API.patch b/patches/server/0135-Bytebuf-API.patch new file mode 100644 index 00000000..0c944e6d --- /dev/null +++ b/patches/server/0135-Bytebuf-API.patch @@ -0,0 +1,1144 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Lumine1909 <133463833+Lumine1909@users.noreply.github.com> +Date: Wed, 22 May 2024 10:12:22 +0800 +Subject: [PATCH] Bytebuf API + + +diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java +index 975062e67278614220eab0c301019a235c7953b7..cc23b30680f16ececc1843cfb132c7187c0a2fac 100644 +--- a/src/main/java/net/minecraft/server/players/PlayerList.java ++++ b/src/main/java/net/minecraft/server/players/PlayerList.java +@@ -469,7 +469,7 @@ public abstract class PlayerList { + if (!player.connection.isAcceptingMessages()) { + return; + } +- ++ ((org.leavesmc.leaves.bytebuf.SimpleBytebufManager) getServer().server.getBytebufManager()).injectPlayer(player.getBukkitEntity()); + org.leavesmc.leaves.protocol.core.LeavesProtocolManager.handlePlayerJoin(player); // Leaves - protocol + + // Leaves start - bot support +diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java +index 405a04f2711e26e22d7dd091745b5b5a01d724d9..5c2484dc3aff26bbd9cbe423b33b2a3c23a70333 100644 +--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java ++++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java +@@ -307,6 +307,7 @@ public final class CraftServer implements Server { + private final io.papermc.paper.potion.PaperPotionBrewer potionBrewer; // Paper - Custom Potion Mixes + private final org.leavesmc.leaves.entity.CraftBotManager botManager = new org.leavesmc.leaves.entity.CraftBotManager(); // Leaves + private final org.leavesmc.leaves.entity.CraftPhotographerManager photographerManager = new org.leavesmc.leaves.entity.CraftPhotographerManager(); // Leaves ++ private final org.leavesmc.leaves.bytebuf.SimpleBytebufManager bytebufManager = new org.leavesmc.leaves.bytebuf.SimpleBytebufManager(); // Leaves + + // Paper start - Folia region threading API + private final io.papermc.paper.threadedregions.scheduler.FallbackRegionScheduler regionizedScheduler = new io.papermc.paper.threadedregions.scheduler.FallbackRegionScheduler(); +@@ -3291,4 +3292,10 @@ public final class CraftServer implements Server { + return photographerManager; + } + // Leaves end - replay mod api ++ // Leaves start - Bytebuf API ++ @Override ++ public org.leavesmc.leaves.bytebuf.BytebufManager getBytebufManager() { ++ return bytebufManager; ++ } ++ // Leaves end - Bytebuf API + } +diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +index 25a5ce110c0515f5a0ee5f287a7f3dd029a8f29f..2c14b256f470c3fbbc55a0444f5f68ba1f22785c 100644 +--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java ++++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +@@ -3519,4 +3519,14 @@ public class CraftPlayer extends CraftHumanEntity implements Player { + public void setSendViewDistance(final int viewDistance) { + this.getHandle().setSendViewDistance(viewDistance); + } ++ // Leaves start - Bytebuf API ++ @Override ++ public void sendPacket(org.leavesmc.leaves.bytebuf.packet.Packet packet) { ++ ((org.leavesmc.leaves.bytebuf.SimpleBytebufManager) getServer().getBytebufManager()).applyPacketToPlayer(this, packet); ++ } ++ @Override ++ public void sendPacket(org.leavesmc.leaves.bytebuf.Bytebuf bytebuf, org.leavesmc.leaves.bytebuf.packet.PacketType type) { ++ ((org.leavesmc.leaves.bytebuf.SimpleBytebufManager) getServer().getBytebufManager()).applyPacketToPlayer(this, new org.leavesmc.leaves.bytebuf.packet.Packet(type, bytebuf)); ++ } ++ // Leaves end - Bytebuf API + } +diff --git a/src/main/java/org/leavesmc/leaves/bytebuf/SimpleBytebufManager.java b/src/main/java/org/leavesmc/leaves/bytebuf/SimpleBytebufManager.java +new file mode 100644 +index 0000000000000000000000000000000000000000..26179fcc836fcb8d1eda8ddb8a875cb9cdd421ab +--- /dev/null ++++ b/src/main/java/org/leavesmc/leaves/bytebuf/SimpleBytebufManager.java +@@ -0,0 +1,1008 @@ ++package org.leavesmc.leaves.bytebuf; ++ ++import io.netty.buffer.Unpooled; ++import io.netty.channel.ChannelDuplexHandler; ++import io.netty.channel.ChannelHandlerContext; ++import io.netty.channel.ChannelPromise; ++import net.minecraft.network.Connection; ++import net.minecraft.network.RegistryFriendlyByteBuf; ++import net.minecraft.network.protocol.BundleDelimiterPacket; ++import net.minecraft.network.protocol.BundlePacket; ++import net.minecraft.network.protocol.common.*; ++import net.minecraft.network.protocol.game.*; ++import net.minecraft.server.MinecraftServer; ++import org.bukkit.craftbukkit.entity.CraftPlayer; ++import org.bukkit.entity.Player; ++import org.bukkit.plugin.Plugin; ++import org.leavesmc.leaves.bytebuf.packet.Packet; ++import org.leavesmc.leaves.bytebuf.packet.PacketListener; ++import org.leavesmc.leaves.bytebuf.packet.PacketType; ++ ++import java.util.HashMap; ++import java.util.Map; ++ ++public class SimpleBytebufManager implements BytebufManager { ++ class PacketHandler extends ChannelDuplexHandler { ++ private final static String handlerName = "leaves-bytebuf-handler"; ++ private final Player player; ++ public PacketHandler(Player player) { ++ this.player = player; ++ } ++ @Override ++ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { ++ if (msg instanceof BundlePacket || msg instanceof BundleDelimiterPacket) { ++ super.channelRead(ctx, msg); ++ return; ++ } ++ try { ++ msg = callPacketInEvent(player, createBytebufPacket((net.minecraft.network.protocol.Packet) msg)); ++ } catch (Exception e) { ++ MinecraftServer.LOGGER.error("Error on PacketInEvent.", e); ++ } ++ if (msg != null) { ++ super.channelRead(ctx, msg); ++ } ++ } ++ ++ @Override ++ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { ++ if (msg instanceof BundlePacket || msg instanceof BundleDelimiterPacket) { ++ super.write(ctx, msg, promise); ++ return; ++ } ++ try { ++ msg = callPacketOutEvent(player, createBytebufPacket((net.minecraft.network.protocol.Packet) msg)); ++ } catch (Exception e) { ++ MinecraftServer.LOGGER.error("Error on PacketOutEvent.", e); ++ } ++ if (msg != null) { ++ super.write(ctx, msg, promise); ++ } ++ } ++ ++ } ++ ++ ++ private final Map listenerMap = new HashMap<>(); ++ @Override ++ public void registerListener(Plugin plugin, PacketListener listener) { ++ listenerMap.put(listener, plugin); ++ } ++ ++ @Override ++ public void unregisterListener(Plugin plugin, PacketListener listener) { ++ listenerMap.remove(listener); ++ } ++ @Override ++ public Bytebuf newBytebuf(int size) { ++ return new WrappedBytebuf(Unpooled.buffer(size)); ++ } ++ ++ @Override ++ public Bytebuf toBytebuf(byte[] bytes) { ++ return new WrappedBytebuf(Unpooled.wrappedBuffer(bytes)); ++ } ++ ++ ++ ++ public void injectPlayer(Player player) { ++ ((CraftPlayer) player).getHandle().connection.connection.channel.pipeline().addBefore( ++ "packet_handler", PacketHandler.handlerName, new PacketHandler(player) ++ ); ++ } ++ public net.minecraft.network.protocol.Packet callPacketInEvent(Player player, Packet packet) { ++ for (PacketListener listener : listenerMap.keySet()) { ++ if (listenerMap.get(listener).isEnabled()) { ++ packet = listener.onPacketIn(player, packet); ++ } else { ++ listenerMap.remove(listener); ++ } ++ } ++ return createNMSPacket(packet); ++ } ++ public net.minecraft.network.protocol.Packet callPacketOutEvent(Player player, Packet packet) { ++ for (PacketListener listener : listenerMap.keySet()) { ++ if (listenerMap.get(listener).isEnabled()) { ++ packet = listener.onPacketOut(player, packet); ++ } else { ++ listenerMap.remove(listener); ++ } ++ } ++ return createNMSPacket(packet); ++ } ++ public void applyPacketToPlayer(Player player, Packet packet) { ++ Connection sp = ((CraftPlayer) player).getHandle().connection.connection; ++ sp.channel.writeAndFlush(createNMSPacket(packet)); ++ } ++ private net.minecraft.network.protocol.Packet createNMSPacket(Packet packet) { ++ RegistryFriendlyByteBuf buf = new RegistryFriendlyByteBuf(((WrappedBytebuf) packet.bytebuf()).getFriendlyBytebuf(), MinecraftServer.getServer().registryAccess()); ++ PacketType type = packet.type(); ++ net.minecraft.network.protocol.Packet nmsPacket = null; ++ switch (type) { ++ case ClientboundAddEntity -> nmsPacket = ClientboundAddEntityPacket.STREAM_CODEC.decode(buf); ++ case ClientboundAddExperienceOrb -> nmsPacket = ClientboundAddExperienceOrbPacket.STREAM_CODEC.decode(buf); ++ case ClientboundAnimate -> nmsPacket = ClientboundAnimatePacket.STREAM_CODEC.decode(buf); ++ case ClientboundAwardStats -> nmsPacket = ClientboundAwardStatsPacket.STREAM_CODEC.decode(buf); ++ case ClientboundBlockChangedAck -> nmsPacket = ClientboundBlockChangedAckPacket.STREAM_CODEC.decode(buf); ++ case ClientboundBlockDestruction -> nmsPacket = ClientboundBlockDestructionPacket.STREAM_CODEC.decode(buf); ++ case ClientboundBlockEntityData -> nmsPacket = ClientboundBlockEntityDataPacket.STREAM_CODEC.decode(buf); ++ case ClientboundBlockEvent -> nmsPacket = ClientboundBlockEventPacket.STREAM_CODEC.decode(buf); ++ case ClientboundBlockUpdate -> nmsPacket = ClientboundBlockUpdatePacket.STREAM_CODEC.decode(buf); ++ case ClientboundBossEvent -> nmsPacket = ClientboundBossEventPacket.STREAM_CODEC.decode(buf); ++ case ClientboundChangeDifficulty -> nmsPacket = ClientboundChangeDifficultyPacket.STREAM_CODEC.decode(buf); ++ case ClientboundChunkBatchFinished -> nmsPacket = ClientboundChunkBatchFinishedPacket.STREAM_CODEC.decode(buf); ++ case ClientboundChunkBatchStart -> nmsPacket = ClientboundChunkBatchStartPacket.STREAM_CODEC.decode(buf); ++ case ClientboundChunksBiomes -> nmsPacket = ClientboundChunksBiomesPacket.STREAM_CODEC.decode(buf); ++ case ClientboundClearTitles -> nmsPacket = ClientboundClearTitlesPacket.STREAM_CODEC.decode(buf); ++ case ClientboundCommandSuggestions -> nmsPacket = ClientboundCommandSuggestionsPacket.STREAM_CODEC.decode(buf); ++ case ClientboundCommands -> nmsPacket = ClientboundCommandsPacket.STREAM_CODEC.decode(buf); ++ case ClientboundContainerClose -> nmsPacket = ClientboundContainerClosePacket.STREAM_CODEC.decode(buf); ++ case ClientboundContainerSetContent -> nmsPacket = ClientboundContainerSetContentPacket.STREAM_CODEC.decode(buf); ++ case ClientboundContainerSetData -> nmsPacket = ClientboundContainerSetDataPacket.STREAM_CODEC.decode(buf); ++ case ClientboundContainerSetSlot -> nmsPacket = ClientboundContainerSetSlotPacket.STREAM_CODEC.decode(buf); ++ case ClientboundCooldown -> nmsPacket = ClientboundCooldownPacket.STREAM_CODEC.decode(buf); ++ case ClientboundCustomChatCompletions -> nmsPacket = ClientboundCustomChatCompletionsPacket.STREAM_CODEC.decode(buf); ++ case ClientboundDamageEvent -> nmsPacket = ClientboundDamageEventPacket.STREAM_CODEC.decode(buf); ++ case ClientboundDebugSample -> nmsPacket = ClientboundDebugSamplePacket.STREAM_CODEC.decode(buf); ++ case ClientboundDeleteChat -> nmsPacket = ClientboundDeleteChatPacket.STREAM_CODEC.decode(buf); ++ case ClientboundDisguisedChat -> nmsPacket = ClientboundDisguisedChatPacket.STREAM_CODEC.decode(buf); ++ case ClientboundEntityEvent -> nmsPacket = ClientboundEntityEventPacket.STREAM_CODEC.decode(buf); ++ case ClientboundExplode -> nmsPacket = ClientboundExplodePacket.STREAM_CODEC.decode(buf); ++ case ClientboundForgetLevelChunk -> nmsPacket = ClientboundForgetLevelChunkPacket.STREAM_CODEC.decode(buf); ++ case ClientboundGameEvent -> nmsPacket = ClientboundGameEventPacket.STREAM_CODEC.decode(buf); ++ case ClientboundHorseScreenOpen -> nmsPacket = ClientboundHorseScreenOpenPacket.STREAM_CODEC.decode(buf); ++ case ClientboundHurtAnimation -> nmsPacket = ClientboundHurtAnimationPacket.STREAM_CODEC.decode(buf); ++ case ClientboundInitializeBorder -> nmsPacket = ClientboundInitializeBorderPacket.STREAM_CODEC.decode(buf); ++ case ClientboundLevelChunkWithLight -> nmsPacket = ClientboundLevelChunkWithLightPacket.STREAM_CODEC.decode(buf); ++ case ClientboundLevelEvent -> nmsPacket = ClientboundLevelEventPacket.STREAM_CODEC.decode(buf); ++ case ClientboundLevelParticles -> nmsPacket = ClientboundLevelParticlesPacket.STREAM_CODEC.decode(buf); ++ case ClientboundLightUpdate -> nmsPacket = ClientboundLightUpdatePacket.STREAM_CODEC.decode(buf); ++ case ClientboundLogin -> nmsPacket = ClientboundLoginPacket.STREAM_CODEC.decode(buf); ++ case ClientboundMapItemData -> nmsPacket = ClientboundMapItemDataPacket.STREAM_CODEC.decode(buf); ++ case ClientboundMerchantOffers -> nmsPacket = ClientboundMerchantOffersPacket.STREAM_CODEC.decode(buf); ++ case ClientboundMoveEntityPos -> nmsPacket = ClientboundMoveEntityPacket.Pos.STREAM_CODEC.decode(buf); ++ case ClientboundMoveEntityPosRot -> nmsPacket = ClientboundMoveEntityPacket.PosRot.STREAM_CODEC.decode(buf); ++ case ClientboundMoveEntityRot -> nmsPacket = ClientboundMoveEntityPacket.Rot.STREAM_CODEC.decode(buf); ++ case ClientboundMoveVehicle -> nmsPacket = ClientboundMoveVehiclePacket.STREAM_CODEC.decode(buf); ++ case ClientboundOpenBook -> nmsPacket = ClientboundOpenBookPacket.STREAM_CODEC.decode(buf); ++ case ClientboundOpenScreen -> nmsPacket = ClientboundOpenScreenPacket.STREAM_CODEC.decode(buf); ++ case ClientboundOpenSignEditor -> nmsPacket = ClientboundOpenSignEditorPacket.STREAM_CODEC.decode(buf); ++ case ClientboundPlaceGhostRecipe -> nmsPacket = ClientboundPlaceGhostRecipePacket.STREAM_CODEC.decode(buf); ++ case ClientboundPlayerAbilities -> nmsPacket = ClientboundPlayerAbilitiesPacket.STREAM_CODEC.decode(buf); ++ case ClientboundPlayerChat -> nmsPacket = ClientboundPlayerChatPacket.STREAM_CODEC.decode(buf); ++ case ClientboundPlayerCombatEnd -> nmsPacket = ClientboundPlayerCombatEndPacket.STREAM_CODEC.decode(buf); ++ case ClientboundPlayerCombatEnter -> nmsPacket = ClientboundPlayerCombatEnterPacket.STREAM_CODEC.decode(buf); ++ case ClientboundPlayerCombatKill -> nmsPacket = ClientboundPlayerCombatKillPacket.STREAM_CODEC.decode(buf); ++ case ClientboundPlayerInfoRemove -> nmsPacket = ClientboundPlayerInfoRemovePacket.STREAM_CODEC.decode(buf); ++ case ClientboundPlayerInfoUpdate -> nmsPacket = ClientboundPlayerInfoUpdatePacket.STREAM_CODEC.decode(buf); ++ case ClientboundPlayerLookAt -> nmsPacket = ClientboundPlayerLookAtPacket.STREAM_CODEC.decode(buf); ++ case ClientboundPlayerPosition -> nmsPacket = ClientboundPlayerPositionPacket.STREAM_CODEC.decode(buf); ++ case ClientboundRecipe -> nmsPacket = ClientboundRecipePacket.STREAM_CODEC.decode(buf); ++ case ClientboundRemoveEntities -> nmsPacket = ClientboundRemoveEntitiesPacket.STREAM_CODEC.decode(buf); ++ case ClientboundRemoveMobEffect -> nmsPacket = ClientboundRemoveMobEffectPacket.STREAM_CODEC.decode(buf); ++ case ClientboundRespawn -> nmsPacket = ClientboundRespawnPacket.STREAM_CODEC.decode(buf); ++ case ClientboundRotateHead -> nmsPacket = ClientboundRotateHeadPacket.STREAM_CODEC.decode(buf); ++ case ClientboundSectionBlocksUpdate -> nmsPacket = ClientboundSectionBlocksUpdatePacket.STREAM_CODEC.decode(buf); ++ case ClientboundSelectAdvancementsTab -> nmsPacket = ClientboundSelectAdvancementsTabPacket.STREAM_CODEC.decode(buf); ++ case ClientboundServerData -> nmsPacket = ClientboundServerDataPacket.STREAM_CODEC.decode(buf); ++ case ClientboundSetActionBarText -> nmsPacket = ClientboundSetActionBarTextPacket.STREAM_CODEC.decode(buf); ++ case ClientboundSetBorderCenter -> nmsPacket = ClientboundSetBorderCenterPacket.STREAM_CODEC.decode(buf); ++ case ClientboundSetBorderLerpSize -> nmsPacket = ClientboundSetBorderLerpSizePacket.STREAM_CODEC.decode(buf); ++ case ClientboundSetBorderSize -> nmsPacket = ClientboundSetBorderSizePacket.STREAM_CODEC.decode(buf); ++ case ClientboundSetBorderWarningDelay -> nmsPacket = ClientboundSetBorderWarningDelayPacket.STREAM_CODEC.decode(buf); ++ case ClientboundSetBorderWarningDistance -> nmsPacket = ClientboundSetBorderWarningDistancePacket.STREAM_CODEC.decode(buf); ++ case ClientboundSetCamera -> nmsPacket = ClientboundSetCameraPacket.STREAM_CODEC.decode(buf); ++ case ClientboundSetCarriedItem -> nmsPacket = ClientboundSetCarriedItemPacket.STREAM_CODEC.decode(buf); ++ case ClientboundSetChunkCacheCenter -> nmsPacket = ClientboundSetChunkCacheCenterPacket.STREAM_CODEC.decode(buf); ++ case ClientboundSetChunkCacheRadius -> nmsPacket = ClientboundSetChunkCacheRadiusPacket.STREAM_CODEC.decode(buf); ++ case ClientboundSetDefaultSpawnPosition -> nmsPacket = ClientboundSetDefaultSpawnPositionPacket.STREAM_CODEC.decode(buf); ++ case ClientboundSetDisplayObjective -> nmsPacket = ClientboundSetDisplayObjectivePacket.STREAM_CODEC.decode(buf); ++ case ClientboundSetEntityData -> nmsPacket = ClientboundSetEntityDataPacket.STREAM_CODEC.decode(buf); ++ case ClientboundSetEntityLink -> nmsPacket = ClientboundSetEntityLinkPacket.STREAM_CODEC.decode(buf); ++ case ClientboundSetEntityMotion -> nmsPacket = ClientboundSetEntityMotionPacket.STREAM_CODEC.decode(buf); ++ case ClientboundSetEquipment -> nmsPacket = ClientboundSetEquipmentPacket.STREAM_CODEC.decode(buf); ++ case ClientboundSetExperience -> nmsPacket = ClientboundSetExperiencePacket.STREAM_CODEC.decode(buf); ++ case ClientboundSetHealth -> nmsPacket = ClientboundSetHealthPacket.STREAM_CODEC.decode(buf); ++ case ClientboundSetObjective -> nmsPacket = ClientboundSetObjectivePacket.STREAM_CODEC.decode(buf); ++ case ClientboundSetPassengers -> nmsPacket = ClientboundSetPassengersPacket.STREAM_CODEC.decode(buf); ++ case ClientboundSetPlayerTeam -> nmsPacket = ClientboundSetPlayerTeamPacket.STREAM_CODEC.decode(buf); ++ case ClientboundSetScore -> nmsPacket = ClientboundSetScorePacket.STREAM_CODEC.decode(buf); ++ case ClientboundSetSimulationDistance -> nmsPacket = ClientboundSetSimulationDistancePacket.STREAM_CODEC.decode(buf); ++ case ClientboundSetSubtitleText -> nmsPacket = ClientboundSetSubtitleTextPacket.STREAM_CODEC.decode(buf); ++ case ClientboundSetTime -> nmsPacket = ClientboundSetTimePacket.STREAM_CODEC.decode(buf); ++ case ClientboundSetTitleText -> nmsPacket = ClientboundSetTitleTextPacket.STREAM_CODEC.decode(buf); ++ case ClientboundSetTitlesAnimation -> nmsPacket = ClientboundSetTitlesAnimationPacket.STREAM_CODEC.decode(buf); ++ case ClientboundSoundEntity -> nmsPacket = ClientboundSoundEntityPacket.STREAM_CODEC.decode(buf); ++ case ClientboundSound -> nmsPacket = ClientboundSoundPacket.STREAM_CODEC.decode(buf); ++ case ClientboundStartConfiguration -> nmsPacket = ClientboundStartConfigurationPacket.STREAM_CODEC.decode(buf); ++ case ClientboundStopSound -> nmsPacket = ClientboundStopSoundPacket.STREAM_CODEC.decode(buf); ++ case ClientboundSystemChat -> nmsPacket = ClientboundSystemChatPacket.STREAM_CODEC.decode(buf); ++ case ClientboundTabList -> nmsPacket = ClientboundTabListPacket.STREAM_CODEC.decode(buf); ++ case ClientboundTagQuery -> nmsPacket = ClientboundTagQueryPacket.STREAM_CODEC.decode(buf); ++ case ClientboundTakeItemEntity -> nmsPacket = ClientboundTakeItemEntityPacket.STREAM_CODEC.decode(buf); ++ case ClientboundTeleportEntity -> nmsPacket = ClientboundTeleportEntityPacket.STREAM_CODEC.decode(buf); ++ case ClientboundUpdateAdvancements -> nmsPacket = ClientboundUpdateAdvancementsPacket.STREAM_CODEC.decode(buf); ++ case ClientboundUpdateAttributes -> nmsPacket = ClientboundUpdateAttributesPacket.STREAM_CODEC.decode(buf); ++ case ClientboundUpdateMobEffect -> nmsPacket = ClientboundUpdateMobEffectPacket.STREAM_CODEC.decode(buf); ++ case ClientboundUpdateRecipes -> nmsPacket = ClientboundUpdateRecipesPacket.STREAM_CODEC.decode(buf); ++ case ClientboundProjectilePower -> nmsPacket = ClientboundProjectilePowerPacket.STREAM_CODEC.decode(buf); ++ case ServerboundAcceptTeleportation -> nmsPacket = ServerboundAcceptTeleportationPacket.STREAM_CODEC.decode(buf); ++ case ServerboundBlockEntityTagQuery -> nmsPacket = ServerboundBlockEntityTagQueryPacket.STREAM_CODEC.decode(buf); ++ case ServerboundChangeDifficulty -> nmsPacket = ServerboundChangeDifficultyPacket.STREAM_CODEC.decode(buf); ++ case ServerboundChatAck -> nmsPacket = ServerboundChatAckPacket.STREAM_CODEC.decode(buf); ++ case ServerboundChatCommand -> nmsPacket = ServerboundChatCommandPacket.STREAM_CODEC.decode(buf); ++ case ServerboundChatCommandSigned -> nmsPacket = ServerboundChatCommandSignedPacket.STREAM_CODEC.decode(buf); ++ case ServerboundChat -> nmsPacket = ServerboundChatPacket.STREAM_CODEC.decode(buf); ++ case ServerboundChatSessionUpdate -> nmsPacket = ServerboundChatSessionUpdatePacket.STREAM_CODEC.decode(buf); ++ case ServerboundChunkBatchReceived -> nmsPacket = ServerboundChunkBatchReceivedPacket.STREAM_CODEC.decode(buf); ++ case ServerboundClientCommand -> nmsPacket = ServerboundClientCommandPacket.STREAM_CODEC.decode(buf); ++ case ServerboundCommandSuggestion -> nmsPacket = ServerboundCommandSuggestionPacket.STREAM_CODEC.decode(buf); ++ case ServerboundConfigurationAcknowledged -> nmsPacket = ServerboundConfigurationAcknowledgedPacket.STREAM_CODEC.decode(buf); ++ case ServerboundContainerButtonClick -> nmsPacket = ServerboundContainerButtonClickPacket.STREAM_CODEC.decode(buf); ++ case ServerboundContainerClick -> nmsPacket = ServerboundContainerClickPacket.STREAM_CODEC.decode(buf); ++ case ServerboundContainerClose -> nmsPacket = ServerboundContainerClosePacket.STREAM_CODEC.decode(buf); ++ case ServerboundContainerSlotStateChanged -> nmsPacket = ServerboundContainerSlotStateChangedPacket.STREAM_CODEC.decode(buf); ++ case ServerboundDebugSampleSubscription -> nmsPacket = ServerboundDebugSampleSubscriptionPacket.STREAM_CODEC.decode(buf); ++ case ServerboundEditBook -> nmsPacket = ServerboundEditBookPacket.STREAM_CODEC.decode(buf); ++ case ServerboundEntityTagQuery -> nmsPacket = ServerboundEntityTagQueryPacket.STREAM_CODEC.decode(buf); ++ case ServerboundInteract -> nmsPacket = ServerboundInteractPacket.STREAM_CODEC.decode(buf); ++ case ServerboundJigsawGenerate -> nmsPacket = ServerboundJigsawGeneratePacket.STREAM_CODEC.decode(buf); ++ case ServerboundLockDifficulty -> nmsPacket = ServerboundLockDifficultyPacket.STREAM_CODEC.decode(buf); ++ case ServerboundMovePlayerPos -> nmsPacket = ServerboundMovePlayerPacket.Pos.STREAM_CODEC.decode(buf); ++ case ServerboundMovePlayerPosRot -> nmsPacket = ServerboundMovePlayerPacket.PosRot.STREAM_CODEC.decode(buf); ++ case ServerboundMovePlayerRot -> nmsPacket = ServerboundMovePlayerPacket.Rot.STREAM_CODEC.decode(buf); ++ case ServerboundMovePlayerStatusOnly -> nmsPacket = ServerboundMovePlayerPacket.StatusOnly.STREAM_CODEC.decode(buf); ++ case ServerboundMoveVehicle -> nmsPacket = ServerboundMoveVehiclePacket.STREAM_CODEC.decode(buf); ++ case ServerboundPaddleBoat -> nmsPacket = ServerboundPaddleBoatPacket.STREAM_CODEC.decode(buf); ++ case ServerboundPickItem -> nmsPacket = ServerboundPickItemPacket.STREAM_CODEC.decode(buf); ++ case ServerboundPlaceRecipe -> nmsPacket = ServerboundPlaceRecipePacket.STREAM_CODEC.decode(buf); ++ case ServerboundPlayerAbilities -> nmsPacket = ServerboundPlayerAbilitiesPacket.STREAM_CODEC.decode(buf); ++ case ServerboundPlayerAction -> nmsPacket = ServerboundPlayerActionPacket.STREAM_CODEC.decode(buf); ++ case ServerboundPlayerCommand -> nmsPacket = ServerboundPlayerCommandPacket.STREAM_CODEC.decode(buf); ++ case ServerboundPlayerInput -> nmsPacket = ServerboundPlayerInputPacket.STREAM_CODEC.decode(buf); ++ case ServerboundRecipeBookChangeSettings -> nmsPacket = ServerboundRecipeBookChangeSettingsPacket.STREAM_CODEC.decode(buf); ++ case ServerboundRecipeBookSeenRecipe -> nmsPacket = ServerboundRecipeBookSeenRecipePacket.STREAM_CODEC.decode(buf); ++ case ServerboundRenameItem -> nmsPacket = ServerboundRenameItemPacket.STREAM_CODEC.decode(buf); ++ case ServerboundSeenAdvancements -> nmsPacket = ServerboundSeenAdvancementsPacket.STREAM_CODEC.decode(buf); ++ case ServerboundSelectTrade -> nmsPacket = ServerboundSelectTradePacket.STREAM_CODEC.decode(buf); ++ case ServerboundSetBeacon -> nmsPacket = ServerboundSetBeaconPacket.STREAM_CODEC.decode(buf); ++ case ServerboundSetCarriedItem -> nmsPacket = ServerboundSetCarriedItemPacket.STREAM_CODEC.decode(buf); ++ case ServerboundSetCommandBlock -> nmsPacket = ServerboundSetCommandBlockPacket.STREAM_CODEC.decode(buf); ++ case ServerboundSetCommandMinecart -> nmsPacket = ServerboundSetCommandMinecartPacket.STREAM_CODEC.decode(buf); ++ case ServerboundSetCreativeModeSlot -> nmsPacket = ServerboundSetCreativeModeSlotPacket.STREAM_CODEC.decode(buf); ++ case ServerboundSetJigsawBlock -> nmsPacket = ServerboundSetJigsawBlockPacket.STREAM_CODEC.decode(buf); ++ case ServerboundSetStructureBlock -> nmsPacket = ServerboundSetStructureBlockPacket.STREAM_CODEC.decode(buf); ++ case ServerboundSignUpdate -> nmsPacket = ServerboundSignUpdatePacket.STREAM_CODEC.decode(buf); ++ case ServerboundSwing -> nmsPacket = ServerboundSwingPacket.STREAM_CODEC.decode(buf); ++ case ServerboundTeleportToEntity -> nmsPacket = ServerboundTeleportToEntityPacket.STREAM_CODEC.decode(buf); ++ case ServerboundUseItemOn -> nmsPacket = ServerboundUseItemOnPacket.STREAM_CODEC.decode(buf); ++ case ServerboundUseItem -> nmsPacket = ServerboundUseItemPacket.STREAM_CODEC.decode(buf); ++ case ClientboundResetScore -> nmsPacket = ClientboundResetScorePacket.STREAM_CODEC.decode(buf); ++ case ClientboundTickingState -> nmsPacket = ClientboundTickingStatePacket.STREAM_CODEC.decode(buf); ++ case ClientboundTickingStep -> nmsPacket = ClientboundTickingStepPacket.STREAM_CODEC.decode(buf); ++ //case ClientboundCustomPayload -> nmsPacket = ClientboundCustomPayloadPacket.STREAM_CODEC.decode(buf); ++ case ClientboundDisconnect -> nmsPacket = ClientboundDisconnectPacket.STREAM_CODEC.decode(buf); ++ case ClientboundKeepAlive -> nmsPacket = ClientboundKeepAlivePacket.STREAM_CODEC.decode(buf); ++ case ClientboundResourcePackPop -> nmsPacket = ClientboundResourcePackPopPacket.STREAM_CODEC.decode(buf); ++ case ClientboundResourcePackPush -> nmsPacket = ClientboundResourcePackPushPacket.STREAM_CODEC.decode(buf); ++ case ClientboundStoreCookie -> nmsPacket = ClientboundStoreCookiePacket.STREAM_CODEC.decode(buf); ++ case ClientboundTransfer -> nmsPacket = ClientboundTransferPacket.STREAM_CODEC.decode(buf); ++ case ClientboundUpdateTags -> nmsPacket = ClientboundUpdateTagsPacket.STREAM_CODEC.decode(buf); ++ case ServerboundClientInformation -> nmsPacket = ServerboundClientInformationPacket.STREAM_CODEC.decode(buf); ++ case ServerboundCustomPayload -> nmsPacket = ServerboundCustomPayloadPacket.STREAM_CODEC.decode(buf); ++ case ServerboundKeepAlive -> nmsPacket = ServerboundKeepAlivePacket.STREAM_CODEC.decode(buf); ++ case ServerboundPong -> nmsPacket = ServerboundPongPacket.STREAM_CODEC.decode(buf); ++ case ServerboundResourcePack -> nmsPacket = ServerboundResourcePackPacket.STREAM_CODEC.decode(buf); ++ default -> throw new UnsupportedOperationException("This feature is not completely finished yet, packet type " + type + " is not supported temporary."); ++ } ++ return nmsPacket; ++ } ++ private Packet createBytebufPacket(net.minecraft.network.protocol.Packet nmsPacket) { ++ PacketType type; ++ RegistryFriendlyByteBuf buf = new RegistryFriendlyByteBuf(Unpooled.buffer(8192), MinecraftServer.getServer().registryAccess()); ++ switch (nmsPacket.type().toString()) { ++ case "clientbound/minecraft:add_entity" -> { ++ type = PacketType.ClientboundAddEntity; ++ ClientboundAddEntityPacket.STREAM_CODEC.encode(buf, (ClientboundAddEntityPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:add_experience_orb" -> { ++ type = PacketType.ClientboundAddExperienceOrb; ++ ClientboundAddExperienceOrbPacket.STREAM_CODEC.encode(buf, (ClientboundAddExperienceOrbPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:animate" -> { ++ type = PacketType.ClientboundAnimate; ++ ClientboundAnimatePacket.STREAM_CODEC.encode(buf, (ClientboundAnimatePacket) nmsPacket); ++ } ++ case "clientbound/minecraft:award_stats" -> { ++ type = PacketType.ClientboundAwardStats; ++ ClientboundAwardStatsPacket.STREAM_CODEC.encode(buf, (ClientboundAwardStatsPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:block_changed_ack" -> { ++ type = PacketType.ClientboundBlockChangedAck; ++ ClientboundBlockChangedAckPacket.STREAM_CODEC.encode(buf, (ClientboundBlockChangedAckPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:block_destruction" -> { ++ type = PacketType.ClientboundBlockDestruction; ++ ClientboundBlockDestructionPacket.STREAM_CODEC.encode(buf, (ClientboundBlockDestructionPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:block_entity_data" -> { ++ type = PacketType.ClientboundBlockEntityData; ++ ClientboundBlockEntityDataPacket.STREAM_CODEC.encode(buf, (ClientboundBlockEntityDataPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:block_event" -> { ++ type = PacketType.ClientboundBlockEvent; ++ ClientboundBlockEventPacket.STREAM_CODEC.encode(buf, (ClientboundBlockEventPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:block_update" -> { ++ type = PacketType.ClientboundBlockUpdate; ++ ClientboundBlockUpdatePacket.STREAM_CODEC.encode(buf, (ClientboundBlockUpdatePacket) nmsPacket); ++ } ++ case "clientbound/minecraft:boss_event" -> { ++ type = PacketType.ClientboundBossEvent; ++ ClientboundBossEventPacket.STREAM_CODEC.encode(buf, (ClientboundBossEventPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:change_difficulty" -> { ++ type = PacketType.ClientboundChangeDifficulty; ++ ClientboundChangeDifficultyPacket.STREAM_CODEC.encode(buf, (ClientboundChangeDifficultyPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:chunk_batch_finished" -> { ++ type = PacketType.ClientboundChunkBatchFinished; ++ ClientboundChunkBatchFinishedPacket.STREAM_CODEC.encode(buf, (ClientboundChunkBatchFinishedPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:chunk_batch_start" -> { ++ type = PacketType.ClientboundChunkBatchStart; ++ ClientboundChunkBatchStartPacket.STREAM_CODEC.encode(buf, (ClientboundChunkBatchStartPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:chunks_biomes" -> { ++ type = PacketType.ClientboundChunksBiomes; ++ ClientboundChunksBiomesPacket.STREAM_CODEC.encode(buf, (ClientboundChunksBiomesPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:clear_titles" -> { ++ type = PacketType.ClientboundClearTitles; ++ ClientboundClearTitlesPacket.STREAM_CODEC.encode(buf, (ClientboundClearTitlesPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:command_suggestions" -> { ++ type = PacketType.ClientboundCommandSuggestions; ++ ClientboundCommandSuggestionsPacket.STREAM_CODEC.encode(buf, (ClientboundCommandSuggestionsPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:commands" -> { ++ type = PacketType.ClientboundCommands; ++ ClientboundCommandsPacket.STREAM_CODEC.encode(buf, (ClientboundCommandsPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:container_close" -> { ++ type = PacketType.ClientboundContainerClose; ++ ClientboundContainerClosePacket.STREAM_CODEC.encode(buf, (ClientboundContainerClosePacket) nmsPacket); ++ } ++ case "clientbound/minecraft:container_set_content" -> { ++ type = PacketType.ClientboundContainerSetContent; ++ ClientboundContainerSetContentPacket.STREAM_CODEC.encode(buf, (ClientboundContainerSetContentPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:container_set_data" -> { ++ type = PacketType.ClientboundContainerSetData; ++ ClientboundContainerSetDataPacket.STREAM_CODEC.encode(buf, (ClientboundContainerSetDataPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:container_set_slot" -> { ++ type = PacketType.ClientboundContainerSetSlot; ++ ClientboundContainerSetSlotPacket.STREAM_CODEC.encode(buf, (ClientboundContainerSetSlotPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:cooldown" -> { ++ type = PacketType.ClientboundCooldown; ++ ClientboundCooldownPacket.STREAM_CODEC.encode(buf, (ClientboundCooldownPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:custom_chat_completions" -> { ++ type = PacketType.ClientboundCustomChatCompletions; ++ ClientboundCustomChatCompletionsPacket.STREAM_CODEC.encode(buf, (ClientboundCustomChatCompletionsPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:damage_event" -> { ++ type = PacketType.ClientboundDamageEvent; ++ ClientboundDamageEventPacket.STREAM_CODEC.encode(buf, (ClientboundDamageEventPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:debug_sample" -> { ++ type = PacketType.ClientboundDebugSample; ++ ClientboundDebugSamplePacket.STREAM_CODEC.encode(buf, (ClientboundDebugSamplePacket) nmsPacket); ++ } ++ case "clientbound/minecraft:delete_chat" -> { ++ type = PacketType.ClientboundDeleteChat; ++ ClientboundDeleteChatPacket.STREAM_CODEC.encode(buf, (ClientboundDeleteChatPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:disguised_chat" -> { ++ type = PacketType.ClientboundDisguisedChat; ++ ClientboundDisguisedChatPacket.STREAM_CODEC.encode(buf, (ClientboundDisguisedChatPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:entity_event" -> { ++ type = PacketType.ClientboundEntityEvent; ++ ClientboundEntityEventPacket.STREAM_CODEC.encode(buf, (ClientboundEntityEventPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:explode" -> { ++ type = PacketType.ClientboundExplode; ++ ClientboundExplodePacket.STREAM_CODEC.encode(buf, (ClientboundExplodePacket) nmsPacket); ++ } ++ case "clientbound/minecraft:forget_level_chunk" -> { ++ type = PacketType.ClientboundForgetLevelChunk; ++ ClientboundForgetLevelChunkPacket.STREAM_CODEC.encode(buf, (ClientboundForgetLevelChunkPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:game_event" -> { ++ type = PacketType.ClientboundGameEvent; ++ ClientboundGameEventPacket.STREAM_CODEC.encode(buf, (ClientboundGameEventPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:horse_screen_open" -> { ++ type = PacketType.ClientboundHorseScreenOpen; ++ ClientboundHorseScreenOpenPacket.STREAM_CODEC.encode(buf, (ClientboundHorseScreenOpenPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:hurt_animation" -> { ++ type = PacketType.ClientboundHurtAnimation; ++ ClientboundHurtAnimationPacket.STREAM_CODEC.encode(buf, (ClientboundHurtAnimationPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:initialize_border" -> { ++ type = PacketType.ClientboundInitializeBorder; ++ ClientboundInitializeBorderPacket.STREAM_CODEC.encode(buf, (ClientboundInitializeBorderPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:level_chunk_with_light" -> { ++ type = PacketType.ClientboundLevelChunkWithLight; ++ ClientboundLevelChunkWithLightPacket.STREAM_CODEC.encode(buf, (ClientboundLevelChunkWithLightPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:level_event" -> { ++ type = PacketType.ClientboundLevelEvent; ++ ClientboundLevelEventPacket.STREAM_CODEC.encode(buf, (ClientboundLevelEventPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:level_particles" -> { ++ type = PacketType.ClientboundLevelParticles; ++ ClientboundLevelParticlesPacket.STREAM_CODEC.encode(buf, (ClientboundLevelParticlesPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:light_update" -> { ++ type = PacketType.ClientboundLightUpdate; ++ ClientboundLightUpdatePacket.STREAM_CODEC.encode(buf, (ClientboundLightUpdatePacket) nmsPacket); ++ } ++ case "clientbound/minecraft:login" -> { ++ type = PacketType.ClientboundLogin; ++ ClientboundLoginPacket.STREAM_CODEC.encode(buf, (ClientboundLoginPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:map_item_data" -> { ++ type = PacketType.ClientboundMapItemData; ++ ClientboundMapItemDataPacket.STREAM_CODEC.encode(buf, (ClientboundMapItemDataPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:merchant_offers" -> { ++ type = PacketType.ClientboundMerchantOffers; ++ ClientboundMerchantOffersPacket.STREAM_CODEC.encode(buf, (ClientboundMerchantOffersPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:move_entity_pos" -> { ++ type = PacketType.ClientboundMoveEntityPos; ++ ClientboundMoveEntityPacket.Pos.STREAM_CODEC.encode(buf, (ClientboundMoveEntityPacket.Pos) nmsPacket); ++ } ++ case "clientbound/minecraft:move_entity_pos_rot" -> { ++ type = PacketType.ClientboundMoveEntityPosRot; ++ ClientboundMoveEntityPacket.PosRot.STREAM_CODEC.encode(buf, (ClientboundMoveEntityPacket.PosRot) nmsPacket); ++ } ++ case "clientbound/minecraft:move_entity_rot" -> { ++ type = PacketType.ClientboundMoveEntityRot; ++ ClientboundMoveEntityPacket.Rot.STREAM_CODEC.encode(buf, (ClientboundMoveEntityPacket.Rot) nmsPacket); ++ } ++ case "clientbound/minecraft:move_vehicle" -> { ++ type = PacketType.ClientboundMoveVehicle; ++ ClientboundMoveVehiclePacket.STREAM_CODEC.encode(buf, (ClientboundMoveVehiclePacket) nmsPacket); ++ } ++ case "clientbound/minecraft:open_book" -> { ++ type = PacketType.ClientboundOpenBook; ++ ClientboundOpenBookPacket.STREAM_CODEC.encode(buf, (ClientboundOpenBookPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:open_screen" -> { ++ type = PacketType.ClientboundOpenScreen; ++ ClientboundOpenScreenPacket.STREAM_CODEC.encode(buf, (ClientboundOpenScreenPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:open_sign_editor" -> { ++ type = PacketType.ClientboundOpenSignEditor; ++ ClientboundOpenSignEditorPacket.STREAM_CODEC.encode(buf, (ClientboundOpenSignEditorPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:place_ghost_recipe" -> { ++ type = PacketType.ClientboundPlaceGhostRecipe; ++ ClientboundPlaceGhostRecipePacket.STREAM_CODEC.encode(buf, (ClientboundPlaceGhostRecipePacket) nmsPacket); ++ } ++ case "clientbound/minecraft:player_abilities" -> { ++ type = PacketType.ClientboundPlayerAbilities; ++ ClientboundPlayerAbilitiesPacket.STREAM_CODEC.encode(buf, (ClientboundPlayerAbilitiesPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:player_chat" -> { ++ type = PacketType.ClientboundPlayerChat; ++ ClientboundPlayerChatPacket.STREAM_CODEC.encode(buf, (ClientboundPlayerChatPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:player_combat_end" -> { ++ type = PacketType.ClientboundPlayerCombatEnd; ++ ClientboundPlayerCombatEndPacket.STREAM_CODEC.encode(buf, (ClientboundPlayerCombatEndPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:player_combat_enter" -> { ++ type = PacketType.ClientboundPlayerCombatEnter; ++ ClientboundPlayerCombatEnterPacket.STREAM_CODEC.encode(buf, (ClientboundPlayerCombatEnterPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:player_combat_kill" -> { ++ type = PacketType.ClientboundPlayerCombatKill; ++ ClientboundPlayerCombatKillPacket.STREAM_CODEC.encode(buf, (ClientboundPlayerCombatKillPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:player_info_remove" -> { ++ type = PacketType.ClientboundPlayerInfoRemove; ++ ClientboundPlayerInfoRemovePacket.STREAM_CODEC.encode(buf, (ClientboundPlayerInfoRemovePacket) nmsPacket); ++ } ++ case "clientbound/minecraft:player_info_update" -> { ++ type = PacketType.ClientboundPlayerInfoUpdate; ++ ClientboundPlayerInfoUpdatePacket.STREAM_CODEC.encode(buf, (ClientboundPlayerInfoUpdatePacket) nmsPacket); ++ } ++ case "clientbound/minecraft:player_look_at" -> { ++ type = PacketType.ClientboundPlayerLookAt; ++ ClientboundPlayerLookAtPacket.STREAM_CODEC.encode(buf, (ClientboundPlayerLookAtPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:player_position" -> { ++ type = PacketType.ClientboundPlayerPosition; ++ ClientboundPlayerPositionPacket.STREAM_CODEC.encode(buf, (ClientboundPlayerPositionPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:recipe" -> { ++ type = PacketType.ClientboundRecipe; ++ ClientboundRecipePacket.STREAM_CODEC.encode(buf, (ClientboundRecipePacket) nmsPacket); ++ } ++ case "clientbound/minecraft:remove_entities" -> { ++ type = PacketType.ClientboundRemoveEntities; ++ ClientboundRemoveEntitiesPacket.STREAM_CODEC.encode(buf, (ClientboundRemoveEntitiesPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:remove_mob_effect" -> { ++ type = PacketType.ClientboundRemoveMobEffect; ++ ClientboundRemoveMobEffectPacket.STREAM_CODEC.encode(buf, (ClientboundRemoveMobEffectPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:respawn" -> { ++ type = PacketType.ClientboundRespawn; ++ ClientboundRespawnPacket.STREAM_CODEC.encode(buf, (ClientboundRespawnPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:rotate_head" -> { ++ type = PacketType.ClientboundRotateHead; ++ ClientboundRotateHeadPacket.STREAM_CODEC.encode(buf, (ClientboundRotateHeadPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:section_blocks_update" -> { ++ type = PacketType.ClientboundSectionBlocksUpdate; ++ ClientboundSectionBlocksUpdatePacket.STREAM_CODEC.encode(buf, (ClientboundSectionBlocksUpdatePacket) nmsPacket); ++ } ++ case "clientbound/minecraft:select_advancements_tab" -> { ++ type = PacketType.ClientboundSelectAdvancementsTab; ++ ClientboundSelectAdvancementsTabPacket.STREAM_CODEC.encode(buf, (ClientboundSelectAdvancementsTabPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:server_data" -> { ++ type = PacketType.ClientboundServerData; ++ ClientboundServerDataPacket.STREAM_CODEC.encode(buf, (ClientboundServerDataPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:set_action_bar_text" -> { ++ type = PacketType.ClientboundSetActionBarText; ++ ClientboundSetActionBarTextPacket.STREAM_CODEC.encode(buf, (ClientboundSetActionBarTextPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:set_border_center" -> { ++ type = PacketType.ClientboundSetBorderCenter; ++ ClientboundSetBorderCenterPacket.STREAM_CODEC.encode(buf, (ClientboundSetBorderCenterPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:set_border_lerp_size" -> { ++ type = PacketType.ClientboundSetBorderLerpSize; ++ ClientboundSetBorderLerpSizePacket.STREAM_CODEC.encode(buf, (ClientboundSetBorderLerpSizePacket) nmsPacket); ++ } ++ case "clientbound/minecraft:set_border_size" -> { ++ type = PacketType.ClientboundSetBorderSize; ++ ClientboundSetBorderSizePacket.STREAM_CODEC.encode(buf, (ClientboundSetBorderSizePacket) nmsPacket); ++ } ++ case "clientbound/minecraft:set_border_warning_delay" -> { ++ type = PacketType.ClientboundSetBorderWarningDelay; ++ ClientboundSetBorderWarningDelayPacket.STREAM_CODEC.encode(buf, (ClientboundSetBorderWarningDelayPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:set_border_warning_distance" -> { ++ type = PacketType.ClientboundSetBorderWarningDistance; ++ ClientboundSetBorderWarningDistancePacket.STREAM_CODEC.encode(buf, (ClientboundSetBorderWarningDistancePacket) nmsPacket); ++ } ++ case "clientbound/minecraft:set_camera" -> { ++ type = PacketType.ClientboundSetCamera; ++ ClientboundSetCameraPacket.STREAM_CODEC.encode(buf, (ClientboundSetCameraPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:set_carried_item" -> { ++ type = PacketType.ClientboundSetCarriedItem; ++ ClientboundSetCarriedItemPacket.STREAM_CODEC.encode(buf, (ClientboundSetCarriedItemPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:set_chunk_cache_center" -> { ++ type = PacketType.ClientboundSetChunkCacheCenter; ++ ClientboundSetChunkCacheCenterPacket.STREAM_CODEC.encode(buf, (ClientboundSetChunkCacheCenterPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:set_chunk_cache_radius" -> { ++ type = PacketType.ClientboundSetChunkCacheRadius; ++ ClientboundSetChunkCacheRadiusPacket.STREAM_CODEC.encode(buf, (ClientboundSetChunkCacheRadiusPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:set_default_spawn_position" -> { ++ type = PacketType.ClientboundSetDefaultSpawnPosition; ++ ClientboundSetDefaultSpawnPositionPacket.STREAM_CODEC.encode(buf, (ClientboundSetDefaultSpawnPositionPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:set_display_objective" -> { ++ type = PacketType.ClientboundSetDisplayObjective; ++ ClientboundSetDisplayObjectivePacket.STREAM_CODEC.encode(buf, (ClientboundSetDisplayObjectivePacket) nmsPacket); ++ } ++ case "clientbound/minecraft:set_entity_data" -> { ++ type = PacketType.ClientboundSetEntityData; ++ ClientboundSetEntityDataPacket.STREAM_CODEC.encode(buf, (ClientboundSetEntityDataPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:set_entity_link" -> { ++ type = PacketType.ClientboundSetEntityLink; ++ ClientboundSetEntityLinkPacket.STREAM_CODEC.encode(buf, (ClientboundSetEntityLinkPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:set_entity_motion" -> { ++ type = PacketType.ClientboundSetEntityMotion; ++ ClientboundSetEntityMotionPacket.STREAM_CODEC.encode(buf, (ClientboundSetEntityMotionPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:set_equipment" -> { ++ type = PacketType.ClientboundSetEquipment; ++ ClientboundSetEquipmentPacket.STREAM_CODEC.encode(buf, (ClientboundSetEquipmentPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:set_experience" -> { ++ type = PacketType.ClientboundSetExperience; ++ ClientboundSetExperiencePacket.STREAM_CODEC.encode(buf, (ClientboundSetExperiencePacket) nmsPacket); ++ } ++ case "clientbound/minecraft:set_health" -> { ++ type = PacketType.ClientboundSetHealth; ++ ClientboundSetHealthPacket.STREAM_CODEC.encode(buf, (ClientboundSetHealthPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:set_objective" -> { ++ type = PacketType.ClientboundSetObjective; ++ ClientboundSetObjectivePacket.STREAM_CODEC.encode(buf, (ClientboundSetObjectivePacket) nmsPacket); ++ } ++ case "clientbound/minecraft:set_passengers" -> { ++ type = PacketType.ClientboundSetPassengers; ++ ClientboundSetPassengersPacket.STREAM_CODEC.encode(buf, (ClientboundSetPassengersPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:set_player_team" -> { ++ type = PacketType.ClientboundSetPlayerTeam; ++ ClientboundSetPlayerTeamPacket.STREAM_CODEC.encode(buf, (ClientboundSetPlayerTeamPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:set_score" -> { ++ type = PacketType.ClientboundSetScore; ++ ClientboundSetScorePacket.STREAM_CODEC.encode(buf, (ClientboundSetScorePacket) nmsPacket); ++ } ++ case "clientbound/minecraft:set_simulation_distance" -> { ++ type = PacketType.ClientboundSetSimulationDistance; ++ ClientboundSetSimulationDistancePacket.STREAM_CODEC.encode(buf, (ClientboundSetSimulationDistancePacket) nmsPacket); ++ } ++ case "clientbound/minecraft:set_subtitle_text" -> { ++ type = PacketType.ClientboundSetSubtitleText; ++ ClientboundSetSubtitleTextPacket.STREAM_CODEC.encode(buf, (ClientboundSetSubtitleTextPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:set_time" -> { ++ type = PacketType.ClientboundSetTime; ++ ClientboundSetTimePacket.STREAM_CODEC.encode(buf, (ClientboundSetTimePacket) nmsPacket); ++ } ++ case "clientbound/minecraft:set_title_text" -> { ++ type = PacketType.ClientboundSetTitleText; ++ ClientboundSetTitleTextPacket.STREAM_CODEC.encode(buf, (ClientboundSetTitleTextPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:set_titles_animation" -> { ++ type = PacketType.ClientboundSetTitlesAnimation; ++ ClientboundSetTitlesAnimationPacket.STREAM_CODEC.encode(buf, (ClientboundSetTitlesAnimationPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:sound_entity" -> { ++ type = PacketType.ClientboundSoundEntity; ++ ClientboundSoundEntityPacket.STREAM_CODEC.encode(buf, (ClientboundSoundEntityPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:sound" -> { ++ type = PacketType.ClientboundSound; ++ ClientboundSoundPacket.STREAM_CODEC.encode(buf, (ClientboundSoundPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:start_configuration" -> { ++ type = PacketType.ClientboundStartConfiguration; ++ ClientboundStartConfigurationPacket.STREAM_CODEC.encode(buf, (ClientboundStartConfigurationPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:stop_sound" -> { ++ type = PacketType.ClientboundStopSound; ++ ClientboundStopSoundPacket.STREAM_CODEC.encode(buf, (ClientboundStopSoundPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:system_chat" -> { ++ type = PacketType.ClientboundSystemChat; ++ ClientboundSystemChatPacket.STREAM_CODEC.encode(buf, (ClientboundSystemChatPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:tab_list" -> { ++ type = PacketType.ClientboundTabList; ++ ClientboundTabListPacket.STREAM_CODEC.encode(buf, (ClientboundTabListPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:tag_query" -> { ++ type = PacketType.ClientboundTagQuery; ++ ClientboundTagQueryPacket.STREAM_CODEC.encode(buf, (ClientboundTagQueryPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:take_item_entity" -> { ++ type = PacketType.ClientboundTakeItemEntity; ++ ClientboundTakeItemEntityPacket.STREAM_CODEC.encode(buf, (ClientboundTakeItemEntityPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:teleport_entity" -> { ++ type = PacketType.ClientboundTeleportEntity; ++ ClientboundTeleportEntityPacket.STREAM_CODEC.encode(buf, (ClientboundTeleportEntityPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:update_advancements" -> { ++ type = PacketType.ClientboundUpdateAdvancements; ++ ClientboundUpdateAdvancementsPacket.STREAM_CODEC.encode(buf, (ClientboundUpdateAdvancementsPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:update_attributes" -> { ++ type = PacketType.ClientboundUpdateAttributes; ++ ClientboundUpdateAttributesPacket.STREAM_CODEC.encode(buf, (ClientboundUpdateAttributesPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:update_mob_effect" -> { ++ type = PacketType.ClientboundUpdateMobEffect; ++ ClientboundUpdateMobEffectPacket.STREAM_CODEC.encode(buf, (ClientboundUpdateMobEffectPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:update_recipes" -> { ++ type = PacketType.ClientboundUpdateRecipes; ++ ClientboundUpdateRecipesPacket.STREAM_CODEC.encode(buf, (ClientboundUpdateRecipesPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:projectile_power" -> { ++ type = PacketType.ClientboundProjectilePower; ++ ClientboundProjectilePowerPacket.STREAM_CODEC.encode(buf, (ClientboundProjectilePowerPacket) nmsPacket); ++ } ++ case "serverbound/minecraft:accept_teleportation" -> { ++ type = PacketType.ServerboundAcceptTeleportation; ++ ServerboundAcceptTeleportationPacket.STREAM_CODEC.encode(buf, (ServerboundAcceptTeleportationPacket) nmsPacket); ++ } ++ case "serverbound/minecraft:block_entity_tag_query" -> { ++ type = PacketType.ServerboundBlockEntityTagQuery; ++ ServerboundBlockEntityTagQueryPacket.STREAM_CODEC.encode(buf, (ServerboundBlockEntityTagQueryPacket) nmsPacket); ++ } ++ case "serverbound/minecraft:change_difficulty" -> { ++ type = PacketType.ServerboundChangeDifficulty; ++ ServerboundChangeDifficultyPacket.STREAM_CODEC.encode(buf, (ServerboundChangeDifficultyPacket) nmsPacket); ++ } ++ case "serverbound/minecraft:chat_ack" -> { ++ type = PacketType.ServerboundChatAck; ++ ServerboundChatAckPacket.STREAM_CODEC.encode(buf, (ServerboundChatAckPacket) nmsPacket); ++ } ++ case "serverbound/minecraft:chat_command" -> { ++ type = PacketType.ServerboundChatCommand; ++ ServerboundChatCommandPacket.STREAM_CODEC.encode(buf, (ServerboundChatCommandPacket) nmsPacket); ++ } ++ case "serverbound/minecraft:chat_command_signed" -> { ++ type = PacketType.ServerboundChatCommandSigned; ++ ServerboundChatCommandSignedPacket.STREAM_CODEC.encode(buf, (ServerboundChatCommandSignedPacket) nmsPacket); ++ } ++ case "serverbound/minecraft:chat" -> { ++ type = PacketType.ServerboundChat; ++ ServerboundChatPacket.STREAM_CODEC.encode(buf, (ServerboundChatPacket) nmsPacket); ++ } ++ case "serverbound/minecraft:chat_session_update" -> { ++ type = PacketType.ServerboundChatSessionUpdate; ++ ServerboundChatSessionUpdatePacket.STREAM_CODEC.encode(buf, (ServerboundChatSessionUpdatePacket) nmsPacket); ++ } ++ case "serverbound/minecraft:chunk_batch_received" -> { ++ type = PacketType.ServerboundChunkBatchReceived; ++ ServerboundChunkBatchReceivedPacket.STREAM_CODEC.encode(buf, (ServerboundChunkBatchReceivedPacket) nmsPacket); ++ } ++ case "serverbound/minecraft:client_command" -> { ++ type = PacketType.ServerboundClientCommand; ++ ServerboundClientCommandPacket.STREAM_CODEC.encode(buf, (ServerboundClientCommandPacket) nmsPacket); ++ } ++ case "serverbound/minecraft:command_suggestion" -> { ++ type = PacketType.ServerboundCommandSuggestion; ++ ServerboundCommandSuggestionPacket.STREAM_CODEC.encode(buf, (ServerboundCommandSuggestionPacket) nmsPacket); ++ } ++ case "serverbound/minecraft:configuration_acknowledged" -> { ++ type = PacketType.ServerboundConfigurationAcknowledged; ++ ServerboundConfigurationAcknowledgedPacket.STREAM_CODEC.encode(buf, (ServerboundConfigurationAcknowledgedPacket) nmsPacket); ++ } ++ case "serverbound/minecraft:container_button_click" -> { ++ type = PacketType.ServerboundContainerButtonClick; ++ ServerboundContainerButtonClickPacket.STREAM_CODEC.encode(buf, (ServerboundContainerButtonClickPacket) nmsPacket); ++ } ++ case "serverbound/minecraft:container_click" -> { ++ type = PacketType.ServerboundContainerClick; ++ ServerboundContainerClickPacket.STREAM_CODEC.encode(buf, (ServerboundContainerClickPacket) nmsPacket); ++ } ++ case "serverbound/minecraft:container_close" -> { ++ type = PacketType.ServerboundContainerClose; ++ ServerboundContainerClosePacket.STREAM_CODEC.encode(buf, (ServerboundContainerClosePacket) nmsPacket); ++ } ++ case "serverbound/minecraft:container_slot_state_changed" -> { ++ type = PacketType.ServerboundContainerSlotStateChanged; ++ ServerboundContainerSlotStateChangedPacket.STREAM_CODEC.encode(buf, (ServerboundContainerSlotStateChangedPacket) nmsPacket); ++ } ++ case "serverbound/minecraft:debug_sample_subscription" -> { ++ type = PacketType.ServerboundDebugSampleSubscription; ++ ServerboundDebugSampleSubscriptionPacket.STREAM_CODEC.encode(buf, (ServerboundDebugSampleSubscriptionPacket) nmsPacket); ++ } ++ case "serverbound/minecraft:edit_book" -> { ++ type = PacketType.ServerboundEditBook; ++ ServerboundEditBookPacket.STREAM_CODEC.encode(buf, (ServerboundEditBookPacket) nmsPacket); ++ } ++ case "serverbound/minecraft:entity_tag_query" -> { ++ type = PacketType.ServerboundEntityTagQuery; ++ ServerboundEntityTagQueryPacket.STREAM_CODEC.encode(buf, (ServerboundEntityTagQueryPacket) nmsPacket); ++ } ++ case "serverbound/minecraft:interact" -> { ++ type = PacketType.ServerboundInteract; ++ ServerboundInteractPacket.STREAM_CODEC.encode(buf, (ServerboundInteractPacket) nmsPacket); ++ } ++ case "serverbound/minecraft:jigsaw_generate" -> { ++ type = PacketType.ServerboundJigsawGenerate; ++ ServerboundJigsawGeneratePacket.STREAM_CODEC.encode(buf, (ServerboundJigsawGeneratePacket) nmsPacket); ++ } ++ case "serverbound/minecraft:lock_difficulty" -> { ++ type = PacketType.ServerboundLockDifficulty; ++ ServerboundLockDifficultyPacket.STREAM_CODEC.encode(buf, (ServerboundLockDifficultyPacket) nmsPacket); ++ } ++ case "serverbound/minecraft:move_player_pos" -> { ++ type = PacketType.ServerboundMovePlayerPos; ++ ServerboundMovePlayerPacket.Pos.STREAM_CODEC.encode(buf, (ServerboundMovePlayerPacket.Pos) nmsPacket); ++ } ++ case "serverbound/minecraft:move_player_pos_rot" -> { ++ type = PacketType.ServerboundMovePlayerPosRot; ++ ServerboundMovePlayerPacket.PosRot.STREAM_CODEC.encode(buf, (ServerboundMovePlayerPacket.PosRot) nmsPacket); ++ } ++ case "serverbound/minecraft:move_player_rot" -> { ++ type = PacketType.ServerboundMovePlayerRot; ++ ServerboundMovePlayerPacket.Rot.STREAM_CODEC.encode(buf, (ServerboundMovePlayerPacket.Rot) nmsPacket); ++ } ++ case "serverbound/minecraft:move_player_status_only" -> { ++ type = PacketType.ServerboundMovePlayerStatusOnly; ++ ServerboundMovePlayerPacket.StatusOnly.STREAM_CODEC.encode(buf, (ServerboundMovePlayerPacket.StatusOnly) nmsPacket); ++ } ++ case "serverbound/minecraft:move_vehicle" -> { ++ type = PacketType.ServerboundMoveVehicle; ++ ServerboundMoveVehiclePacket.STREAM_CODEC.encode(buf, (ServerboundMoveVehiclePacket) nmsPacket); ++ } ++ case "serverbound/minecraft:paddle_boat" -> { ++ type = PacketType.ServerboundPaddleBoat; ++ ServerboundPaddleBoatPacket.STREAM_CODEC.encode(buf, (ServerboundPaddleBoatPacket) nmsPacket); ++ } ++ case "serverbound/minecraft:pick_item" -> { ++ type = PacketType.ServerboundPickItem; ++ ServerboundPickItemPacket.STREAM_CODEC.encode(buf, (ServerboundPickItemPacket) nmsPacket); ++ } ++ case "serverbound/minecraft:place_recipe" -> { ++ type = PacketType.ServerboundPlaceRecipe; ++ ServerboundPlaceRecipePacket.STREAM_CODEC.encode(buf, (ServerboundPlaceRecipePacket) nmsPacket); ++ } ++ case "serverbound/minecraft:player_abilities" -> { ++ type = PacketType.ServerboundPlayerAbilities; ++ ServerboundPlayerAbilitiesPacket.STREAM_CODEC.encode(buf, (ServerboundPlayerAbilitiesPacket) nmsPacket); ++ } ++ case "serverbound/minecraft:player_action" -> { ++ type = PacketType.ServerboundPlayerAction; ++ ServerboundPlayerActionPacket.STREAM_CODEC.encode(buf, (ServerboundPlayerActionPacket) nmsPacket); ++ } ++ case "serverbound/minecraft:player_command" -> { ++ type = PacketType.ServerboundPlayerCommand; ++ ServerboundPlayerCommandPacket.STREAM_CODEC.encode(buf, (ServerboundPlayerCommandPacket) nmsPacket); ++ } ++ case "serverbound/minecraft:player_input" -> { ++ type = PacketType.ServerboundPlayerInput; ++ ServerboundPlayerInputPacket.STREAM_CODEC.encode(buf, (ServerboundPlayerInputPacket) nmsPacket); ++ } ++ case "serverbound/minecraft:recipe_book_change_settings" -> { ++ type = PacketType.ServerboundRecipeBookChangeSettings; ++ ServerboundRecipeBookChangeSettingsPacket.STREAM_CODEC.encode(buf, (ServerboundRecipeBookChangeSettingsPacket) nmsPacket); ++ } ++ case "serverbound/minecraft:recipe_book_seen_recipe" -> { ++ type = PacketType.ServerboundRecipeBookSeenRecipe; ++ ServerboundRecipeBookSeenRecipePacket.STREAM_CODEC.encode(buf, (ServerboundRecipeBookSeenRecipePacket) nmsPacket); ++ } ++ case "serverbound/minecraft:rename_item" -> { ++ type = PacketType.ServerboundRenameItem; ++ ServerboundRenameItemPacket.STREAM_CODEC.encode(buf, (ServerboundRenameItemPacket) nmsPacket); ++ } ++ case "serverbound/minecraft:seen_advancements" -> { ++ type = PacketType.ServerboundSeenAdvancements; ++ ServerboundSeenAdvancementsPacket.STREAM_CODEC.encode(buf, (ServerboundSeenAdvancementsPacket) nmsPacket); ++ } ++ case "serverbound/minecraft:select_trade" -> { ++ type = PacketType.ServerboundSelectTrade; ++ ServerboundSelectTradePacket.STREAM_CODEC.encode(buf, (ServerboundSelectTradePacket) nmsPacket); ++ } ++ case "serverbound/minecraft:set_beacon" -> { ++ type = PacketType.ServerboundSetBeacon; ++ ServerboundSetBeaconPacket.STREAM_CODEC.encode(buf, (ServerboundSetBeaconPacket) nmsPacket); ++ } ++ case "serverbound/minecraft:set_carried_item" -> { ++ type = PacketType.ServerboundSetCarriedItem; ++ ServerboundSetCarriedItemPacket.STREAM_CODEC.encode(buf, (ServerboundSetCarriedItemPacket) nmsPacket); ++ } ++ case "serverbound/minecraft:set_command_block" -> { ++ type = PacketType.ServerboundSetCommandBlock; ++ ServerboundSetCommandBlockPacket.STREAM_CODEC.encode(buf, (ServerboundSetCommandBlockPacket) nmsPacket); ++ } ++ case "serverbound/minecraft:set_command_minecart" -> { ++ type = PacketType.ServerboundSetCommandMinecart; ++ ServerboundSetCommandMinecartPacket.STREAM_CODEC.encode(buf, (ServerboundSetCommandMinecartPacket) nmsPacket); ++ } ++ case "serverbound/minecraft:set_creative_mode_slot" -> { ++ type = PacketType.ServerboundSetCreativeModeSlot; ++ ServerboundSetCreativeModeSlotPacket.STREAM_CODEC.encode(buf, (ServerboundSetCreativeModeSlotPacket) nmsPacket); ++ } ++ case "serverbound/minecraft:set_jigsaw_block" -> { ++ type = PacketType.ServerboundSetJigsawBlock; ++ ServerboundSetJigsawBlockPacket.STREAM_CODEC.encode(buf, (ServerboundSetJigsawBlockPacket) nmsPacket); ++ } ++ case "serverbound/minecraft:set_structure_block" -> { ++ type = PacketType.ServerboundSetStructureBlock; ++ ServerboundSetStructureBlockPacket.STREAM_CODEC.encode(buf, (ServerboundSetStructureBlockPacket) nmsPacket); ++ } ++ case "serverbound/minecraft:sign_update" -> { ++ type = PacketType.ServerboundSignUpdate; ++ ServerboundSignUpdatePacket.STREAM_CODEC.encode(buf, (ServerboundSignUpdatePacket) nmsPacket); ++ } ++ case "serverbound/minecraft:swing" -> { ++ type = PacketType.ServerboundSwing; ++ ServerboundSwingPacket.STREAM_CODEC.encode(buf, (ServerboundSwingPacket) nmsPacket); ++ } ++ case "serverbound/minecraft:teleport_to_entity" -> { ++ type = PacketType.ServerboundTeleportToEntity; ++ ServerboundTeleportToEntityPacket.STREAM_CODEC.encode(buf, (ServerboundTeleportToEntityPacket) nmsPacket); ++ } ++ case "serverbound/minecraft:use_item_on" -> { ++ type = PacketType.ServerboundUseItemOn; ++ ServerboundUseItemOnPacket.STREAM_CODEC.encode(buf, (ServerboundUseItemOnPacket) nmsPacket); ++ } ++ case "serverbound/minecraft:use_item" -> { ++ type = PacketType.ServerboundUseItem; ++ ServerboundUseItemPacket.STREAM_CODEC.encode(buf, (ServerboundUseItemPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:reset_score" -> { ++ type = PacketType.ClientboundResetScore; ++ ClientboundResetScorePacket.STREAM_CODEC.encode(buf, (ClientboundResetScorePacket) nmsPacket); ++ } ++ case "clientbound/minecraft:ticking_state" -> { ++ type = PacketType.ClientboundTickingState; ++ ClientboundTickingStatePacket.STREAM_CODEC.encode(buf, (ClientboundTickingStatePacket) nmsPacket); ++ } ++ case "clientbound/minecraft:ticking_step" -> { ++ type = PacketType.ClientboundTickingStep; ++ ClientboundTickingStepPacket.STREAM_CODEC.encode(buf, (ClientboundTickingStepPacket) nmsPacket); ++ } ++ /* ++ case "clientbound/minecraft:custom_payload" -> { ++ type = PacketType.ClientboundCustomPayload; ++ ClientboundCustomPayloadPacket.STREAM_CODEC.encode(buf, (ClientboundCustomPayloadPacket) nmsPacket); ++ } ++ ++ */ ++ case "clientbound/minecraft:disconnect" -> { ++ type = PacketType.ClientboundDisconnect; ++ ClientboundDisconnectPacket.STREAM_CODEC.encode(buf, (ClientboundDisconnectPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:keep_alive" -> { ++ type = PacketType.ClientboundKeepAlive; ++ ClientboundKeepAlivePacket.STREAM_CODEC.encode(buf, (ClientboundKeepAlivePacket) nmsPacket); ++ } ++ case "clientbound/minecraft:resource_pack_pop" -> { ++ type = PacketType.ClientboundResourcePackPop; ++ ClientboundResourcePackPopPacket.STREAM_CODEC.encode(buf, (ClientboundResourcePackPopPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:resource_pack_push" -> { ++ type = PacketType.ClientboundResourcePackPush; ++ ClientboundResourcePackPushPacket.STREAM_CODEC.encode(buf, (ClientboundResourcePackPushPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:store_cookie" -> { ++ type = PacketType.ClientboundStoreCookie; ++ ClientboundStoreCookiePacket.STREAM_CODEC.encode(buf, (ClientboundStoreCookiePacket) nmsPacket); ++ } ++ case "clientbound/minecraft:transfer" -> { ++ type = PacketType.ClientboundTransfer; ++ ClientboundTransferPacket.STREAM_CODEC.encode(buf, (ClientboundTransferPacket) nmsPacket); ++ } ++ case "clientbound/minecraft:update_tags" -> { ++ type = PacketType.ClientboundUpdateTags; ++ ClientboundUpdateTagsPacket.STREAM_CODEC.encode(buf, (ClientboundUpdateTagsPacket) nmsPacket); ++ } ++ case "serverbound/minecraft:client_information" -> { ++ type = PacketType.ServerboundClientInformation; ++ ServerboundClientInformationPacket.STREAM_CODEC.encode(buf, (ServerboundClientInformationPacket) nmsPacket); ++ } ++ case "serverbound/minecraft:custom_payload" -> { ++ type = PacketType.ServerboundCustomPayload; ++ ServerboundCustomPayloadPacket.STREAM_CODEC.encode(buf, (ServerboundCustomPayloadPacket) nmsPacket); ++ } ++ case "serverbound/minecraft:keep_alive" -> { ++ type = PacketType.ServerboundKeepAlive; ++ ServerboundKeepAlivePacket.STREAM_CODEC.encode(buf, (ServerboundKeepAlivePacket) nmsPacket); ++ } ++ case "serverbound/minecraft:pong" -> { ++ type = PacketType.ServerboundPong; ++ ServerboundPongPacket.STREAM_CODEC.encode(buf, (ServerboundPongPacket) nmsPacket); ++ } ++ case "serverbound/minecraft:resource_pack" -> { ++ type = PacketType.ServerboundResourcePack; ++ ServerboundResourcePackPacket.STREAM_CODEC.encode(buf, (ServerboundResourcePackPacket) nmsPacket); ++ } ++ default -> ++ throw new UnsupportedOperationException("This feature is not completely finished yet, packet " + nmsPacket + " is not supported temporary."); ++ } ++ return new Packet(type, Bytebuf.of(buf.array())); ++ } ++} +diff --git a/src/main/java/org/leavesmc/leaves/bytebuf/WrappedBytebuf.java b/src/main/java/org/leavesmc/leaves/bytebuf/WrappedBytebuf.java +new file mode 100644 +index 0000000000000000000000000000000000000000..b53641dffbe6302dfb0e7e666b0e62a3cf94a70c +--- /dev/null ++++ b/src/main/java/org/leavesmc/leaves/bytebuf/WrappedBytebuf.java +@@ -0,0 +1,63 @@ ++package org.leavesmc.leaves.bytebuf; ++ ++import io.netty.buffer.ByteBuf; ++import net.minecraft.network.FriendlyByteBuf; ++ ++public class WrappedBytebuf implements Bytebuf { ++ private final FriendlyByteBuf buf; ++ public WrappedBytebuf(ByteBuf buf) { ++ this.buf = new FriendlyByteBuf(buf); ++ } ++ public FriendlyByteBuf getFriendlyBytebuf() { ++ return buf; ++ } ++ ++ @Override ++ public byte[] toArray() { ++ return buf.array(); ++ } ++ ++ @Override ++ public Bytebuf writeByte(int i) { ++ buf.writeByte(i); ++ return this; ++ } ++ ++ @Override ++ public byte readByte() { ++ return buf.readByte(); ++ } ++ ++ @Override ++ public Bytebuf writeShort(int i) { ++ buf.writeShort(i); ++ return this; ++ } ++ ++ @Override ++ public short readShort() { ++ return buf.readShort(); ++ } ++ ++ @Override ++ public Bytebuf writeInt(int i) { ++ buf.writeShort(i); ++ return this; ++ } ++ ++ @Override ++ public int readInt() { ++ return buf.readInt(); ++ } ++ ++ @Override ++ public Bytebuf writeLong(long i) { ++ buf.writeLong(i); ++ return this; ++ } ++ ++ @Override ++ public long readLong() { ++ return buf.readLong(); ++ } ++} From 04f709ebf3611d13669e6635a3d61df5806e70fd Mon Sep 17 00:00:00 2001 From: Lumine1909 <133463833+Lumine1909@users.noreply.github.com> Date: Tue, 21 May 2024 23:49:24 -0400 Subject: [PATCH 2/9] remove unapplied --- patches/unapplied/api/0011-Bytebuf-API.patch | 224 ------------- .../unapplied/server/0137-Bytebuf-API.patch | 314 ------------------ 2 files changed, 538 deletions(-) delete mode 100644 patches/unapplied/api/0011-Bytebuf-API.patch delete mode 100644 patches/unapplied/server/0137-Bytebuf-API.patch diff --git a/patches/unapplied/api/0011-Bytebuf-API.patch b/patches/unapplied/api/0011-Bytebuf-API.patch deleted file mode 100644 index 63e8bf4a..00000000 --- a/patches/unapplied/api/0011-Bytebuf-API.patch +++ /dev/null @@ -1,224 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Lumine1909 <3556577839@qq.com> -Date: Fri, 12 Apr 2024 20:12:33 -0400 -Subject: [PATCH] Bytebuf API - - -diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java -index b068de949e21525d79223e607fafd43b030a8294..1853a5c230de0e3bc66e0617efe01e6dd15ef553 100644 ---- a/src/main/java/org/bukkit/Bukkit.java -+++ b/src/main/java/org/bukkit/Bukkit.java -@@ -2923,6 +2923,14 @@ public final class Bukkit { - return server.getPhotographerManager(); - } - // Leaves end - Photographer API -+ // Leaves start - Bytebuf API -+ public static @NotNull org.leavesmc.leaves.packet.bytebuf.Bytebuf newByteBuf() { -+ return server.newByteBuf(); -+ } -+ public static @NotNull org.leavesmc.leaves.packet.bytebuf.Bytebuf newByteBuf(int initalCapability) { -+ return server.newByteBuf(initalCapability); -+ } -+ // Leaves end - Bytebuf API - - @NotNull - public static Server.Spigot spigot() { -diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java -index 23ac9b72d2a59b23223ad9335ebed63c40ac117f..56b7e84f075af5d10cb23635f52fc0fedb1f7c6f 100644 ---- a/src/main/java/org/bukkit/Server.java -+++ b/src/main/java/org/bukkit/Server.java -@@ -2564,4 +2564,9 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi - // Leaves start - Photographer API - @NotNull PhotographerManager getPhotographerManager(); - // Leaves end - Photographer API -+ // Leaves start - Bytebuf API -+ @NotNull org.leavesmc.leaves.packet.bytebuf.Bytebuf newByteBuf(); -+ @NotNull org.leavesmc.leaves.packet.bytebuf.Bytebuf newByteBuf(int initalCapability); -+ -+ // Leaves end - Bytebuf API - } -diff --git a/src/main/java/org/bukkit/entity/Player.java b/src/main/java/org/bukkit/entity/Player.java -index 6c327a07bf8a6aa11a2d7dad12b2830acc539484..cfd3acc5e4adcd30fd70ca2c5601bcca1357c821 100644 ---- a/src/main/java/org/bukkit/entity/Player.java -+++ b/src/main/java/org/bukkit/entity/Player.java -@@ -3760,6 +3760,10 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM - */ - void resetIdleDuration(); - // Paper end -+ // Leaves start - Bytebuf API -+ void sendPacket(org.leavesmc.leaves.packet.Packet packet); -+ void sendPacket(org.leavesmc.leaves.packet.bytebuf.Bytebuf buf, org.leavesmc.leaves.packet.PacketType packetType); -+ // Leaves end - Bytebuf API - - // Paper start - Add chunk view API - /** -diff --git a/src/main/java/org/leavesmc/leaves/packet/Packet.java b/src/main/java/org/leavesmc/leaves/packet/Packet.java -new file mode 100644 -index 0000000000000000000000000000000000000000..0ea5069b994eb3da2952f696c1fd1bc0e81e281a ---- /dev/null -+++ b/src/main/java/org/leavesmc/leaves/packet/Packet.java -@@ -0,0 +1,8 @@ -+package org.leavesmc.leaves.packet; -+ -+import org.leavesmc.leaves.packet.bytebuf.Bytebuf; -+ -+public interface Packet { -+ PacketType getType(); -+ Bytebuf getBytebuf(); -+} -diff --git a/src/main/java/org/leavesmc/leaves/packet/PacketType.java b/src/main/java/org/leavesmc/leaves/packet/PacketType.java -new file mode 100644 -index 0000000000000000000000000000000000000000..3cf5792ddb7aa52580c4d91c2ddef593a43212af ---- /dev/null -+++ b/src/main/java/org/leavesmc/leaves/packet/PacketType.java -@@ -0,0 +1,115 @@ -+package org.leavesmc.leaves.packet; -+ -+/*** -+ * TODO: API comment -+ */ -+public enum PacketType { -+ ClientboundAddEntity, -+ ClientboundAddExperienceOrb, -+ ClientboundAnimate, -+ ClientboundAwardStats, -+ ClientboundBlockChangedAck, -+ ClientboundBlockDestruction, -+ ClientboundBlockEntityData, -+ ClientboundBlockEvent, -+ ClientboundBlockUpdate, -+ ClientboundBossEvent, -+ // ClientboundBundle, Not a regular packet, see https://wiki.vg/Protocol#Bundle_Delimiter -+ ClientboundChangeDifficulty, -+ ClientboundChunkBatchFinished, -+ ClientboundChunkBatchStart, -+ ClientboundChunksBiomes, -+ ClientboundClearTitles, -+ ClientboundCommands, -+ ClientboundCommandSuggestions, -+ ClientboundContainerClose, -+ ClientboundContainerSetContent, -+ ClientboundContainerSetData, -+ ClientboundContainerSetSlot, -+ ClientboundCooldown, -+ ClientboundCustomChatCompletions, -+ ClientboundDamageEvent, -+ ClientboundDeleteChat, -+ ClientboundDisguisedChat, -+ ClientboundEntityEvent, -+ ClientboundExplode, -+ ClientboundForgetLevelChunk, -+ ClientboundGameEvent, -+ ClientboundHorseScreenOpen, -+ ClientboundHurtAnimation, -+ ClientboundInitializeBorder, -+ ClientboundLevelChunkWithLight, -+ ClientboundLevelEvent, -+ ClientboundLevelParticles, -+ ClientboundLightUpdate, -+ ClientboundLightUpdatePack, -+ ClientboundLogin, -+ ClientboundMapItemData, -+ ClientboundMerchantOffers, -+ // ClientboundMoveEntity, Abstract class -+ ClientboundMoveVehicle, -+ ClientboundOpenBook, -+ ClientboundOpenScreen, -+ ClientboundOpenSignEditor, -+ ClientboundPlaceGhostRecipe, -+ ClientboundPlayerAbilities, -+ ClientboundPlayerChat, -+ ClientboundPlayerCombatEnd, -+ ClientboundPlayerCombatEnter, -+ ClientboundPlayerCombatKill, -+ ClientboundPlayerInfoRemove, -+ ClientboundPlayerInfoUpdate, -+ ClientboundPlayerLookAt, -+ ClientboundPlayerPosition, -+ ClientboundRecipe, -+ ClientboundRemoveEntities, -+ ClientboundRemoveMobEffect, -+ ClientboundResetScore, -+ ClientboundRespawn, -+ ClientboundRotateHead, -+ ClientboundSectionBlocksUpdate, -+ ClientboundSelectAdvancementsTab, -+ ClientboundServerData, -+ ClientboundSetActionBarText, -+ ClientboundSetBorderCenter, -+ ClientboundSetBorderLerpSize, -+ ClientboundSetBorderSize, -+ ClientboundSetBorderWarningDelay, -+ ClientboundSetBorderWarningDistance, -+ ClientboundSetCamera, -+ ClientboundSetCarriedItem, -+ ClientboundSetChunkCacheCenter, -+ ClientboundSetChunkCacheRadius, -+ ClientboundSetDefaultSpawnPosition, -+ ClientboundSetDisplayObjective, -+ ClientboundSetEntityData, -+ ClientboundSetEntityLink, -+ ClientboundSetEntityMotion, -+ ClientboundSetEquipment, -+ ClientboundSetExperience, -+ ClientboundSetHealth, -+ ClientboundSetObjective, -+ ClientboundSetPassengers, -+ ClientboundSetPlayerTeam, -+ ClientboundSetScore, -+ ClientboundSetSimulationDistance, -+ ClientboundSetSubtitleText, -+ ClientboundSetTime, -+ ClientboundSetTitlesAnimation, -+ ClientboundSetTitleText, -+ ClientboundSoundEntity, -+ ClientboundSound, -+ ClientboundStartConfiguration, -+ ClientboundStopSound, -+ ClientboundSystemChat, -+ ClientboundTabList, -+ ClientboundTagQuery, -+ ClientboundTakeItemEntity, -+ ClientboundTeleportEntity, -+ ClientboundTickingState, -+ ClientboundTickingStep, -+ ClientboundUpdateAdvancements, -+ ClientboundUpdateAttributes, -+ ClientboundUpdateMobEffect, -+ ClientboundUpdateRecipes -+} -diff --git a/src/main/java/org/leavesmc/leaves/packet/bytebuf/Bytebuf.java b/src/main/java/org/leavesmc/leaves/packet/bytebuf/Bytebuf.java -new file mode 100644 -index 0000000000000000000000000000000000000000..78a49c0d86742bc98f6b1434cba00a735982fd7a ---- /dev/null -+++ b/src/main/java/org/leavesmc/leaves/packet/bytebuf/Bytebuf.java -@@ -0,0 +1,29 @@ -+package org.leavesmc.leaves.packet.bytebuf; -+ -+import org.bukkit.inventory.ItemStack; -+import org.leavesmc.leaves.packet.Packet; -+import org.leavesmc.leaves.packet.PacketType; -+ -+import java.util.UUID; -+ -+public interface Bytebuf { -+ Packet toPacket(PacketType type); -+ Bytebuf writeByte(int i); -+ Bytebuf writeBoolean(boolean flag); -+ Bytebuf writeFloat(float f); -+ Bytebuf writeInt(int i); -+ Bytebuf writeShort(int i); -+ Bytebuf writeLong(long i); -+ Bytebuf writeVarInt(int value); -+ Bytebuf writeUUID(UUID uuid); -+ Bytebuf writeVarLong(long value); -+ -+ /* -+ In order to bypass NMS in the API, use deserialization of Object here. -+ In the future, it may be adjusted to use API encapsulated content (workload++). -+ */ -+ Bytebuf writeStringNbt(String nbt); -+ Bytebuf writeStringComponent(String component); -+ Bytebuf writeItem(ItemStack itemStack); -+ -+} diff --git a/patches/unapplied/server/0137-Bytebuf-API.patch b/patches/unapplied/server/0137-Bytebuf-API.patch deleted file mode 100644 index da338c75..00000000 --- a/patches/unapplied/server/0137-Bytebuf-API.patch +++ /dev/null @@ -1,314 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Lumine1909 <3556577839@qq.com> -Date: Fri, 12 Apr 2024 20:13:20 -0400 -Subject: [PATCH] Bytebuf API - - -diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java -index 70b4f5dc96e285184bd3e676397c6bddd193db37..5e2b61e191f29c59d614c0f3f5bcc17bbd9d1700 100644 ---- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java -+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java -@@ -3288,4 +3288,15 @@ public final class CraftServer implements Server { - return photographerManager; - } - // Leaves end - replay mod api -+ // Leaves start - Bytebuf API -+ @Override -+ public @Nonnull org.leavesmc.leaves.packet.bytebuf.Bytebuf newByteBuf() { -+ return new org.leavesmc.leaves.packet.bytebuf.WrappedBytebuf(); -+ } -+ -+ @Override -+ public @Nonnull org.leavesmc.leaves.packet.bytebuf.Bytebuf newByteBuf(int initalCapability) { -+ return new org.leavesmc.leaves.packet.bytebuf.WrappedBytebuf(initalCapability); -+ } -+ // Leaves end - Bytebuf API - } -diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java -index be198fa712ced7b61de16bdbc1f13acd2306cb22..d53e88a4261ddddc744c3c48b61564749f3ac28f 100644 ---- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java -+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java -@@ -3390,6 +3390,17 @@ public class CraftPlayer extends CraftHumanEntity implements Player { - public void resetIdleDuration() { - this.getHandle().resetLastActionTime(); - } -+ // Leaves start - Bytebuf API -+ @Override -+ public void sendPacket(org.leavesmc.leaves.packet.Packet packet) { -+ this.getHandle().connection.send(((org.leavesmc.leaves.packet.WrappedPacket) packet).getNmsPacket()); -+ } -+ @Override -+ public void sendPacket(org.leavesmc.leaves.packet.bytebuf.Bytebuf buf, org.leavesmc.leaves.packet.PacketType packetType) { -+ org.leavesmc.leaves.packet.Packet packet = buf.toPacket(packetType); -+ this.getHandle().connection.send(((org.leavesmc.leaves.packet.WrappedPacket) packet).getNmsPacket()); -+ } -+ // Leaves end - Bytebuf API - // Paper end - - // Paper start - Add chunk view API -diff --git a/src/main/java/org/leavesmc/leaves/packet/WrappedPacket.java b/src/main/java/org/leavesmc/leaves/packet/WrappedPacket.java -new file mode 100644 -index 0000000000000000000000000000000000000000..dc0dde18d3ae300657d92e20ae3e17136b8b72f4 ---- /dev/null -+++ b/src/main/java/org/leavesmc/leaves/packet/WrappedPacket.java -@@ -0,0 +1,140 @@ -+package org.leavesmc.leaves.packet; -+ -+import net.minecraft.network.protocol.game.*; -+import org.leavesmc.leaves.packet.bytebuf.Bytebuf; -+import org.leavesmc.leaves.packet.bytebuf.WrappedBytebuf; -+ -+public class WrappedPacket implements Packet { -+ private final PacketType type; -+ private final Bytebuf wrappedBytebuf; -+ net.minecraft.network.protocol.Packet nmsPacket; -+ public WrappedPacket(PacketType type, WrappedBytebuf buf) { -+ this.type = type; -+ this.wrappedBytebuf = buf; -+ try { -+ switch (type) { -+ case ClientboundAddEntity -> nmsPacket = new ClientboundAddEntityPacket(buf.getFriendlyByteBuf()); -+ case ClientboundAddExperienceOrb -> nmsPacket = new ClientboundAddExperienceOrbPacket(buf.getFriendlyByteBuf()); -+ case ClientboundAnimate -> nmsPacket = new ClientboundAnimatePacket(buf.getFriendlyByteBuf()); -+ case ClientboundAwardStats -> nmsPacket = new ClientboundAwardStatsPacket(buf.getFriendlyByteBuf()); -+ case ClientboundBlockChangedAck -> nmsPacket = new ClientboundBlockChangedAckPacket(buf.getFriendlyByteBuf()); -+ case ClientboundBlockDestruction -> nmsPacket = new ClientboundBlockDestructionPacket(buf.getFriendlyByteBuf()); -+ case ClientboundBlockEntityData -> nmsPacket = new ClientboundBlockEntityDataPacket(buf.getFriendlyByteBuf()); -+ case ClientboundBlockEvent -> nmsPacket = new ClientboundBlockEventPacket(buf.getFriendlyByteBuf()); -+ case ClientboundBlockUpdate -> nmsPacket = new ClientboundBlockUpdatePacket(buf.getFriendlyByteBuf()); -+ case ClientboundBossEvent -> nmsPacket = new ClientboundBossEventPacket(buf.getFriendlyByteBuf()); -+ case ClientboundChangeDifficulty -> nmsPacket = new ClientboundChangeDifficultyPacket(buf.getFriendlyByteBuf()); -+ case ClientboundChunkBatchFinished -> nmsPacket = new ClientboundChunkBatchFinishedPacket(buf.getFriendlyByteBuf()); -+ case ClientboundChunkBatchStart -> nmsPacket = new ClientboundChunkBatchStartPacket(buf.getFriendlyByteBuf()); -+ case ClientboundChunksBiomes -> nmsPacket = new ClientboundChunksBiomesPacket(buf.getFriendlyByteBuf()); -+ case ClientboundClearTitles -> nmsPacket = new ClientboundClearTitlesPacket(buf.getFriendlyByteBuf()); -+ case ClientboundCommands -> nmsPacket = new ClientboundCommandsPacket(buf.getFriendlyByteBuf()); -+ case ClientboundCommandSuggestions -> nmsPacket = new ClientboundCommandSuggestionsPacket(buf.getFriendlyByteBuf()); -+ case ClientboundContainerClose -> nmsPacket = new ClientboundContainerClosePacket(buf.getFriendlyByteBuf()); -+ case ClientboundContainerSetContent -> nmsPacket = new ClientboundContainerSetContentPacket(buf.getFriendlyByteBuf()); -+ case ClientboundContainerSetData -> nmsPacket = new ClientboundContainerSetDataPacket(buf.getFriendlyByteBuf()); -+ case ClientboundContainerSetSlot -> nmsPacket = new ClientboundContainerSetSlotPacket(buf.getFriendlyByteBuf()); -+ case ClientboundCooldown -> nmsPacket = new ClientboundCooldownPacket(buf.getFriendlyByteBuf()); -+ case ClientboundCustomChatCompletions -> nmsPacket = new ClientboundCustomChatCompletionsPacket(buf.getFriendlyByteBuf()); -+ case ClientboundDamageEvent -> nmsPacket = new ClientboundDamageEventPacket(buf.getFriendlyByteBuf()); -+ case ClientboundDeleteChat -> nmsPacket = new ClientboundDeleteChatPacket(buf.getFriendlyByteBuf()); -+ case ClientboundDisguisedChat -> nmsPacket = new ClientboundDisguisedChatPacket(buf.getFriendlyByteBuf()); -+ case ClientboundEntityEvent -> nmsPacket = new ClientboundEntityEventPacket(buf.getFriendlyByteBuf()); -+ case ClientboundExplode -> nmsPacket = new ClientboundExplodePacket(buf.getFriendlyByteBuf()); -+ case ClientboundForgetLevelChunk -> nmsPacket = new ClientboundForgetLevelChunkPacket(buf.getFriendlyByteBuf()); -+ case ClientboundGameEvent -> nmsPacket = new ClientboundGameEventPacket(buf.getFriendlyByteBuf()); -+ case ClientboundHorseScreenOpen -> nmsPacket = new ClientboundHorseScreenOpenPacket(buf.getFriendlyByteBuf()); -+ case ClientboundHurtAnimation -> nmsPacket = new ClientboundHurtAnimationPacket(buf.getFriendlyByteBuf()); -+ case ClientboundInitializeBorder -> nmsPacket = new ClientboundInitializeBorderPacket(buf.getFriendlyByteBuf()); -+ case ClientboundLevelChunkWithLight -> nmsPacket = new ClientboundLevelChunkWithLightPacket(buf.getFriendlyByteBuf()); -+ case ClientboundLevelEvent -> nmsPacket = new ClientboundLevelEventPacket(buf.getFriendlyByteBuf()); -+ case ClientboundLevelParticles -> nmsPacket = new ClientboundLevelParticlesPacket(buf.getFriendlyByteBuf()); -+ case ClientboundLightUpdate -> nmsPacket = new ClientboundLightUpdatePacket(buf.getFriendlyByteBuf()); -+ case ClientboundLogin -> nmsPacket = new ClientboundLoginPacket(buf.getFriendlyByteBuf()); -+ case ClientboundMapItemData -> nmsPacket = new ClientboundMapItemDataPacket(buf.getFriendlyByteBuf()); -+ case ClientboundMerchantOffers -> nmsPacket = new ClientboundMerchantOffersPacket(buf.getFriendlyByteBuf()); -+ case ClientboundMoveVehicle -> nmsPacket = new ClientboundMoveVehiclePacket(buf.getFriendlyByteBuf()); -+ case ClientboundOpenBook -> nmsPacket = new ClientboundOpenBookPacket(buf.getFriendlyByteBuf()); -+ case ClientboundOpenScreen -> nmsPacket = new ClientboundOpenScreenPacket(buf.getFriendlyByteBuf()); -+ case ClientboundOpenSignEditor -> nmsPacket = new ClientboundOpenSignEditorPacket(buf.getFriendlyByteBuf()); -+ case ClientboundPlaceGhostRecipe -> nmsPacket = new ClientboundPlaceGhostRecipePacket(buf.getFriendlyByteBuf()); -+ case ClientboundPlayerAbilities -> nmsPacket = new ClientboundPlayerAbilitiesPacket(buf.getFriendlyByteBuf()); -+ case ClientboundPlayerChat -> nmsPacket = new ClientboundPlayerChatPacket(buf.getFriendlyByteBuf()); -+ case ClientboundPlayerCombatEnd -> nmsPacket = new ClientboundPlayerCombatEndPacket(buf.getFriendlyByteBuf()); -+ case ClientboundPlayerCombatEnter -> nmsPacket = new ClientboundPlayerCombatEnterPacket(buf.getFriendlyByteBuf()); -+ case ClientboundPlayerCombatKill -> nmsPacket = new ClientboundPlayerCombatKillPacket(buf.getFriendlyByteBuf()); -+ case ClientboundPlayerInfoRemove -> nmsPacket = new ClientboundPlayerInfoRemovePacket(buf.getFriendlyByteBuf()); -+ case ClientboundPlayerInfoUpdate -> nmsPacket = new ClientboundPlayerInfoUpdatePacket(buf.getFriendlyByteBuf()); -+ case ClientboundPlayerLookAt -> nmsPacket = new ClientboundPlayerLookAtPacket(buf.getFriendlyByteBuf()); -+ case ClientboundPlayerPosition -> nmsPacket = new ClientboundPlayerPositionPacket(buf.getFriendlyByteBuf()); -+ case ClientboundRecipe -> nmsPacket = new ClientboundRecipePacket(buf.getFriendlyByteBuf()); -+ case ClientboundRemoveEntities -> nmsPacket = new ClientboundRemoveEntitiesPacket(buf.getFriendlyByteBuf()); -+ case ClientboundRemoveMobEffect -> nmsPacket = new ClientboundRemoveMobEffectPacket(buf.getFriendlyByteBuf()); -+ case ClientboundResetScore -> nmsPacket = new ClientboundResetScorePacket(buf.getFriendlyByteBuf()); -+ case ClientboundRespawn -> nmsPacket = new ClientboundRespawnPacket(buf.getFriendlyByteBuf()); -+ case ClientboundRotateHead -> nmsPacket = new ClientboundRotateHeadPacket(buf.getFriendlyByteBuf()); -+ case ClientboundSectionBlocksUpdate -> nmsPacket = new ClientboundSectionBlocksUpdatePacket(buf.getFriendlyByteBuf()); -+ case ClientboundSelectAdvancementsTab -> nmsPacket = new ClientboundSelectAdvancementsTabPacket(buf.getFriendlyByteBuf()); -+ case ClientboundServerData -> nmsPacket = new ClientboundServerDataPacket(buf.getFriendlyByteBuf()); -+ case ClientboundSetActionBarText -> nmsPacket = new ClientboundSetActionBarTextPacket(buf.getFriendlyByteBuf()); -+ case ClientboundSetBorderCenter -> nmsPacket = new ClientboundSetBorderCenterPacket(buf.getFriendlyByteBuf()); -+ case ClientboundSetBorderLerpSize -> nmsPacket = new ClientboundSetBorderLerpSizePacket(buf.getFriendlyByteBuf()); -+ case ClientboundSetBorderSize -> nmsPacket = new ClientboundSetBorderSizePacket(buf.getFriendlyByteBuf()); -+ case ClientboundSetBorderWarningDelay -> nmsPacket = new ClientboundSetBorderWarningDelayPacket(buf.getFriendlyByteBuf()); -+ case ClientboundSetBorderWarningDistance -> nmsPacket = new ClientboundSetBorderWarningDistancePacket(buf.getFriendlyByteBuf()); -+ case ClientboundSetCamera -> nmsPacket = new ClientboundSetCameraPacket(buf.getFriendlyByteBuf()); -+ case ClientboundSetCarriedItem -> nmsPacket = new ClientboundSetCarriedItemPacket(buf.getFriendlyByteBuf()); -+ case ClientboundSetChunkCacheCenter -> nmsPacket = new ClientboundSetChunkCacheCenterPacket(buf.getFriendlyByteBuf()); -+ case ClientboundSetChunkCacheRadius -> nmsPacket = new ClientboundSetChunkCacheRadiusPacket(buf.getFriendlyByteBuf()); -+ case ClientboundSetDefaultSpawnPosition -> nmsPacket = new ClientboundSetDefaultSpawnPositionPacket(buf.getFriendlyByteBuf()); -+ case ClientboundSetDisplayObjective -> nmsPacket = new ClientboundSetDisplayObjectivePacket(buf.getFriendlyByteBuf()); -+ case ClientboundSetEntityData -> nmsPacket = new ClientboundSetEntityDataPacket(buf.getFriendlyByteBuf()); -+ case ClientboundSetEntityLink -> nmsPacket = new ClientboundSetEntityLinkPacket(buf.getFriendlyByteBuf()); -+ case ClientboundSetEntityMotion -> nmsPacket = new ClientboundSetEntityMotionPacket(buf.getFriendlyByteBuf()); -+ case ClientboundSetEquipment -> nmsPacket = new ClientboundSetEquipmentPacket(buf.getFriendlyByteBuf()); -+ case ClientboundSetExperience -> nmsPacket = new ClientboundSetExperiencePacket(buf.getFriendlyByteBuf()); -+ case ClientboundSetHealth -> nmsPacket = new ClientboundSetHealthPacket(buf.getFriendlyByteBuf()); -+ case ClientboundSetObjective -> nmsPacket = new ClientboundSetObjectivePacket(buf.getFriendlyByteBuf()); -+ case ClientboundSetPassengers -> nmsPacket = new ClientboundSetPassengersPacket(buf.getFriendlyByteBuf()); -+ case ClientboundSetPlayerTeam -> nmsPacket = new ClientboundSetPlayerTeamPacket(buf.getFriendlyByteBuf()); -+ case ClientboundSetScore -> nmsPacket = new ClientboundSetScorePacket(buf.getFriendlyByteBuf()); -+ case ClientboundSetSimulationDistance -> nmsPacket = new ClientboundSetSimulationDistancePacket(buf.getFriendlyByteBuf()); -+ case ClientboundSetSubtitleText -> nmsPacket = new ClientboundSetSubtitleTextPacket(buf.getFriendlyByteBuf()); -+ case ClientboundSetTime -> nmsPacket = new ClientboundSetTimePacket(buf.getFriendlyByteBuf()); -+ case ClientboundSetTitlesAnimation -> nmsPacket = new ClientboundSetTitlesAnimationPacket(buf.getFriendlyByteBuf()); -+ case ClientboundSetTitleText -> nmsPacket = new ClientboundSetTitleTextPacket(buf.getFriendlyByteBuf()); -+ case ClientboundSoundEntity -> nmsPacket = new ClientboundSoundEntityPacket(buf.getFriendlyByteBuf()); -+ case ClientboundSound -> nmsPacket = new ClientboundSoundPacket(buf.getFriendlyByteBuf()); -+ case ClientboundStartConfiguration -> nmsPacket = new ClientboundStartConfigurationPacket(buf.getFriendlyByteBuf()); -+ case ClientboundStopSound -> nmsPacket = new ClientboundStopSoundPacket(buf.getFriendlyByteBuf()); -+ case ClientboundSystemChat -> nmsPacket = new ClientboundSystemChatPacket(buf.getFriendlyByteBuf()); -+ case ClientboundTabList -> nmsPacket = new ClientboundTabListPacket(buf.getFriendlyByteBuf()); -+ case ClientboundTagQuery -> nmsPacket = new ClientboundTagQueryPacket(buf.getFriendlyByteBuf()); -+ case ClientboundTakeItemEntity -> nmsPacket = new ClientboundTakeItemEntityPacket(buf.getFriendlyByteBuf()); -+ case ClientboundTeleportEntity -> nmsPacket = new ClientboundTeleportEntityPacket(buf.getFriendlyByteBuf()); -+ case ClientboundTickingState -> nmsPacket = new ClientboundTickingStatePacket(buf.getFriendlyByteBuf()); -+ case ClientboundTickingStep -> nmsPacket = new ClientboundTickingStepPacket(buf.getFriendlyByteBuf()); -+ case ClientboundUpdateAdvancements -> nmsPacket = new ClientboundUpdateAdvancementsPacket(buf.getFriendlyByteBuf()); -+ case ClientboundUpdateAttributes -> nmsPacket = new ClientboundUpdateAttributesPacket(buf.getFriendlyByteBuf()); -+ case ClientboundUpdateMobEffect -> nmsPacket = new ClientboundUpdateMobEffectPacket(buf.getFriendlyByteBuf()); -+ case ClientboundUpdateRecipes -> nmsPacket = new ClientboundUpdateRecipesPacket(buf.getFriendlyByteBuf()); -+ -+ } -+ } catch (Exception e) { -+ throw new UnsupportedOperationException("This feature is not completely finished yet, packet type " + type + " is not supported temporary."); -+ } -+ } -+ @Override -+ public PacketType getType() { -+ return type; -+ } -+ -+ @Override -+ public Bytebuf getBytebuf() { -+ return wrappedBytebuf; -+ } -+ -+ public net.minecraft.network.protocol.Packet getNmsPacket() { -+ return nmsPacket; -+ } -+} -diff --git a/src/main/java/org/leavesmc/leaves/packet/bytebuf/WrappedBytebuf.java b/src/main/java/org/leavesmc/leaves/packet/bytebuf/WrappedBytebuf.java -new file mode 100644 -index 0000000000000000000000000000000000000000..7444fab5dba74abfcf7b33eb39ea51d53a283a15 ---- /dev/null -+++ b/src/main/java/org/leavesmc/leaves/packet/bytebuf/WrappedBytebuf.java -@@ -0,0 +1,114 @@ -+package org.leavesmc.leaves.packet.bytebuf; -+ -+import com.mojang.brigadier.exceptions.CommandSyntaxException; -+import io.netty.buffer.Unpooled; -+import net.minecraft.nbt.Tag; -+import net.minecraft.nbt.TagParser; -+import net.minecraft.network.FriendlyByteBuf; -+import net.minecraft.network.chat.Component; -+import org.bukkit.craftbukkit.inventory.CraftItemStack; -+import org.bukkit.inventory.ItemStack; -+import org.leavesmc.leaves.packet.WrappedPacket; -+import org.leavesmc.leaves.packet.Packet; -+import org.leavesmc.leaves.packet.PacketType; -+ -+import java.util.UUID; -+ -+public class WrappedBytebuf implements Bytebuf { -+ private final FriendlyByteBuf friendlyByteBuf; -+ public WrappedBytebuf() { -+ this(256); -+ } -+ public WrappedBytebuf(int initialCapacity) { -+ friendlyByteBuf = new FriendlyByteBuf(Unpooled.buffer(initialCapacity)); -+ } -+ -+ @Override -+ public Packet toPacket(PacketType type) { -+ return new WrappedPacket(type, this); -+ } -+ -+ @Override -+ public Bytebuf writeByte(int i) { -+ friendlyByteBuf.writeByte(i); -+ return this; -+ } -+ -+ @Override -+ public Bytebuf writeBoolean(boolean flag) { -+ friendlyByteBuf.writeBoolean(flag); -+ return this; -+ } -+ -+ @Override -+ public Bytebuf writeFloat(float f) { -+ friendlyByteBuf.writeFloat(f); -+ return this; -+ } -+ -+ @Override -+ public Bytebuf writeInt(int i) { -+ friendlyByteBuf.writeInt(i); -+ return this; -+ } -+ -+ @Override -+ public Bytebuf writeShort(int i) { -+ friendlyByteBuf.writeShort(i); -+ return this; -+ } -+ -+ @Override -+ public Bytebuf writeLong(long i) { -+ friendlyByteBuf.writeLong(i); -+ return this; -+ } -+ -+ @Override -+ public Bytebuf writeVarInt(int value) { -+ friendlyByteBuf.writeVarInt(value); -+ return this; -+ } -+ -+ @Override -+ public Bytebuf writeUUID(UUID uuid) { -+ return null; -+ } -+ -+ @Override -+ public Bytebuf writeVarLong(long value) { -+ friendlyByteBuf.writeVarLong(value); -+ return this; -+ } -+ -+ @Override -+ public Bytebuf writeStringNbt(String nbt) { -+ try { -+ Tag tag = TagParser.parseTag(nbt); -+ friendlyByteBuf.writeNbt(tag); -+ } catch (CommandSyntaxException e) { -+ throw new IllegalArgumentException(e); -+ } -+ return this; -+ } -+ -+ @Override -+ public Bytebuf writeStringComponent(String component) { -+ try { -+ friendlyByteBuf.writeComponent(Component.Serializer.fromJson(component)); -+ } catch (Exception e) { -+ throw new IllegalArgumentException(e); -+ } -+ return this; -+ } -+ -+ @Override -+ public Bytebuf writeItem(ItemStack itemStack) { -+ friendlyByteBuf.writeItem(((CraftItemStack) itemStack).handle); -+ return this; -+ } -+ -+ public FriendlyByteBuf getFriendlyByteBuf() { -+ return friendlyByteBuf; -+ } -+} From f2d1fb8513e8590ae8018b8115adff7b45d173aa Mon Sep 17 00:00:00 2001 From: Lumine1909 <133463833+Lumine1909@users.noreply.github.com> Date: Wed, 22 May 2024 17:37:51 -0400 Subject: [PATCH 3/9] better format --- patches/api/0011-Bytebuf-API.patch | 13 +- patches/server/0135-Bytebuf-API.patch | 399 +++++++++++++++++--------- 2 files changed, 267 insertions(+), 145 deletions(-) diff --git a/patches/api/0011-Bytebuf-API.patch b/patches/api/0011-Bytebuf-API.patch index 9db7387e..44dc6140 100644 --- a/patches/api/0011-Bytebuf-API.patch +++ b/patches/api/0011-Bytebuf-API.patch @@ -1,6 +1,6 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Lumine1909 <133463833+Lumine1909@users.noreply.github.com> -Date: Wed, 22 May 2024 10:12:04 _0800 +Date: Wed, 22 May 2024 10:12:04 +0800 Subject: [PATCH] Bytebuf API @@ -50,10 +50,10 @@ index 6c327a07bf8a6aa11a2d7dad12b2830acc539484..939bdc02b917ad72a8b7e6640067da19 Spigot spigot(); diff --git a/src/main/java/org/leavesmc/leaves/bytebuf/Bytebuf.java b/src/main/java/org/leavesmc/leaves/bytebuf/Bytebuf.java new file mode 100644 -index 0000000000000000000000000000000000000000..fd7b6e2c31aedbb5e58bd15a9a56c30f490d78c9 +index 0000000000000000000000000000000000000000..e01174a95bec27a5ca808dbc976a97a373577a3b --- /dev/null +++ b/src/main/java/org/leavesmc/leaves/bytebuf/Bytebuf.java -@@ -0,0 +1,25 @@ +@@ -0,0 +1,32 @@ +package org.leavesmc.leaves.bytebuf; + +import org.bukkit.Bukkit; @@ -70,6 +70,11 @@ index 0000000000000000000000000000000000000000..fd7b6e2c31aedbb5e58bd15a9a56c30f + } + byte[] toArray(); + ++ Bytebuf skipBytes(int i); ++ int readerIndex(); ++ Bytebuf readerIndex(int i); ++ int writerIndex(); ++ Bytebuf writerIndex(int i); + Bytebuf writeByte(int i); + byte readByte(); + Bytebuf writeShort(int i); @@ -78,6 +83,8 @@ index 0000000000000000000000000000000000000000..fd7b6e2c31aedbb5e58bd15a9a56c30f + int readInt(); + Bytebuf writeLong(long i); + long readLong(); ++ Bytebuf writeUTFString(String utf); ++ String readUTFString(); +} diff --git a/src/main/java/org/leavesmc/leaves/bytebuf/BytebufManager.java b/src/main/java/org/leavesmc/leaves/bytebuf/BytebufManager.java new file mode 100644 diff --git a/patches/server/0135-Bytebuf-API.patch b/patches/server/0135-Bytebuf-API.patch index 0c944e6d..360af4b8 100644 --- a/patches/server/0135-Bytebuf-API.patch +++ b/patches/server/0135-Bytebuf-API.patch @@ -5,7 +5,7 @@ Subject: [PATCH] Bytebuf API diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java -index 975062e67278614220eab0c301019a235c7953b7..cc23b30680f16ececc1843cfb132c7187c0a2fac 100644 +index 975062e67278614220eab0c301019a235c7953b7..c7623096107a2fd7efd54146b952669fc627a149 100644 --- a/src/main/java/net/minecraft/server/players/PlayerList.java +++ b/src/main/java/net/minecraft/server/players/PlayerList.java @@ -469,7 +469,7 @@ public abstract class PlayerList { @@ -13,35 +13,38 @@ index 975062e67278614220eab0c301019a235c7953b7..cc23b30680f16ececc1843cfb132c718 return; } - -+ ((org.leavesmc.leaves.bytebuf.SimpleBytebufManager) getServer().server.getBytebufManager()).injectPlayer(player.getBukkitEntity()); ++ getServer().server.getBytebufHandler().injectPlayer(player); org.leavesmc.leaves.protocol.core.LeavesProtocolManager.handlePlayerJoin(player); // Leaves - protocol // Leaves start - bot support diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java -index 405a04f2711e26e22d7dd091745b5b5a01d724d9..5c2484dc3aff26bbd9cbe423b33b2a3c23a70333 100644 +index 405a04f2711e26e22d7dd091745b5b5a01d724d9..dea7f028f0bd81e0811f37ce226da50dd4ed158b 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -307,6 +307,7 @@ public final class CraftServer implements Server { private final io.papermc.paper.potion.PaperPotionBrewer potionBrewer; // Paper - Custom Potion Mixes private final org.leavesmc.leaves.entity.CraftBotManager botManager = new org.leavesmc.leaves.entity.CraftBotManager(); // Leaves private final org.leavesmc.leaves.entity.CraftPhotographerManager photographerManager = new org.leavesmc.leaves.entity.CraftPhotographerManager(); // Leaves -+ private final org.leavesmc.leaves.bytebuf.SimpleBytebufManager bytebufManager = new org.leavesmc.leaves.bytebuf.SimpleBytebufManager(); // Leaves ++ private final org.leavesmc.leaves.bytebuf.internal.InternalBytebufHandler internalBytebufHandler = new org.leavesmc.leaves.bytebuf.internal.InternalBytebufHandler(); // Leaves // Paper start - Folia region threading API private final io.papermc.paper.threadedregions.scheduler.FallbackRegionScheduler regionizedScheduler = new io.papermc.paper.threadedregions.scheduler.FallbackRegionScheduler(); -@@ -3291,4 +3292,10 @@ public final class CraftServer implements Server { +@@ -3291,4 +3292,13 @@ public final class CraftServer implements Server { return photographerManager; } // Leaves end - replay mod api + // Leaves start - Bytebuf API + @Override + public org.leavesmc.leaves.bytebuf.BytebufManager getBytebufManager() { -+ return bytebufManager; ++ return internalBytebufHandler.getManager(); ++ } ++ public org.leavesmc.leaves.bytebuf.internal.InternalBytebufHandler getBytebufHandler() { ++ return internalBytebufHandler; + } + // Leaves end - Bytebuf API } diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java -index 25a5ce110c0515f5a0ee5f287a7f3dd029a8f29f..2c14b256f470c3fbbc55a0444f5f68ba1f22785c 100644 +index 25a5ce110c0515f5a0ee5f287a7f3dd029a8f29f..1eb60f1d9bec4b11bb1d0242266d6e084e53b372 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -3519,4 +3519,14 @@ public class CraftPlayer extends CraftHumanEntity implements Player { @@ -51,23 +54,170 @@ index 25a5ce110c0515f5a0ee5f287a7f3dd029a8f29f..2c14b256f470c3fbbc55a0444f5f68ba + // Leaves start - Bytebuf API + @Override + public void sendPacket(org.leavesmc.leaves.bytebuf.packet.Packet packet) { -+ ((org.leavesmc.leaves.bytebuf.SimpleBytebufManager) getServer().getBytebufManager()).applyPacketToPlayer(this, packet); ++ ((CraftServer) getServer()).getBytebufHandler().applyPacketToPlayer(this, packet); + } + @Override + public void sendPacket(org.leavesmc.leaves.bytebuf.Bytebuf bytebuf, org.leavesmc.leaves.bytebuf.packet.PacketType type) { -+ ((org.leavesmc.leaves.bytebuf.SimpleBytebufManager) getServer().getBytebufManager()).applyPacketToPlayer(this, new org.leavesmc.leaves.bytebuf.packet.Packet(type, bytebuf)); ++ ((CraftServer) getServer()).getBytebufHandler().applyPacketToPlayer(this, new org.leavesmc.leaves.bytebuf.packet.Packet(type, bytebuf)); + } + // Leaves end - Bytebuf API } diff --git a/src/main/java/org/leavesmc/leaves/bytebuf/SimpleBytebufManager.java b/src/main/java/org/leavesmc/leaves/bytebuf/SimpleBytebufManager.java new file mode 100644 -index 0000000000000000000000000000000000000000..26179fcc836fcb8d1eda8ddb8a875cb9cdd421ab +index 0000000000000000000000000000000000000000..854af9da6e27e037e022abfef241221ef1c75d0d --- /dev/null +++ b/src/main/java/org/leavesmc/leaves/bytebuf/SimpleBytebufManager.java -@@ -0,0 +1,1008 @@ +@@ -0,0 +1,31 @@ +package org.leavesmc.leaves.bytebuf; + +import io.netty.buffer.Unpooled; ++import org.bukkit.plugin.Plugin; ++import org.leavesmc.leaves.bytebuf.internal.InternalBytebufHandler; ++import org.leavesmc.leaves.bytebuf.packet.PacketListener; ++ ++public class SimpleBytebufManager implements BytebufManager { ++ private final InternalBytebufHandler internal; ++ public SimpleBytebufManager(InternalBytebufHandler internal) { ++ this.internal = internal; ++ } ++ @Override ++ public void registerListener(Plugin plugin, PacketListener listener) { ++ internal.listenerMap.put(listener, plugin); ++ } ++ ++ @Override ++ public void unregisterListener(Plugin plugin, PacketListener listener) { ++ internal.listenerMap.remove(listener); ++ } ++ @Override ++ public Bytebuf newBytebuf(int size) { ++ return new WrappedBytebuf(Unpooled.buffer(size)); ++ } ++ ++ @Override ++ public Bytebuf toBytebuf(byte[] bytes) { ++ return new WrappedBytebuf(Unpooled.wrappedBuffer(bytes)); ++ } ++} +diff --git a/src/main/java/org/leavesmc/leaves/bytebuf/WrappedBytebuf.java b/src/main/java/org/leavesmc/leaves/bytebuf/WrappedBytebuf.java +new file mode 100644 +index 0000000000000000000000000000000000000000..39e53a092ffd7e3e04d529edb3468ba614373165 +--- /dev/null ++++ b/src/main/java/org/leavesmc/leaves/bytebuf/WrappedBytebuf.java +@@ -0,0 +1,104 @@ ++package org.leavesmc.leaves.bytebuf; ++ ++import io.netty.buffer.ByteBuf; ++import net.minecraft.network.FriendlyByteBuf; ++ ++public class WrappedBytebuf implements Bytebuf { ++ private final FriendlyByteBuf buf; ++ ++ public WrappedBytebuf(ByteBuf buf) { ++ this.buf = new FriendlyByteBuf(buf); ++ } ++ ++ public FriendlyByteBuf getFriendlyBytebuf() { ++ return buf; ++ } ++ ++ @Override ++ public byte[] toArray() { ++ return buf.array(); ++ } ++ ++ @Override ++ public Bytebuf skipBytes(int i) { ++ buf.skipBytes(i); ++ return this; ++ } ++ ++ @Override ++ public int readerIndex() { ++ return buf.readerIndex(); ++ } ++ ++ @Override ++ public Bytebuf readerIndex(int i) { ++ buf.readerIndex(i); ++ return this; ++ } ++ ++ @Override ++ public int writerIndex() { ++ return buf.writerIndex(); ++ } ++ ++ @Override ++ public Bytebuf writerIndex(int i) { ++ buf.writerIndex(i); ++ return this; ++ } ++ ++ @Override ++ public Bytebuf writeByte(int i) { ++ buf.writeByte(i); ++ return this; ++ } ++ ++ @Override ++ public byte readByte() { ++ return buf.readByte(); ++ } ++ ++ @Override ++ public Bytebuf writeShort(int i) { ++ buf.writeShort(i); ++ return this; ++ } ++ ++ @Override ++ public short readShort() { ++ return buf.readShort(); ++ } ++ ++ @Override ++ public Bytebuf writeInt(int i) { ++ buf.writeShort(i); ++ return this; ++ } ++ ++ @Override ++ public int readInt() { ++ return buf.readInt(); ++ } ++ ++ @Override ++ public Bytebuf writeLong(long i) { ++ buf.writeLong(i); ++ return this; ++ } ++ ++ @Override ++ public long readLong() { ++ return buf.readLong(); ++ } ++ ++ @Override ++ public Bytebuf writeUTFString(String utf) { ++ buf.writeUtf(utf); ++ return this; ++ } ++ ++ @Override ++ public String readUTFString() { ++ return buf.readUtf(); ++ } ++} +diff --git a/src/main/java/org/leavesmc/leaves/bytebuf/internal/InternalBytebufHandler.java b/src/main/java/org/leavesmc/leaves/bytebuf/internal/InternalBytebufHandler.java +new file mode 100644 +index 0000000000000000000000000000000000000000..1dff2f33d0c55c286a8f71652f086d5a2fab471c +--- /dev/null ++++ b/src/main/java/org/leavesmc/leaves/bytebuf/internal/InternalBytebufHandler.java +@@ -0,0 +1,1042 @@ ++package org.leavesmc.leaves.bytebuf.internal; ++ ++import io.netty.buffer.Unpooled; +import io.netty.channel.ChannelDuplexHandler; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelPromise; @@ -78,9 +228,14 @@ index 0000000000000000000000000000000000000000..26179fcc836fcb8d1eda8ddb8a875cb9 +import net.minecraft.network.protocol.common.*; +import net.minecraft.network.protocol.game.*; +import net.minecraft.server.MinecraftServer; ++import net.minecraft.server.level.ServerPlayer; +import org.bukkit.craftbukkit.entity.CraftPlayer; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; ++import org.leavesmc.leaves.bytebuf.Bytebuf; ++import org.leavesmc.leaves.bytebuf.BytebufManager; ++import org.leavesmc.leaves.bytebuf.SimpleBytebufManager; ++import org.leavesmc.leaves.bytebuf.WrappedBytebuf; +import org.leavesmc.leaves.bytebuf.packet.Packet; +import org.leavesmc.leaves.bytebuf.packet.PacketListener; +import org.leavesmc.leaves.bytebuf.packet.PacketType; @@ -88,13 +243,16 @@ index 0000000000000000000000000000000000000000..26179fcc836fcb8d1eda8ddb8a875cb9 +import java.util.HashMap; +import java.util.Map; + -+public class SimpleBytebufManager implements BytebufManager { ++public class InternalBytebufHandler { ++ + class PacketHandler extends ChannelDuplexHandler { + private final static String handlerName = "leaves-bytebuf-handler"; + private final Player player; ++ + public PacketHandler(Player player) { + this.player = player; + } ++ + @Override + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { + if (msg instanceof BundlePacket || msg instanceof BundleDelimiterPacket) { @@ -109,6 +267,7 @@ index 0000000000000000000000000000000000000000..26179fcc836fcb8d1eda8ddb8a875cb9 + if (msg != null) { + super.channelRead(ctx, msg); + } ++ + } + + @Override @@ -129,34 +288,18 @@ index 0000000000000000000000000000000000000000..26179fcc836fcb8d1eda8ddb8a875cb9 + + } + ++ public final Map listenerMap = new HashMap<>(); ++ private final BytebufManager manager = new SimpleBytebufManager(this); + -+ private final Map listenerMap = new HashMap<>(); -+ @Override -+ public void registerListener(Plugin plugin, PacketListener listener) { -+ listenerMap.put(listener, plugin); -+ } + -+ @Override -+ public void unregisterListener(Plugin plugin, PacketListener listener) { -+ listenerMap.remove(listener); -+ } -+ @Override -+ public Bytebuf newBytebuf(int size) { -+ return new WrappedBytebuf(Unpooled.buffer(size)); ++ public void injectPlayer(ServerPlayer player) { ++ player.connection.connection.channel.pipeline().addBefore("packet_handler", PacketHandler.handlerName, new PacketHandler(player.getBukkitEntity())); + } + -+ @Override -+ public Bytebuf toBytebuf(byte[] bytes) { -+ return new WrappedBytebuf(Unpooled.wrappedBuffer(bytes)); ++ public BytebufManager getManager() { ++ return manager; + } + -+ -+ -+ public void injectPlayer(Player player) { -+ ((CraftPlayer) player).getHandle().connection.connection.channel.pipeline().addBefore( -+ "packet_handler", PacketHandler.handlerName, new PacketHandler(player) -+ ); -+ } + public net.minecraft.network.protocol.Packet callPacketInEvent(Player player, Packet packet) { + for (PacketListener listener : listenerMap.keySet()) { + if (listenerMap.get(listener).isEnabled()) { @@ -167,6 +310,7 @@ index 0000000000000000000000000000000000000000..26179fcc836fcb8d1eda8ddb8a875cb9 + } + return createNMSPacket(packet); + } ++ + public net.minecraft.network.protocol.Packet callPacketOutEvent(Player player, Packet packet) { + for (PacketListener listener : listenerMap.keySet()) { + if (listenerMap.get(listener).isEnabled()) { @@ -177,11 +321,13 @@ index 0000000000000000000000000000000000000000..26179fcc836fcb8d1eda8ddb8a875cb9 + } + return createNMSPacket(packet); + } ++ + public void applyPacketToPlayer(Player player, Packet packet) { + Connection sp = ((CraftPlayer) player).getHandle().connection.connection; + sp.channel.writeAndFlush(createNMSPacket(packet)); + } -+ private net.minecraft.network.protocol.Packet createNMSPacket(Packet packet) { ++ ++ public net.minecraft.network.protocol.Packet createNMSPacket(Packet packet) { + RegistryFriendlyByteBuf buf = new RegistryFriendlyByteBuf(((WrappedBytebuf) packet.bytebuf()).getFriendlyBytebuf(), MinecraftServer.getServer().registryAccess()); + PacketType type = packet.type(); + net.minecraft.network.protocol.Packet nmsPacket = null; @@ -197,18 +343,22 @@ index 0000000000000000000000000000000000000000..26179fcc836fcb8d1eda8ddb8a875cb9 + case ClientboundBlockUpdate -> nmsPacket = ClientboundBlockUpdatePacket.STREAM_CODEC.decode(buf); + case ClientboundBossEvent -> nmsPacket = ClientboundBossEventPacket.STREAM_CODEC.decode(buf); + case ClientboundChangeDifficulty -> nmsPacket = ClientboundChangeDifficultyPacket.STREAM_CODEC.decode(buf); -+ case ClientboundChunkBatchFinished -> nmsPacket = ClientboundChunkBatchFinishedPacket.STREAM_CODEC.decode(buf); ++ case ClientboundChunkBatchFinished -> ++ nmsPacket = ClientboundChunkBatchFinishedPacket.STREAM_CODEC.decode(buf); + case ClientboundChunkBatchStart -> nmsPacket = ClientboundChunkBatchStartPacket.STREAM_CODEC.decode(buf); + case ClientboundChunksBiomes -> nmsPacket = ClientboundChunksBiomesPacket.STREAM_CODEC.decode(buf); + case ClientboundClearTitles -> nmsPacket = ClientboundClearTitlesPacket.STREAM_CODEC.decode(buf); -+ case ClientboundCommandSuggestions -> nmsPacket = ClientboundCommandSuggestionsPacket.STREAM_CODEC.decode(buf); ++ case ClientboundCommandSuggestions -> ++ nmsPacket = ClientboundCommandSuggestionsPacket.STREAM_CODEC.decode(buf); + case ClientboundCommands -> nmsPacket = ClientboundCommandsPacket.STREAM_CODEC.decode(buf); + case ClientboundContainerClose -> nmsPacket = ClientboundContainerClosePacket.STREAM_CODEC.decode(buf); -+ case ClientboundContainerSetContent -> nmsPacket = ClientboundContainerSetContentPacket.STREAM_CODEC.decode(buf); ++ case ClientboundContainerSetContent -> ++ nmsPacket = ClientboundContainerSetContentPacket.STREAM_CODEC.decode(buf); + case ClientboundContainerSetData -> nmsPacket = ClientboundContainerSetDataPacket.STREAM_CODEC.decode(buf); + case ClientboundContainerSetSlot -> nmsPacket = ClientboundContainerSetSlotPacket.STREAM_CODEC.decode(buf); + case ClientboundCooldown -> nmsPacket = ClientboundCooldownPacket.STREAM_CODEC.decode(buf); -+ case ClientboundCustomChatCompletions -> nmsPacket = ClientboundCustomChatCompletionsPacket.STREAM_CODEC.decode(buf); ++ case ClientboundCustomChatCompletions -> ++ nmsPacket = ClientboundCustomChatCompletionsPacket.STREAM_CODEC.decode(buf); + case ClientboundDamageEvent -> nmsPacket = ClientboundDamageEventPacket.STREAM_CODEC.decode(buf); + case ClientboundDebugSample -> nmsPacket = ClientboundDebugSamplePacket.STREAM_CODEC.decode(buf); + case ClientboundDeleteChat -> nmsPacket = ClientboundDeleteChatPacket.STREAM_CODEC.decode(buf); @@ -220,7 +370,8 @@ index 0000000000000000000000000000000000000000..26179fcc836fcb8d1eda8ddb8a875cb9 + case ClientboundHorseScreenOpen -> nmsPacket = ClientboundHorseScreenOpenPacket.STREAM_CODEC.decode(buf); + case ClientboundHurtAnimation -> nmsPacket = ClientboundHurtAnimationPacket.STREAM_CODEC.decode(buf); + case ClientboundInitializeBorder -> nmsPacket = ClientboundInitializeBorderPacket.STREAM_CODEC.decode(buf); -+ case ClientboundLevelChunkWithLight -> nmsPacket = ClientboundLevelChunkWithLightPacket.STREAM_CODEC.decode(buf); ++ case ClientboundLevelChunkWithLight -> ++ nmsPacket = ClientboundLevelChunkWithLightPacket.STREAM_CODEC.decode(buf); + case ClientboundLevelEvent -> nmsPacket = ClientboundLevelEventPacket.STREAM_CODEC.decode(buf); + case ClientboundLevelParticles -> nmsPacket = ClientboundLevelParticlesPacket.STREAM_CODEC.decode(buf); + case ClientboundLightUpdate -> nmsPacket = ClientboundLightUpdatePacket.STREAM_CODEC.decode(buf); @@ -238,7 +389,8 @@ index 0000000000000000000000000000000000000000..26179fcc836fcb8d1eda8ddb8a875cb9 + case ClientboundPlayerAbilities -> nmsPacket = ClientboundPlayerAbilitiesPacket.STREAM_CODEC.decode(buf); + case ClientboundPlayerChat -> nmsPacket = ClientboundPlayerChatPacket.STREAM_CODEC.decode(buf); + case ClientboundPlayerCombatEnd -> nmsPacket = ClientboundPlayerCombatEndPacket.STREAM_CODEC.decode(buf); -+ case ClientboundPlayerCombatEnter -> nmsPacket = ClientboundPlayerCombatEnterPacket.STREAM_CODEC.decode(buf); ++ case ClientboundPlayerCombatEnter -> ++ nmsPacket = ClientboundPlayerCombatEnterPacket.STREAM_CODEC.decode(buf); + case ClientboundPlayerCombatKill -> nmsPacket = ClientboundPlayerCombatKillPacket.STREAM_CODEC.decode(buf); + case ClientboundPlayerInfoRemove -> nmsPacket = ClientboundPlayerInfoRemovePacket.STREAM_CODEC.decode(buf); + case ClientboundPlayerInfoUpdate -> nmsPacket = ClientboundPlayerInfoUpdatePacket.STREAM_CODEC.decode(buf); @@ -249,21 +401,30 @@ index 0000000000000000000000000000000000000000..26179fcc836fcb8d1eda8ddb8a875cb9 + case ClientboundRemoveMobEffect -> nmsPacket = ClientboundRemoveMobEffectPacket.STREAM_CODEC.decode(buf); + case ClientboundRespawn -> nmsPacket = ClientboundRespawnPacket.STREAM_CODEC.decode(buf); + case ClientboundRotateHead -> nmsPacket = ClientboundRotateHeadPacket.STREAM_CODEC.decode(buf); -+ case ClientboundSectionBlocksUpdate -> nmsPacket = ClientboundSectionBlocksUpdatePacket.STREAM_CODEC.decode(buf); -+ case ClientboundSelectAdvancementsTab -> nmsPacket = ClientboundSelectAdvancementsTabPacket.STREAM_CODEC.decode(buf); ++ case ClientboundSectionBlocksUpdate -> ++ nmsPacket = ClientboundSectionBlocksUpdatePacket.STREAM_CODEC.decode(buf); ++ case ClientboundSelectAdvancementsTab -> ++ nmsPacket = ClientboundSelectAdvancementsTabPacket.STREAM_CODEC.decode(buf); + case ClientboundServerData -> nmsPacket = ClientboundServerDataPacket.STREAM_CODEC.decode(buf); + case ClientboundSetActionBarText -> nmsPacket = ClientboundSetActionBarTextPacket.STREAM_CODEC.decode(buf); + case ClientboundSetBorderCenter -> nmsPacket = ClientboundSetBorderCenterPacket.STREAM_CODEC.decode(buf); -+ case ClientboundSetBorderLerpSize -> nmsPacket = ClientboundSetBorderLerpSizePacket.STREAM_CODEC.decode(buf); ++ case ClientboundSetBorderLerpSize -> ++ nmsPacket = ClientboundSetBorderLerpSizePacket.STREAM_CODEC.decode(buf); + case ClientboundSetBorderSize -> nmsPacket = ClientboundSetBorderSizePacket.STREAM_CODEC.decode(buf); -+ case ClientboundSetBorderWarningDelay -> nmsPacket = ClientboundSetBorderWarningDelayPacket.STREAM_CODEC.decode(buf); -+ case ClientboundSetBorderWarningDistance -> nmsPacket = ClientboundSetBorderWarningDistancePacket.STREAM_CODEC.decode(buf); ++ case ClientboundSetBorderWarningDelay -> ++ nmsPacket = ClientboundSetBorderWarningDelayPacket.STREAM_CODEC.decode(buf); ++ case ClientboundSetBorderWarningDistance -> ++ nmsPacket = ClientboundSetBorderWarningDistancePacket.STREAM_CODEC.decode(buf); + case ClientboundSetCamera -> nmsPacket = ClientboundSetCameraPacket.STREAM_CODEC.decode(buf); + case ClientboundSetCarriedItem -> nmsPacket = ClientboundSetCarriedItemPacket.STREAM_CODEC.decode(buf); -+ case ClientboundSetChunkCacheCenter -> nmsPacket = ClientboundSetChunkCacheCenterPacket.STREAM_CODEC.decode(buf); -+ case ClientboundSetChunkCacheRadius -> nmsPacket = ClientboundSetChunkCacheRadiusPacket.STREAM_CODEC.decode(buf); -+ case ClientboundSetDefaultSpawnPosition -> nmsPacket = ClientboundSetDefaultSpawnPositionPacket.STREAM_CODEC.decode(buf); -+ case ClientboundSetDisplayObjective -> nmsPacket = ClientboundSetDisplayObjectivePacket.STREAM_CODEC.decode(buf); ++ case ClientboundSetChunkCacheCenter -> ++ nmsPacket = ClientboundSetChunkCacheCenterPacket.STREAM_CODEC.decode(buf); ++ case ClientboundSetChunkCacheRadius -> ++ nmsPacket = ClientboundSetChunkCacheRadiusPacket.STREAM_CODEC.decode(buf); ++ case ClientboundSetDefaultSpawnPosition -> ++ nmsPacket = ClientboundSetDefaultSpawnPositionPacket.STREAM_CODEC.decode(buf); ++ case ClientboundSetDisplayObjective -> ++ nmsPacket = ClientboundSetDisplayObjectivePacket.STREAM_CODEC.decode(buf); + case ClientboundSetEntityData -> nmsPacket = ClientboundSetEntityDataPacket.STREAM_CODEC.decode(buf); + case ClientboundSetEntityLink -> nmsPacket = ClientboundSetEntityLinkPacket.STREAM_CODEC.decode(buf); + case ClientboundSetEntityMotion -> nmsPacket = ClientboundSetEntityMotionPacket.STREAM_CODEC.decode(buf); @@ -274,42 +435,56 @@ index 0000000000000000000000000000000000000000..26179fcc836fcb8d1eda8ddb8a875cb9 + case ClientboundSetPassengers -> nmsPacket = ClientboundSetPassengersPacket.STREAM_CODEC.decode(buf); + case ClientboundSetPlayerTeam -> nmsPacket = ClientboundSetPlayerTeamPacket.STREAM_CODEC.decode(buf); + case ClientboundSetScore -> nmsPacket = ClientboundSetScorePacket.STREAM_CODEC.decode(buf); -+ case ClientboundSetSimulationDistance -> nmsPacket = ClientboundSetSimulationDistancePacket.STREAM_CODEC.decode(buf); ++ case ClientboundSetSimulationDistance -> ++ nmsPacket = ClientboundSetSimulationDistancePacket.STREAM_CODEC.decode(buf); + case ClientboundSetSubtitleText -> nmsPacket = ClientboundSetSubtitleTextPacket.STREAM_CODEC.decode(buf); + case ClientboundSetTime -> nmsPacket = ClientboundSetTimePacket.STREAM_CODEC.decode(buf); + case ClientboundSetTitleText -> nmsPacket = ClientboundSetTitleTextPacket.STREAM_CODEC.decode(buf); -+ case ClientboundSetTitlesAnimation -> nmsPacket = ClientboundSetTitlesAnimationPacket.STREAM_CODEC.decode(buf); ++ case ClientboundSetTitlesAnimation -> ++ nmsPacket = ClientboundSetTitlesAnimationPacket.STREAM_CODEC.decode(buf); + case ClientboundSoundEntity -> nmsPacket = ClientboundSoundEntityPacket.STREAM_CODEC.decode(buf); + case ClientboundSound -> nmsPacket = ClientboundSoundPacket.STREAM_CODEC.decode(buf); -+ case ClientboundStartConfiguration -> nmsPacket = ClientboundStartConfigurationPacket.STREAM_CODEC.decode(buf); ++ case ClientboundStartConfiguration -> ++ nmsPacket = ClientboundStartConfigurationPacket.STREAM_CODEC.decode(buf); + case ClientboundStopSound -> nmsPacket = ClientboundStopSoundPacket.STREAM_CODEC.decode(buf); + case ClientboundSystemChat -> nmsPacket = ClientboundSystemChatPacket.STREAM_CODEC.decode(buf); + case ClientboundTabList -> nmsPacket = ClientboundTabListPacket.STREAM_CODEC.decode(buf); + case ClientboundTagQuery -> nmsPacket = ClientboundTagQueryPacket.STREAM_CODEC.decode(buf); + case ClientboundTakeItemEntity -> nmsPacket = ClientboundTakeItemEntityPacket.STREAM_CODEC.decode(buf); + case ClientboundTeleportEntity -> nmsPacket = ClientboundTeleportEntityPacket.STREAM_CODEC.decode(buf); -+ case ClientboundUpdateAdvancements -> nmsPacket = ClientboundUpdateAdvancementsPacket.STREAM_CODEC.decode(buf); ++ case ClientboundUpdateAdvancements -> ++ nmsPacket = ClientboundUpdateAdvancementsPacket.STREAM_CODEC.decode(buf); + case ClientboundUpdateAttributes -> nmsPacket = ClientboundUpdateAttributesPacket.STREAM_CODEC.decode(buf); + case ClientboundUpdateMobEffect -> nmsPacket = ClientboundUpdateMobEffectPacket.STREAM_CODEC.decode(buf); + case ClientboundUpdateRecipes -> nmsPacket = ClientboundUpdateRecipesPacket.STREAM_CODEC.decode(buf); + case ClientboundProjectilePower -> nmsPacket = ClientboundProjectilePowerPacket.STREAM_CODEC.decode(buf); -+ case ServerboundAcceptTeleportation -> nmsPacket = ServerboundAcceptTeleportationPacket.STREAM_CODEC.decode(buf); -+ case ServerboundBlockEntityTagQuery -> nmsPacket = ServerboundBlockEntityTagQueryPacket.STREAM_CODEC.decode(buf); ++ case ServerboundAcceptTeleportation -> ++ nmsPacket = ServerboundAcceptTeleportationPacket.STREAM_CODEC.decode(buf); ++ case ServerboundBlockEntityTagQuery -> ++ nmsPacket = ServerboundBlockEntityTagQueryPacket.STREAM_CODEC.decode(buf); + case ServerboundChangeDifficulty -> nmsPacket = ServerboundChangeDifficultyPacket.STREAM_CODEC.decode(buf); + case ServerboundChatAck -> nmsPacket = ServerboundChatAckPacket.STREAM_CODEC.decode(buf); + case ServerboundChatCommand -> nmsPacket = ServerboundChatCommandPacket.STREAM_CODEC.decode(buf); -+ case ServerboundChatCommandSigned -> nmsPacket = ServerboundChatCommandSignedPacket.STREAM_CODEC.decode(buf); ++ case ServerboundChatCommandSigned -> ++ nmsPacket = ServerboundChatCommandSignedPacket.STREAM_CODEC.decode(buf); + case ServerboundChat -> nmsPacket = ServerboundChatPacket.STREAM_CODEC.decode(buf); -+ case ServerboundChatSessionUpdate -> nmsPacket = ServerboundChatSessionUpdatePacket.STREAM_CODEC.decode(buf); -+ case ServerboundChunkBatchReceived -> nmsPacket = ServerboundChunkBatchReceivedPacket.STREAM_CODEC.decode(buf); ++ case ServerboundChatSessionUpdate -> ++ nmsPacket = ServerboundChatSessionUpdatePacket.STREAM_CODEC.decode(buf); ++ case ServerboundChunkBatchReceived -> ++ nmsPacket = ServerboundChunkBatchReceivedPacket.STREAM_CODEC.decode(buf); + case ServerboundClientCommand -> nmsPacket = ServerboundClientCommandPacket.STREAM_CODEC.decode(buf); -+ case ServerboundCommandSuggestion -> nmsPacket = ServerboundCommandSuggestionPacket.STREAM_CODEC.decode(buf); -+ case ServerboundConfigurationAcknowledged -> nmsPacket = ServerboundConfigurationAcknowledgedPacket.STREAM_CODEC.decode(buf); -+ case ServerboundContainerButtonClick -> nmsPacket = ServerboundContainerButtonClickPacket.STREAM_CODEC.decode(buf); ++ case ServerboundCommandSuggestion -> ++ nmsPacket = ServerboundCommandSuggestionPacket.STREAM_CODEC.decode(buf); ++ case ServerboundConfigurationAcknowledged -> ++ nmsPacket = ServerboundConfigurationAcknowledgedPacket.STREAM_CODEC.decode(buf); ++ case ServerboundContainerButtonClick -> ++ nmsPacket = ServerboundContainerButtonClickPacket.STREAM_CODEC.decode(buf); + case ServerboundContainerClick -> nmsPacket = ServerboundContainerClickPacket.STREAM_CODEC.decode(buf); + case ServerboundContainerClose -> nmsPacket = ServerboundContainerClosePacket.STREAM_CODEC.decode(buf); -+ case ServerboundContainerSlotStateChanged -> nmsPacket = ServerboundContainerSlotStateChangedPacket.STREAM_CODEC.decode(buf); -+ case ServerboundDebugSampleSubscription -> nmsPacket = ServerboundDebugSampleSubscriptionPacket.STREAM_CODEC.decode(buf); ++ case ServerboundContainerSlotStateChanged -> ++ nmsPacket = ServerboundContainerSlotStateChangedPacket.STREAM_CODEC.decode(buf); ++ case ServerboundDebugSampleSubscription -> ++ nmsPacket = ServerboundDebugSampleSubscriptionPacket.STREAM_CODEC.decode(buf); + case ServerboundEditBook -> nmsPacket = ServerboundEditBookPacket.STREAM_CODEC.decode(buf); + case ServerboundEntityTagQuery -> nmsPacket = ServerboundEntityTagQueryPacket.STREAM_CODEC.decode(buf); + case ServerboundInteract -> nmsPacket = ServerboundInteractPacket.STREAM_CODEC.decode(buf); @@ -318,7 +493,8 @@ index 0000000000000000000000000000000000000000..26179fcc836fcb8d1eda8ddb8a875cb9 + case ServerboundMovePlayerPos -> nmsPacket = ServerboundMovePlayerPacket.Pos.STREAM_CODEC.decode(buf); + case ServerboundMovePlayerPosRot -> nmsPacket = ServerboundMovePlayerPacket.PosRot.STREAM_CODEC.decode(buf); + case ServerboundMovePlayerRot -> nmsPacket = ServerboundMovePlayerPacket.Rot.STREAM_CODEC.decode(buf); -+ case ServerboundMovePlayerStatusOnly -> nmsPacket = ServerboundMovePlayerPacket.StatusOnly.STREAM_CODEC.decode(buf); ++ case ServerboundMovePlayerStatusOnly -> ++ nmsPacket = ServerboundMovePlayerPacket.StatusOnly.STREAM_CODEC.decode(buf); + case ServerboundMoveVehicle -> nmsPacket = ServerboundMoveVehiclePacket.STREAM_CODEC.decode(buf); + case ServerboundPaddleBoat -> nmsPacket = ServerboundPaddleBoatPacket.STREAM_CODEC.decode(buf); + case ServerboundPickItem -> nmsPacket = ServerboundPickItemPacket.STREAM_CODEC.decode(buf); @@ -327,18 +503,23 @@ index 0000000000000000000000000000000000000000..26179fcc836fcb8d1eda8ddb8a875cb9 + case ServerboundPlayerAction -> nmsPacket = ServerboundPlayerActionPacket.STREAM_CODEC.decode(buf); + case ServerboundPlayerCommand -> nmsPacket = ServerboundPlayerCommandPacket.STREAM_CODEC.decode(buf); + case ServerboundPlayerInput -> nmsPacket = ServerboundPlayerInputPacket.STREAM_CODEC.decode(buf); -+ case ServerboundRecipeBookChangeSettings -> nmsPacket = ServerboundRecipeBookChangeSettingsPacket.STREAM_CODEC.decode(buf); -+ case ServerboundRecipeBookSeenRecipe -> nmsPacket = ServerboundRecipeBookSeenRecipePacket.STREAM_CODEC.decode(buf); ++ case ServerboundRecipeBookChangeSettings -> ++ nmsPacket = ServerboundRecipeBookChangeSettingsPacket.STREAM_CODEC.decode(buf); ++ case ServerboundRecipeBookSeenRecipe -> ++ nmsPacket = ServerboundRecipeBookSeenRecipePacket.STREAM_CODEC.decode(buf); + case ServerboundRenameItem -> nmsPacket = ServerboundRenameItemPacket.STREAM_CODEC.decode(buf); + case ServerboundSeenAdvancements -> nmsPacket = ServerboundSeenAdvancementsPacket.STREAM_CODEC.decode(buf); + case ServerboundSelectTrade -> nmsPacket = ServerboundSelectTradePacket.STREAM_CODEC.decode(buf); + case ServerboundSetBeacon -> nmsPacket = ServerboundSetBeaconPacket.STREAM_CODEC.decode(buf); + case ServerboundSetCarriedItem -> nmsPacket = ServerboundSetCarriedItemPacket.STREAM_CODEC.decode(buf); + case ServerboundSetCommandBlock -> nmsPacket = ServerboundSetCommandBlockPacket.STREAM_CODEC.decode(buf); -+ case ServerboundSetCommandMinecart -> nmsPacket = ServerboundSetCommandMinecartPacket.STREAM_CODEC.decode(buf); -+ case ServerboundSetCreativeModeSlot -> nmsPacket = ServerboundSetCreativeModeSlotPacket.STREAM_CODEC.decode(buf); ++ case ServerboundSetCommandMinecart -> ++ nmsPacket = ServerboundSetCommandMinecartPacket.STREAM_CODEC.decode(buf); ++ case ServerboundSetCreativeModeSlot -> ++ nmsPacket = ServerboundSetCreativeModeSlotPacket.STREAM_CODEC.decode(buf); + case ServerboundSetJigsawBlock -> nmsPacket = ServerboundSetJigsawBlockPacket.STREAM_CODEC.decode(buf); -+ case ServerboundSetStructureBlock -> nmsPacket = ServerboundSetStructureBlockPacket.STREAM_CODEC.decode(buf); ++ case ServerboundSetStructureBlock -> ++ nmsPacket = ServerboundSetStructureBlockPacket.STREAM_CODEC.decode(buf); + case ServerboundSignUpdate -> nmsPacket = ServerboundSignUpdatePacket.STREAM_CODEC.decode(buf); + case ServerboundSwing -> nmsPacket = ServerboundSwingPacket.STREAM_CODEC.decode(buf); + case ServerboundTeleportToEntity -> nmsPacket = ServerboundTeleportToEntityPacket.STREAM_CODEC.decode(buf); @@ -355,16 +536,19 @@ index 0000000000000000000000000000000000000000..26179fcc836fcb8d1eda8ddb8a875cb9 + case ClientboundStoreCookie -> nmsPacket = ClientboundStoreCookiePacket.STREAM_CODEC.decode(buf); + case ClientboundTransfer -> nmsPacket = ClientboundTransferPacket.STREAM_CODEC.decode(buf); + case ClientboundUpdateTags -> nmsPacket = ClientboundUpdateTagsPacket.STREAM_CODEC.decode(buf); -+ case ServerboundClientInformation -> nmsPacket = ServerboundClientInformationPacket.STREAM_CODEC.decode(buf); ++ case ServerboundClientInformation -> ++ nmsPacket = ServerboundClientInformationPacket.STREAM_CODEC.decode(buf); + case ServerboundCustomPayload -> nmsPacket = ServerboundCustomPayloadPacket.STREAM_CODEC.decode(buf); + case ServerboundKeepAlive -> nmsPacket = ServerboundKeepAlivePacket.STREAM_CODEC.decode(buf); + case ServerboundPong -> nmsPacket = ServerboundPongPacket.STREAM_CODEC.decode(buf); + case ServerboundResourcePack -> nmsPacket = ServerboundResourcePackPacket.STREAM_CODEC.decode(buf); -+ default -> throw new UnsupportedOperationException("This feature is not completely finished yet, packet type " + type + " is not supported temporary."); ++ default -> ++ throw new UnsupportedOperationException("This feature is not completely finished yet, packet type " + type + " is not supported temporary."); + } + return nmsPacket; + } -+ private Packet createBytebufPacket(net.minecraft.network.protocol.Packet nmsPacket) { ++ ++ public Packet createBytebufPacket(net.minecraft.network.protocol.Packet nmsPacket) { + PacketType type; + RegistryFriendlyByteBuf buf = new RegistryFriendlyByteBuf(Unpooled.buffer(8192), MinecraftServer.getServer().registryAccess()); + switch (nmsPacket.type().toString()) { @@ -1073,72 +1257,3 @@ index 0000000000000000000000000000000000000000..26179fcc836fcb8d1eda8ddb8a875cb9 + return new Packet(type, Bytebuf.of(buf.array())); + } +} -diff --git a/src/main/java/org/leavesmc/leaves/bytebuf/WrappedBytebuf.java b/src/main/java/org/leavesmc/leaves/bytebuf/WrappedBytebuf.java -new file mode 100644 -index 0000000000000000000000000000000000000000..b53641dffbe6302dfb0e7e666b0e62a3cf94a70c ---- /dev/null -+++ b/src/main/java/org/leavesmc/leaves/bytebuf/WrappedBytebuf.java -@@ -0,0 +1,63 @@ -+package org.leavesmc.leaves.bytebuf; -+ -+import io.netty.buffer.ByteBuf; -+import net.minecraft.network.FriendlyByteBuf; -+ -+public class WrappedBytebuf implements Bytebuf { -+ private final FriendlyByteBuf buf; -+ public WrappedBytebuf(ByteBuf buf) { -+ this.buf = new FriendlyByteBuf(buf); -+ } -+ public FriendlyByteBuf getFriendlyBytebuf() { -+ return buf; -+ } -+ -+ @Override -+ public byte[] toArray() { -+ return buf.array(); -+ } -+ -+ @Override -+ public Bytebuf writeByte(int i) { -+ buf.writeByte(i); -+ return this; -+ } -+ -+ @Override -+ public byte readByte() { -+ return buf.readByte(); -+ } -+ -+ @Override -+ public Bytebuf writeShort(int i) { -+ buf.writeShort(i); -+ return this; -+ } -+ -+ @Override -+ public short readShort() { -+ return buf.readShort(); -+ } -+ -+ @Override -+ public Bytebuf writeInt(int i) { -+ buf.writeShort(i); -+ return this; -+ } -+ -+ @Override -+ public int readInt() { -+ return buf.readInt(); -+ } -+ -+ @Override -+ public Bytebuf writeLong(long i) { -+ buf.writeLong(i); -+ return this; -+ } -+ -+ @Override -+ public long readLong() { -+ return buf.readLong(); -+ } -+} From e8404fcecac251b4a205dc90ddd58b93f6ad391e Mon Sep 17 00:00:00 2001 From: Lumine1909 <133463833+Lumine1909@users.noreply.github.com> Date: Wed, 22 May 2024 17:42:34 -0400 Subject: [PATCH 4/9] fix reading change --- patches/server/0135-Bytebuf-API.patch | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/patches/server/0135-Bytebuf-API.patch b/patches/server/0135-Bytebuf-API.patch index 360af4b8..7f398b53 100644 --- a/patches/server/0135-Bytebuf-API.patch +++ b/patches/server/0135-Bytebuf-API.patch @@ -211,10 +211,10 @@ index 0000000000000000000000000000000000000000..39e53a092ffd7e3e04d529edb3468ba6 +} diff --git a/src/main/java/org/leavesmc/leaves/bytebuf/internal/InternalBytebufHandler.java b/src/main/java/org/leavesmc/leaves/bytebuf/internal/InternalBytebufHandler.java new file mode 100644 -index 0000000000000000000000000000000000000000..1dff2f33d0c55c286a8f71652f086d5a2fab471c +index 0000000000000000000000000000000000000000..902714e071a66a126d9601072945783111018114 --- /dev/null +++ b/src/main/java/org/leavesmc/leaves/bytebuf/internal/InternalBytebufHandler.java -@@ -0,0 +1,1042 @@ +@@ -0,0 +1,1044 @@ +package org.leavesmc.leaves.bytebuf.internal; + +import io.netty.buffer.Unpooled; @@ -308,6 +308,7 @@ index 0000000000000000000000000000000000000000..1dff2f33d0c55c286a8f71652f086d5a + listenerMap.remove(listener); + } + } ++ packet.bytebuf().readerIndex(0).writerIndex(0); + return createNMSPacket(packet); + } + @@ -319,6 +320,7 @@ index 0000000000000000000000000000000000000000..1dff2f33d0c55c286a8f71652f086d5a + listenerMap.remove(listener); + } + } ++ packet.bytebuf().readerIndex(0).writerIndex(0); + return createNMSPacket(packet); + } + From 97334cf8f5c96e20b8afb4abc61dad6518cc0dfd Mon Sep 17 00:00:00 2001 From: Lumine1909 <133463833+Lumine1909@users.noreply.github.com> Date: Wed, 22 May 2024 17:49:30 -0400 Subject: [PATCH 5/9] fix --- patches/server/0135-Bytebuf-API.patch | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/patches/server/0135-Bytebuf-API.patch b/patches/server/0135-Bytebuf-API.patch index 7f398b53..576e2f29 100644 --- a/patches/server/0135-Bytebuf-API.patch +++ b/patches/server/0135-Bytebuf-API.patch @@ -211,7 +211,7 @@ index 0000000000000000000000000000000000000000..39e53a092ffd7e3e04d529edb3468ba6 +} diff --git a/src/main/java/org/leavesmc/leaves/bytebuf/internal/InternalBytebufHandler.java b/src/main/java/org/leavesmc/leaves/bytebuf/internal/InternalBytebufHandler.java new file mode 100644 -index 0000000000000000000000000000000000000000..902714e071a66a126d9601072945783111018114 +index 0000000000000000000000000000000000000000..59aa425f9fec68b614077eb2f7013ee0a40da95f --- /dev/null +++ b/src/main/java/org/leavesmc/leaves/bytebuf/internal/InternalBytebufHandler.java @@ -0,0 +1,1044 @@ @@ -308,7 +308,7 @@ index 0000000000000000000000000000000000000000..902714e071a66a126d96010729457831 + listenerMap.remove(listener); + } + } -+ packet.bytebuf().readerIndex(0).writerIndex(0); ++ packet.bytebuf().writerIndex(0).readerIndex(0); + return createNMSPacket(packet); + } + @@ -320,7 +320,7 @@ index 0000000000000000000000000000000000000000..902714e071a66a126d96010729457831 + listenerMap.remove(listener); + } + } -+ packet.bytebuf().readerIndex(0).writerIndex(0); ++ packet.bytebuf().writerIndex(0).readerIndex(0); + return createNMSPacket(packet); + } + From e39875115a12e5fccdcecf7213912a704bd6154d Mon Sep 17 00:00:00 2001 From: Lumine1909 <133463833+Lumine1909@users.noreply.github.com> Date: Wed, 22 May 2024 18:12:26 -0400 Subject: [PATCH 6/9] fix --- patches/api/0011-Bytebuf-API.patch | 6 ++++-- patches/server/0135-Bytebuf-API.patch | 22 +++++++++++++++++----- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/patches/api/0011-Bytebuf-API.patch b/patches/api/0011-Bytebuf-API.patch index 44dc6140..781e85b4 100644 --- a/patches/api/0011-Bytebuf-API.patch +++ b/patches/api/0011-Bytebuf-API.patch @@ -50,10 +50,10 @@ index 6c327a07bf8a6aa11a2d7dad12b2830acc539484..939bdc02b917ad72a8b7e6640067da19 Spigot spigot(); diff --git a/src/main/java/org/leavesmc/leaves/bytebuf/Bytebuf.java b/src/main/java/org/leavesmc/leaves/bytebuf/Bytebuf.java new file mode 100644 -index 0000000000000000000000000000000000000000..e01174a95bec27a5ca808dbc976a97a373577a3b +index 0000000000000000000000000000000000000000..aafb63823c29129bdffc8421e0800aa8e2065a31 --- /dev/null +++ b/src/main/java/org/leavesmc/leaves/bytebuf/Bytebuf.java -@@ -0,0 +1,32 @@ +@@ -0,0 +1,34 @@ +package org.leavesmc.leaves.bytebuf; + +import org.bukkit.Bukkit; @@ -75,6 +75,8 @@ index 0000000000000000000000000000000000000000..e01174a95bec27a5ca808dbc976a97a3 + Bytebuf readerIndex(int i); + int writerIndex(); + Bytebuf writerIndex(int i); ++ Bytebuf resetReaderIndex(); ++ Bytebuf resetWriterIndex(); + Bytebuf writeByte(int i); + byte readByte(); + Bytebuf writeShort(int i); diff --git a/patches/server/0135-Bytebuf-API.patch b/patches/server/0135-Bytebuf-API.patch index 576e2f29..bd39523c 100644 --- a/patches/server/0135-Bytebuf-API.patch +++ b/patches/server/0135-Bytebuf-API.patch @@ -101,10 +101,10 @@ index 0000000000000000000000000000000000000000..854af9da6e27e037e022abfef241221e +} diff --git a/src/main/java/org/leavesmc/leaves/bytebuf/WrappedBytebuf.java b/src/main/java/org/leavesmc/leaves/bytebuf/WrappedBytebuf.java new file mode 100644 -index 0000000000000000000000000000000000000000..39e53a092ffd7e3e04d529edb3468ba614373165 +index 0000000000000000000000000000000000000000..98c501ce88d45ad688a44652e7e4e69a05ab9a71 --- /dev/null +++ b/src/main/java/org/leavesmc/leaves/bytebuf/WrappedBytebuf.java -@@ -0,0 +1,104 @@ +@@ -0,0 +1,116 @@ +package org.leavesmc.leaves.bytebuf; + +import io.netty.buffer.ByteBuf; @@ -155,6 +155,18 @@ index 0000000000000000000000000000000000000000..39e53a092ffd7e3e04d529edb3468ba6 + } + + @Override ++ public Bytebuf resetReaderIndex() { ++ buf.resetReaderIndex(); ++ return this; ++ } ++ ++ @Override ++ public Bytebuf resetWriterIndex() { ++ buf.resetWriterIndex(); ++ return this; ++ } ++ ++ @Override + public Bytebuf writeByte(int i) { + buf.writeByte(i); + return this; @@ -211,7 +223,7 @@ index 0000000000000000000000000000000000000000..39e53a092ffd7e3e04d529edb3468ba6 +} diff --git a/src/main/java/org/leavesmc/leaves/bytebuf/internal/InternalBytebufHandler.java b/src/main/java/org/leavesmc/leaves/bytebuf/internal/InternalBytebufHandler.java new file mode 100644 -index 0000000000000000000000000000000000000000..59aa425f9fec68b614077eb2f7013ee0a40da95f +index 0000000000000000000000000000000000000000..6e1d8d29436d813a3a75de17c467c4fb1cfceec5 --- /dev/null +++ b/src/main/java/org/leavesmc/leaves/bytebuf/internal/InternalBytebufHandler.java @@ -0,0 +1,1044 @@ @@ -304,11 +316,11 @@ index 0000000000000000000000000000000000000000..59aa425f9fec68b614077eb2f7013ee0 + for (PacketListener listener : listenerMap.keySet()) { + if (listenerMap.get(listener).isEnabled()) { + packet = listener.onPacketIn(player, packet); ++ packet.bytebuf().resetReaderIndex(); + } else { + listenerMap.remove(listener); + } + } -+ packet.bytebuf().writerIndex(0).readerIndex(0); + return createNMSPacket(packet); + } + @@ -316,11 +328,11 @@ index 0000000000000000000000000000000000000000..59aa425f9fec68b614077eb2f7013ee0 + for (PacketListener listener : listenerMap.keySet()) { + if (listenerMap.get(listener).isEnabled()) { + packet = listener.onPacketOut(player, packet); ++ packet.bytebuf().resetReaderIndex(); + } else { + listenerMap.remove(listener); + } + } -+ packet.bytebuf().writerIndex(0).readerIndex(0); + return createNMSPacket(packet); + } + From 7107161ad36a9409b85e3aa4364d7bbce072d34d Mon Sep 17 00:00:00 2001 From: Lumine1909 <133463833+Lumine1909@users.noreply.github.com> Date: Thu, 23 May 2024 00:53:11 -0400 Subject: [PATCH 7/9] maybe better now? --- patches/api/0011-Bytebuf-API.patch | 38 ++++++-- patches/server/0135-Bytebuf-API.patch | 134 ++++++++++---------------- 2 files changed, 82 insertions(+), 90 deletions(-) diff --git a/patches/api/0011-Bytebuf-API.patch b/patches/api/0011-Bytebuf-API.patch index 781e85b4..57da8bd7 100644 --- a/patches/api/0011-Bytebuf-API.patch +++ b/patches/api/0011-Bytebuf-API.patch @@ -50,59 +50,83 @@ index 6c327a07bf8a6aa11a2d7dad12b2830acc539484..939bdc02b917ad72a8b7e6640067da19 Spigot spigot(); diff --git a/src/main/java/org/leavesmc/leaves/bytebuf/Bytebuf.java b/src/main/java/org/leavesmc/leaves/bytebuf/Bytebuf.java new file mode 100644 -index 0000000000000000000000000000000000000000..aafb63823c29129bdffc8421e0800aa8e2065a31 +index 0000000000000000000000000000000000000000..8e0b7e132ea1cec7776a23ecbf6d1feef9f2eaf5 --- /dev/null +++ b/src/main/java/org/leavesmc/leaves/bytebuf/Bytebuf.java -@@ -0,0 +1,34 @@ +@@ -0,0 +1,54 @@ +package org.leavesmc.leaves.bytebuf; + +import org.bukkit.Bukkit; + +public interface Bytebuf { ++ + static Bytebuf buf(int size) { + return Bukkit.getBytebufManager().newBytebuf(size); + } ++ + static Bytebuf buf() { + return buf(128); + } ++ + static Bytebuf of(byte[] bytes) { + return Bukkit.getBytebufManager().toBytebuf(bytes); + } ++ + byte[] toArray(); + + Bytebuf skipBytes(int i); ++ + int readerIndex(); ++ + Bytebuf readerIndex(int i); ++ + int writerIndex(); ++ + Bytebuf writerIndex(int i); ++ + Bytebuf resetReaderIndex(); ++ + Bytebuf resetWriterIndex(); ++ + Bytebuf writeByte(int i); ++ + byte readByte(); ++ + Bytebuf writeShort(int i); ++ + short readShort(); ++ + Bytebuf writeInt(int i); ++ + int readInt(); ++ + Bytebuf writeLong(long i); ++ + long readLong(); ++ + Bytebuf writeUTFString(String utf); ++ + String readUTFString(); +} diff --git a/src/main/java/org/leavesmc/leaves/bytebuf/BytebufManager.java b/src/main/java/org/leavesmc/leaves/bytebuf/BytebufManager.java new file mode 100644 -index 0000000000000000000000000000000000000000..b0c759b3ea19ca10be56b232181e56d056cf3a2d +index 0000000000000000000000000000000000000000..8668e47dee7a23d7843efc4a9752919f7a1dce88 --- /dev/null +++ b/src/main/java/org/leavesmc/leaves/bytebuf/BytebufManager.java -@@ -0,0 +1,11 @@ +@@ -0,0 +1,15 @@ +package org.leavesmc.leaves.bytebuf; + +import org.bukkit.plugin.Plugin; +import org.leavesmc.leaves.bytebuf.packet.PacketListener; + +public interface BytebufManager { ++ + void registerListener(Plugin plugin, PacketListener listener); ++ + void unregisterListener(Plugin plugin, PacketListener listener); ++ + Bytebuf newBytebuf(int size); ++ + Bytebuf toBytebuf(byte[] bytes); +} diff --git a/src/main/java/org/leavesmc/leaves/bytebuf/packet/Packet.java b/src/main/java/org/leavesmc/leaves/bytebuf/packet/Packet.java @@ -119,16 +143,18 @@ index 0000000000000000000000000000000000000000..8bb00c16fe3e6089397cc0fcaaec4715 +} diff --git a/src/main/java/org/leavesmc/leaves/bytebuf/packet/PacketListener.java b/src/main/java/org/leavesmc/leaves/bytebuf/packet/PacketListener.java new file mode 100644 -index 0000000000000000000000000000000000000000..3a8cb462287498a8b1959f31261ebbca74b62ef5 +index 0000000000000000000000000000000000000000..e246c0a8725fa3b2be065433652a19a565c7205c --- /dev/null +++ b/src/main/java/org/leavesmc/leaves/bytebuf/packet/PacketListener.java -@@ -0,0 +1,8 @@ +@@ -0,0 +1,10 @@ +package org.leavesmc.leaves.bytebuf.packet; + +import org.bukkit.entity.Player; + +public interface PacketListener { ++ + Packet onPacketIn(Player player, Packet packet); ++ + Packet onPacketOut(Player player, Packet packet); +} diff --git a/src/main/java/org/leavesmc/leaves/bytebuf/packet/PacketType.java b/src/main/java/org/leavesmc/leaves/bytebuf/packet/PacketType.java diff --git a/patches/server/0135-Bytebuf-API.patch b/patches/server/0135-Bytebuf-API.patch index bd39523c..8622d6d9 100644 --- a/patches/server/0135-Bytebuf-API.patch +++ b/patches/server/0135-Bytebuf-API.patch @@ -64,10 +64,10 @@ index 25a5ce110c0515f5a0ee5f287a7f3dd029a8f29f..1eb60f1d9bec4b11bb1d0242266d6e08 } diff --git a/src/main/java/org/leavesmc/leaves/bytebuf/SimpleBytebufManager.java b/src/main/java/org/leavesmc/leaves/bytebuf/SimpleBytebufManager.java new file mode 100644 -index 0000000000000000000000000000000000000000..854af9da6e27e037e022abfef241221ef1c75d0d +index 0000000000000000000000000000000000000000..443f7f6e0b8d40eaafb8009b3b7e405c6ec78d02 --- /dev/null +++ b/src/main/java/org/leavesmc/leaves/bytebuf/SimpleBytebufManager.java -@@ -0,0 +1,31 @@ +@@ -0,0 +1,35 @@ +package org.leavesmc.leaves.bytebuf; + +import io.netty.buffer.Unpooled; @@ -76,10 +76,13 @@ index 0000000000000000000000000000000000000000..854af9da6e27e037e022abfef241221e +import org.leavesmc.leaves.bytebuf.packet.PacketListener; + +public class SimpleBytebufManager implements BytebufManager { ++ + private final InternalBytebufHandler internal; ++ + public SimpleBytebufManager(InternalBytebufHandler internal) { + this.internal = internal; + } ++ + @Override + public void registerListener(Plugin plugin, PacketListener listener) { + internal.listenerMap.put(listener, plugin); @@ -89,6 +92,7 @@ index 0000000000000000000000000000000000000000..854af9da6e27e037e022abfef241221e + public void unregisterListener(Plugin plugin, PacketListener listener) { + internal.listenerMap.remove(listener); + } ++ + @Override + public Bytebuf newBytebuf(int size) { + return new WrappedBytebuf(Unpooled.buffer(size)); @@ -101,16 +105,17 @@ index 0000000000000000000000000000000000000000..854af9da6e27e037e022abfef241221e +} diff --git a/src/main/java/org/leavesmc/leaves/bytebuf/WrappedBytebuf.java b/src/main/java/org/leavesmc/leaves/bytebuf/WrappedBytebuf.java new file mode 100644 -index 0000000000000000000000000000000000000000..98c501ce88d45ad688a44652e7e4e69a05ab9a71 +index 0000000000000000000000000000000000000000..399b212fa20594ec8bb3f686d0cdc3ceb7dd2cfe --- /dev/null +++ b/src/main/java/org/leavesmc/leaves/bytebuf/WrappedBytebuf.java -@@ -0,0 +1,116 @@ +@@ -0,0 +1,117 @@ +package org.leavesmc.leaves.bytebuf; + +import io.netty.buffer.ByteBuf; +import net.minecraft.network.FriendlyByteBuf; + +public class WrappedBytebuf implements Bytebuf { ++ + private final FriendlyByteBuf buf; + + public WrappedBytebuf(ByteBuf buf) { @@ -223,10 +228,10 @@ index 0000000000000000000000000000000000000000..98c501ce88d45ad688a44652e7e4e69a +} diff --git a/src/main/java/org/leavesmc/leaves/bytebuf/internal/InternalBytebufHandler.java b/src/main/java/org/leavesmc/leaves/bytebuf/internal/InternalBytebufHandler.java new file mode 100644 -index 0000000000000000000000000000000000000000..6e1d8d29436d813a3a75de17c467c4fb1cfceec5 +index 0000000000000000000000000000000000000000..fdeec0625275862b289c7c59aaef11facc76dce7 --- /dev/null +++ b/src/main/java/org/leavesmc/leaves/bytebuf/internal/InternalBytebufHandler.java -@@ -0,0 +1,1044 @@ +@@ -0,0 +1,1005 @@ +package org.leavesmc.leaves.bytebuf.internal; + +import io.netty.buffer.Unpooled; @@ -258,6 +263,7 @@ index 0000000000000000000000000000000000000000..6e1d8d29436d813a3a75de17c467c4fb +public class InternalBytebufHandler { + + class PacketHandler extends ChannelDuplexHandler { ++ + private final static String handlerName = "leaves-bytebuf-handler"; + private final Player player; + @@ -297,13 +303,11 @@ index 0000000000000000000000000000000000000000..6e1d8d29436d813a3a75de17c467c4fb + super.write(ctx, msg, promise); + } + } -+ + } + + public final Map listenerMap = new HashMap<>(); + private final BytebufManager manager = new SimpleBytebufManager(this); + -+ + public void injectPlayer(ServerPlayer player) { + player.connection.connection.channel.pipeline().addBefore("packet_handler", PacketHandler.handlerName, new PacketHandler(player.getBukkitEntity())); + } @@ -357,22 +361,18 @@ index 0000000000000000000000000000000000000000..6e1d8d29436d813a3a75de17c467c4fb + case ClientboundBlockUpdate -> nmsPacket = ClientboundBlockUpdatePacket.STREAM_CODEC.decode(buf); + case ClientboundBossEvent -> nmsPacket = ClientboundBossEventPacket.STREAM_CODEC.decode(buf); + case ClientboundChangeDifficulty -> nmsPacket = ClientboundChangeDifficultyPacket.STREAM_CODEC.decode(buf); -+ case ClientboundChunkBatchFinished -> -+ nmsPacket = ClientboundChunkBatchFinishedPacket.STREAM_CODEC.decode(buf); ++ case ClientboundChunkBatchFinished -> nmsPacket = ClientboundChunkBatchFinishedPacket.STREAM_CODEC.decode(buf); + case ClientboundChunkBatchStart -> nmsPacket = ClientboundChunkBatchStartPacket.STREAM_CODEC.decode(buf); + case ClientboundChunksBiomes -> nmsPacket = ClientboundChunksBiomesPacket.STREAM_CODEC.decode(buf); + case ClientboundClearTitles -> nmsPacket = ClientboundClearTitlesPacket.STREAM_CODEC.decode(buf); -+ case ClientboundCommandSuggestions -> -+ nmsPacket = ClientboundCommandSuggestionsPacket.STREAM_CODEC.decode(buf); ++ case ClientboundCommandSuggestions -> nmsPacket = ClientboundCommandSuggestionsPacket.STREAM_CODEC.decode(buf); + case ClientboundCommands -> nmsPacket = ClientboundCommandsPacket.STREAM_CODEC.decode(buf); + case ClientboundContainerClose -> nmsPacket = ClientboundContainerClosePacket.STREAM_CODEC.decode(buf); -+ case ClientboundContainerSetContent -> -+ nmsPacket = ClientboundContainerSetContentPacket.STREAM_CODEC.decode(buf); ++ case ClientboundContainerSetContent -> nmsPacket = ClientboundContainerSetContentPacket.STREAM_CODEC.decode(buf); + case ClientboundContainerSetData -> nmsPacket = ClientboundContainerSetDataPacket.STREAM_CODEC.decode(buf); + case ClientboundContainerSetSlot -> nmsPacket = ClientboundContainerSetSlotPacket.STREAM_CODEC.decode(buf); + case ClientboundCooldown -> nmsPacket = ClientboundCooldownPacket.STREAM_CODEC.decode(buf); -+ case ClientboundCustomChatCompletions -> -+ nmsPacket = ClientboundCustomChatCompletionsPacket.STREAM_CODEC.decode(buf); ++ case ClientboundCustomChatCompletions -> nmsPacket = ClientboundCustomChatCompletionsPacket.STREAM_CODEC.decode(buf); + case ClientboundDamageEvent -> nmsPacket = ClientboundDamageEventPacket.STREAM_CODEC.decode(buf); + case ClientboundDebugSample -> nmsPacket = ClientboundDebugSamplePacket.STREAM_CODEC.decode(buf); + case ClientboundDeleteChat -> nmsPacket = ClientboundDeleteChatPacket.STREAM_CODEC.decode(buf); @@ -384,8 +384,7 @@ index 0000000000000000000000000000000000000000..6e1d8d29436d813a3a75de17c467c4fb + case ClientboundHorseScreenOpen -> nmsPacket = ClientboundHorseScreenOpenPacket.STREAM_CODEC.decode(buf); + case ClientboundHurtAnimation -> nmsPacket = ClientboundHurtAnimationPacket.STREAM_CODEC.decode(buf); + case ClientboundInitializeBorder -> nmsPacket = ClientboundInitializeBorderPacket.STREAM_CODEC.decode(buf); -+ case ClientboundLevelChunkWithLight -> -+ nmsPacket = ClientboundLevelChunkWithLightPacket.STREAM_CODEC.decode(buf); ++ case ClientboundLevelChunkWithLight -> nmsPacket = ClientboundLevelChunkWithLightPacket.STREAM_CODEC.decode(buf); + case ClientboundLevelEvent -> nmsPacket = ClientboundLevelEventPacket.STREAM_CODEC.decode(buf); + case ClientboundLevelParticles -> nmsPacket = ClientboundLevelParticlesPacket.STREAM_CODEC.decode(buf); + case ClientboundLightUpdate -> nmsPacket = ClientboundLightUpdatePacket.STREAM_CODEC.decode(buf); @@ -403,8 +402,7 @@ index 0000000000000000000000000000000000000000..6e1d8d29436d813a3a75de17c467c4fb + case ClientboundPlayerAbilities -> nmsPacket = ClientboundPlayerAbilitiesPacket.STREAM_CODEC.decode(buf); + case ClientboundPlayerChat -> nmsPacket = ClientboundPlayerChatPacket.STREAM_CODEC.decode(buf); + case ClientboundPlayerCombatEnd -> nmsPacket = ClientboundPlayerCombatEndPacket.STREAM_CODEC.decode(buf); -+ case ClientboundPlayerCombatEnter -> -+ nmsPacket = ClientboundPlayerCombatEnterPacket.STREAM_CODEC.decode(buf); ++ case ClientboundPlayerCombatEnter -> nmsPacket = ClientboundPlayerCombatEnterPacket.STREAM_CODEC.decode(buf); + case ClientboundPlayerCombatKill -> nmsPacket = ClientboundPlayerCombatKillPacket.STREAM_CODEC.decode(buf); + case ClientboundPlayerInfoRemove -> nmsPacket = ClientboundPlayerInfoRemovePacket.STREAM_CODEC.decode(buf); + case ClientboundPlayerInfoUpdate -> nmsPacket = ClientboundPlayerInfoUpdatePacket.STREAM_CODEC.decode(buf); @@ -415,30 +413,21 @@ index 0000000000000000000000000000000000000000..6e1d8d29436d813a3a75de17c467c4fb + case ClientboundRemoveMobEffect -> nmsPacket = ClientboundRemoveMobEffectPacket.STREAM_CODEC.decode(buf); + case ClientboundRespawn -> nmsPacket = ClientboundRespawnPacket.STREAM_CODEC.decode(buf); + case ClientboundRotateHead -> nmsPacket = ClientboundRotateHeadPacket.STREAM_CODEC.decode(buf); -+ case ClientboundSectionBlocksUpdate -> -+ nmsPacket = ClientboundSectionBlocksUpdatePacket.STREAM_CODEC.decode(buf); -+ case ClientboundSelectAdvancementsTab -> -+ nmsPacket = ClientboundSelectAdvancementsTabPacket.STREAM_CODEC.decode(buf); ++ case ClientboundSectionBlocksUpdate -> nmsPacket = ClientboundSectionBlocksUpdatePacket.STREAM_CODEC.decode(buf); ++ case ClientboundSelectAdvancementsTab -> nmsPacket = ClientboundSelectAdvancementsTabPacket.STREAM_CODEC.decode(buf); + case ClientboundServerData -> nmsPacket = ClientboundServerDataPacket.STREAM_CODEC.decode(buf); + case ClientboundSetActionBarText -> nmsPacket = ClientboundSetActionBarTextPacket.STREAM_CODEC.decode(buf); + case ClientboundSetBorderCenter -> nmsPacket = ClientboundSetBorderCenterPacket.STREAM_CODEC.decode(buf); -+ case ClientboundSetBorderLerpSize -> -+ nmsPacket = ClientboundSetBorderLerpSizePacket.STREAM_CODEC.decode(buf); ++ case ClientboundSetBorderLerpSize -> nmsPacket = ClientboundSetBorderLerpSizePacket.STREAM_CODEC.decode(buf); + case ClientboundSetBorderSize -> nmsPacket = ClientboundSetBorderSizePacket.STREAM_CODEC.decode(buf); -+ case ClientboundSetBorderWarningDelay -> -+ nmsPacket = ClientboundSetBorderWarningDelayPacket.STREAM_CODEC.decode(buf); -+ case ClientboundSetBorderWarningDistance -> -+ nmsPacket = ClientboundSetBorderWarningDistancePacket.STREAM_CODEC.decode(buf); ++ case ClientboundSetBorderWarningDelay -> nmsPacket = ClientboundSetBorderWarningDelayPacket.STREAM_CODEC.decode(buf); ++ case ClientboundSetBorderWarningDistance -> nmsPacket = ClientboundSetBorderWarningDistancePacket.STREAM_CODEC.decode(buf); + case ClientboundSetCamera -> nmsPacket = ClientboundSetCameraPacket.STREAM_CODEC.decode(buf); + case ClientboundSetCarriedItem -> nmsPacket = ClientboundSetCarriedItemPacket.STREAM_CODEC.decode(buf); -+ case ClientboundSetChunkCacheCenter -> -+ nmsPacket = ClientboundSetChunkCacheCenterPacket.STREAM_CODEC.decode(buf); -+ case ClientboundSetChunkCacheRadius -> -+ nmsPacket = ClientboundSetChunkCacheRadiusPacket.STREAM_CODEC.decode(buf); -+ case ClientboundSetDefaultSpawnPosition -> -+ nmsPacket = ClientboundSetDefaultSpawnPositionPacket.STREAM_CODEC.decode(buf); -+ case ClientboundSetDisplayObjective -> -+ nmsPacket = ClientboundSetDisplayObjectivePacket.STREAM_CODEC.decode(buf); ++ case ClientboundSetChunkCacheCenter -> nmsPacket = ClientboundSetChunkCacheCenterPacket.STREAM_CODEC.decode(buf); ++ case ClientboundSetChunkCacheRadius -> nmsPacket = ClientboundSetChunkCacheRadiusPacket.STREAM_CODEC.decode(buf); ++ case ClientboundSetDefaultSpawnPosition -> nmsPacket = ClientboundSetDefaultSpawnPositionPacket.STREAM_CODEC.decode(buf); ++ case ClientboundSetDisplayObjective -> nmsPacket = ClientboundSetDisplayObjectivePacket.STREAM_CODEC.decode(buf); + case ClientboundSetEntityData -> nmsPacket = ClientboundSetEntityDataPacket.STREAM_CODEC.decode(buf); + case ClientboundSetEntityLink -> nmsPacket = ClientboundSetEntityLinkPacket.STREAM_CODEC.decode(buf); + case ClientboundSetEntityMotion -> nmsPacket = ClientboundSetEntityMotionPacket.STREAM_CODEC.decode(buf); @@ -449,56 +438,42 @@ index 0000000000000000000000000000000000000000..6e1d8d29436d813a3a75de17c467c4fb + case ClientboundSetPassengers -> nmsPacket = ClientboundSetPassengersPacket.STREAM_CODEC.decode(buf); + case ClientboundSetPlayerTeam -> nmsPacket = ClientboundSetPlayerTeamPacket.STREAM_CODEC.decode(buf); + case ClientboundSetScore -> nmsPacket = ClientboundSetScorePacket.STREAM_CODEC.decode(buf); -+ case ClientboundSetSimulationDistance -> -+ nmsPacket = ClientboundSetSimulationDistancePacket.STREAM_CODEC.decode(buf); ++ case ClientboundSetSimulationDistance -> nmsPacket = ClientboundSetSimulationDistancePacket.STREAM_CODEC.decode(buf); + case ClientboundSetSubtitleText -> nmsPacket = ClientboundSetSubtitleTextPacket.STREAM_CODEC.decode(buf); + case ClientboundSetTime -> nmsPacket = ClientboundSetTimePacket.STREAM_CODEC.decode(buf); + case ClientboundSetTitleText -> nmsPacket = ClientboundSetTitleTextPacket.STREAM_CODEC.decode(buf); -+ case ClientboundSetTitlesAnimation -> -+ nmsPacket = ClientboundSetTitlesAnimationPacket.STREAM_CODEC.decode(buf); ++ case ClientboundSetTitlesAnimation -> nmsPacket = ClientboundSetTitlesAnimationPacket.STREAM_CODEC.decode(buf); + case ClientboundSoundEntity -> nmsPacket = ClientboundSoundEntityPacket.STREAM_CODEC.decode(buf); + case ClientboundSound -> nmsPacket = ClientboundSoundPacket.STREAM_CODEC.decode(buf); -+ case ClientboundStartConfiguration -> -+ nmsPacket = ClientboundStartConfigurationPacket.STREAM_CODEC.decode(buf); ++ case ClientboundStartConfiguration -> nmsPacket = ClientboundStartConfigurationPacket.STREAM_CODEC.decode(buf); + case ClientboundStopSound -> nmsPacket = ClientboundStopSoundPacket.STREAM_CODEC.decode(buf); + case ClientboundSystemChat -> nmsPacket = ClientboundSystemChatPacket.STREAM_CODEC.decode(buf); + case ClientboundTabList -> nmsPacket = ClientboundTabListPacket.STREAM_CODEC.decode(buf); + case ClientboundTagQuery -> nmsPacket = ClientboundTagQueryPacket.STREAM_CODEC.decode(buf); + case ClientboundTakeItemEntity -> nmsPacket = ClientboundTakeItemEntityPacket.STREAM_CODEC.decode(buf); + case ClientboundTeleportEntity -> nmsPacket = ClientboundTeleportEntityPacket.STREAM_CODEC.decode(buf); -+ case ClientboundUpdateAdvancements -> -+ nmsPacket = ClientboundUpdateAdvancementsPacket.STREAM_CODEC.decode(buf); ++ case ClientboundUpdateAdvancements -> nmsPacket = ClientboundUpdateAdvancementsPacket.STREAM_CODEC.decode(buf); + case ClientboundUpdateAttributes -> nmsPacket = ClientboundUpdateAttributesPacket.STREAM_CODEC.decode(buf); + case ClientboundUpdateMobEffect -> nmsPacket = ClientboundUpdateMobEffectPacket.STREAM_CODEC.decode(buf); + case ClientboundUpdateRecipes -> nmsPacket = ClientboundUpdateRecipesPacket.STREAM_CODEC.decode(buf); + case ClientboundProjectilePower -> nmsPacket = ClientboundProjectilePowerPacket.STREAM_CODEC.decode(buf); -+ case ServerboundAcceptTeleportation -> -+ nmsPacket = ServerboundAcceptTeleportationPacket.STREAM_CODEC.decode(buf); -+ case ServerboundBlockEntityTagQuery -> -+ nmsPacket = ServerboundBlockEntityTagQueryPacket.STREAM_CODEC.decode(buf); ++ case ServerboundAcceptTeleportation -> nmsPacket = ServerboundAcceptTeleportationPacket.STREAM_CODEC.decode(buf); ++ case ServerboundBlockEntityTagQuery -> nmsPacket = ServerboundBlockEntityTagQueryPacket.STREAM_CODEC.decode(buf); + case ServerboundChangeDifficulty -> nmsPacket = ServerboundChangeDifficultyPacket.STREAM_CODEC.decode(buf); + case ServerboundChatAck -> nmsPacket = ServerboundChatAckPacket.STREAM_CODEC.decode(buf); + case ServerboundChatCommand -> nmsPacket = ServerboundChatCommandPacket.STREAM_CODEC.decode(buf); -+ case ServerboundChatCommandSigned -> -+ nmsPacket = ServerboundChatCommandSignedPacket.STREAM_CODEC.decode(buf); ++ case ServerboundChatCommandSigned -> nmsPacket = ServerboundChatCommandSignedPacket.STREAM_CODEC.decode(buf); + case ServerboundChat -> nmsPacket = ServerboundChatPacket.STREAM_CODEC.decode(buf); -+ case ServerboundChatSessionUpdate -> -+ nmsPacket = ServerboundChatSessionUpdatePacket.STREAM_CODEC.decode(buf); -+ case ServerboundChunkBatchReceived -> -+ nmsPacket = ServerboundChunkBatchReceivedPacket.STREAM_CODEC.decode(buf); ++ case ServerboundChatSessionUpdate -> nmsPacket = ServerboundChatSessionUpdatePacket.STREAM_CODEC.decode(buf); ++ case ServerboundChunkBatchReceived -> nmsPacket = ServerboundChunkBatchReceivedPacket.STREAM_CODEC.decode(buf); + case ServerboundClientCommand -> nmsPacket = ServerboundClientCommandPacket.STREAM_CODEC.decode(buf); -+ case ServerboundCommandSuggestion -> -+ nmsPacket = ServerboundCommandSuggestionPacket.STREAM_CODEC.decode(buf); -+ case ServerboundConfigurationAcknowledged -> -+ nmsPacket = ServerboundConfigurationAcknowledgedPacket.STREAM_CODEC.decode(buf); -+ case ServerboundContainerButtonClick -> -+ nmsPacket = ServerboundContainerButtonClickPacket.STREAM_CODEC.decode(buf); ++ case ServerboundCommandSuggestion -> nmsPacket = ServerboundCommandSuggestionPacket.STREAM_CODEC.decode(buf); ++ case ServerboundConfigurationAcknowledged -> nmsPacket = ServerboundConfigurationAcknowledgedPacket.STREAM_CODEC.decode(buf); ++ case ServerboundContainerButtonClick -> nmsPacket = ServerboundContainerButtonClickPacket.STREAM_CODEC.decode(buf); + case ServerboundContainerClick -> nmsPacket = ServerboundContainerClickPacket.STREAM_CODEC.decode(buf); + case ServerboundContainerClose -> nmsPacket = ServerboundContainerClosePacket.STREAM_CODEC.decode(buf); -+ case ServerboundContainerSlotStateChanged -> -+ nmsPacket = ServerboundContainerSlotStateChangedPacket.STREAM_CODEC.decode(buf); -+ case ServerboundDebugSampleSubscription -> -+ nmsPacket = ServerboundDebugSampleSubscriptionPacket.STREAM_CODEC.decode(buf); ++ case ServerboundContainerSlotStateChanged -> nmsPacket = ServerboundContainerSlotStateChangedPacket.STREAM_CODEC.decode(buf); ++ case ServerboundDebugSampleSubscription -> nmsPacket = ServerboundDebugSampleSubscriptionPacket.STREAM_CODEC.decode(buf); + case ServerboundEditBook -> nmsPacket = ServerboundEditBookPacket.STREAM_CODEC.decode(buf); + case ServerboundEntityTagQuery -> nmsPacket = ServerboundEntityTagQueryPacket.STREAM_CODEC.decode(buf); + case ServerboundInteract -> nmsPacket = ServerboundInteractPacket.STREAM_CODEC.decode(buf); @@ -507,8 +482,7 @@ index 0000000000000000000000000000000000000000..6e1d8d29436d813a3a75de17c467c4fb + case ServerboundMovePlayerPos -> nmsPacket = ServerboundMovePlayerPacket.Pos.STREAM_CODEC.decode(buf); + case ServerboundMovePlayerPosRot -> nmsPacket = ServerboundMovePlayerPacket.PosRot.STREAM_CODEC.decode(buf); + case ServerboundMovePlayerRot -> nmsPacket = ServerboundMovePlayerPacket.Rot.STREAM_CODEC.decode(buf); -+ case ServerboundMovePlayerStatusOnly -> -+ nmsPacket = ServerboundMovePlayerPacket.StatusOnly.STREAM_CODEC.decode(buf); ++ case ServerboundMovePlayerStatusOnly -> nmsPacket = ServerboundMovePlayerPacket.StatusOnly.STREAM_CODEC.decode(buf); + case ServerboundMoveVehicle -> nmsPacket = ServerboundMoveVehiclePacket.STREAM_CODEC.decode(buf); + case ServerboundPaddleBoat -> nmsPacket = ServerboundPaddleBoatPacket.STREAM_CODEC.decode(buf); + case ServerboundPickItem -> nmsPacket = ServerboundPickItemPacket.STREAM_CODEC.decode(buf); @@ -517,23 +491,18 @@ index 0000000000000000000000000000000000000000..6e1d8d29436d813a3a75de17c467c4fb + case ServerboundPlayerAction -> nmsPacket = ServerboundPlayerActionPacket.STREAM_CODEC.decode(buf); + case ServerboundPlayerCommand -> nmsPacket = ServerboundPlayerCommandPacket.STREAM_CODEC.decode(buf); + case ServerboundPlayerInput -> nmsPacket = ServerboundPlayerInputPacket.STREAM_CODEC.decode(buf); -+ case ServerboundRecipeBookChangeSettings -> -+ nmsPacket = ServerboundRecipeBookChangeSettingsPacket.STREAM_CODEC.decode(buf); -+ case ServerboundRecipeBookSeenRecipe -> -+ nmsPacket = ServerboundRecipeBookSeenRecipePacket.STREAM_CODEC.decode(buf); ++ case ServerboundRecipeBookChangeSettings -> nmsPacket = ServerboundRecipeBookChangeSettingsPacket.STREAM_CODEC.decode(buf); ++ case ServerboundRecipeBookSeenRecipe -> nmsPacket = ServerboundRecipeBookSeenRecipePacket.STREAM_CODEC.decode(buf); + case ServerboundRenameItem -> nmsPacket = ServerboundRenameItemPacket.STREAM_CODEC.decode(buf); + case ServerboundSeenAdvancements -> nmsPacket = ServerboundSeenAdvancementsPacket.STREAM_CODEC.decode(buf); + case ServerboundSelectTrade -> nmsPacket = ServerboundSelectTradePacket.STREAM_CODEC.decode(buf); + case ServerboundSetBeacon -> nmsPacket = ServerboundSetBeaconPacket.STREAM_CODEC.decode(buf); + case ServerboundSetCarriedItem -> nmsPacket = ServerboundSetCarriedItemPacket.STREAM_CODEC.decode(buf); + case ServerboundSetCommandBlock -> nmsPacket = ServerboundSetCommandBlockPacket.STREAM_CODEC.decode(buf); -+ case ServerboundSetCommandMinecart -> -+ nmsPacket = ServerboundSetCommandMinecartPacket.STREAM_CODEC.decode(buf); -+ case ServerboundSetCreativeModeSlot -> -+ nmsPacket = ServerboundSetCreativeModeSlotPacket.STREAM_CODEC.decode(buf); ++ case ServerboundSetCommandMinecart -> nmsPacket = ServerboundSetCommandMinecartPacket.STREAM_CODEC.decode(buf); ++ case ServerboundSetCreativeModeSlot -> nmsPacket = ServerboundSetCreativeModeSlotPacket.STREAM_CODEC.decode(buf); + case ServerboundSetJigsawBlock -> nmsPacket = ServerboundSetJigsawBlockPacket.STREAM_CODEC.decode(buf); -+ case ServerboundSetStructureBlock -> -+ nmsPacket = ServerboundSetStructureBlockPacket.STREAM_CODEC.decode(buf); ++ case ServerboundSetStructureBlock -> nmsPacket = ServerboundSetStructureBlockPacket.STREAM_CODEC.decode(buf); + case ServerboundSignUpdate -> nmsPacket = ServerboundSignUpdatePacket.STREAM_CODEC.decode(buf); + case ServerboundSwing -> nmsPacket = ServerboundSwingPacket.STREAM_CODEC.decode(buf); + case ServerboundTeleportToEntity -> nmsPacket = ServerboundTeleportToEntityPacket.STREAM_CODEC.decode(buf); @@ -550,14 +519,12 @@ index 0000000000000000000000000000000000000000..6e1d8d29436d813a3a75de17c467c4fb + case ClientboundStoreCookie -> nmsPacket = ClientboundStoreCookiePacket.STREAM_CODEC.decode(buf); + case ClientboundTransfer -> nmsPacket = ClientboundTransferPacket.STREAM_CODEC.decode(buf); + case ClientboundUpdateTags -> nmsPacket = ClientboundUpdateTagsPacket.STREAM_CODEC.decode(buf); -+ case ServerboundClientInformation -> -+ nmsPacket = ServerboundClientInformationPacket.STREAM_CODEC.decode(buf); ++ case ServerboundClientInformation -> nmsPacket = ServerboundClientInformationPacket.STREAM_CODEC.decode(buf); + case ServerboundCustomPayload -> nmsPacket = ServerboundCustomPayloadPacket.STREAM_CODEC.decode(buf); + case ServerboundKeepAlive -> nmsPacket = ServerboundKeepAlivePacket.STREAM_CODEC.decode(buf); + case ServerboundPong -> nmsPacket = ServerboundPongPacket.STREAM_CODEC.decode(buf); + case ServerboundResourcePack -> nmsPacket = ServerboundResourcePackPacket.STREAM_CODEC.decode(buf); -+ default -> -+ throw new UnsupportedOperationException("This feature is not completely finished yet, packet type " + type + " is not supported temporary."); ++ default -> throw new UnsupportedOperationException("This feature is not completely finished yet, packet type " + type + " is not supported temporary."); + } + return nmsPacket; + } @@ -1265,8 +1232,7 @@ index 0000000000000000000000000000000000000000..6e1d8d29436d813a3a75de17c467c4fb + type = PacketType.ServerboundResourcePack; + ServerboundResourcePackPacket.STREAM_CODEC.encode(buf, (ServerboundResourcePackPacket) nmsPacket); + } -+ default -> -+ throw new UnsupportedOperationException("This feature is not completely finished yet, packet " + nmsPacket + " is not supported temporary."); ++ default -> throw new UnsupportedOperationException("This feature is not completely finished yet, packet " + nmsPacket + " is not supported temporary."); + } + return new Packet(type, Bytebuf.of(buf.array())); + } From 5e8a1f9a53d5a3932808daf1182035033f139838 Mon Sep 17 00:00:00 2001 From: Lumine1909 <133463833+Lumine1909@users.noreply.github.com> Date: Thu, 23 May 2024 23:23:15 -0400 Subject: [PATCH 8/9] rewrite and component support --- patches/api/0011-Bytebuf-API.patch | 16 +- patches/server/0135-Bytebuf-API.patch | 1008 +++---------------------- 2 files changed, 135 insertions(+), 889 deletions(-) diff --git a/patches/api/0011-Bytebuf-API.patch b/patches/api/0011-Bytebuf-API.patch index 57da8bd7..e3d75bbb 100644 --- a/patches/api/0011-Bytebuf-API.patch +++ b/patches/api/0011-Bytebuf-API.patch @@ -50,10 +50,10 @@ index 6c327a07bf8a6aa11a2d7dad12b2830acc539484..939bdc02b917ad72a8b7e6640067da19 Spigot spigot(); diff --git a/src/main/java/org/leavesmc/leaves/bytebuf/Bytebuf.java b/src/main/java/org/leavesmc/leaves/bytebuf/Bytebuf.java new file mode 100644 -index 0000000000000000000000000000000000000000..8e0b7e132ea1cec7776a23ecbf6d1feef9f2eaf5 +index 0000000000000000000000000000000000000000..f0f28cfdfc61e6dd6e91e68dfa8c2742e391feef --- /dev/null +++ b/src/main/java/org/leavesmc/leaves/bytebuf/Bytebuf.java -@@ -0,0 +1,54 @@ +@@ -0,0 +1,66 @@ +package org.leavesmc.leaves.bytebuf; + +import org.bukkit.Bukkit; @@ -92,6 +92,10 @@ index 0000000000000000000000000000000000000000..8e0b7e132ea1cec7776a23ecbf6d1fee + + byte readByte(); + ++ Bytebuf writeBoolean(boolean b); ++ ++ boolean readBoolean(); ++ + Bytebuf writeShort(int i); + + short readShort(); @@ -107,6 +111,14 @@ index 0000000000000000000000000000000000000000..8e0b7e132ea1cec7776a23ecbf6d1fee + Bytebuf writeUTFString(String utf); + + String readUTFString(); ++ ++ Bytebuf writeComponentPlain(String str); ++ ++ String readComponentPlain(); ++ ++ Bytebuf writeComponentJson(String json); ++ ++ String readComponentJson(); +} diff --git a/src/main/java/org/leavesmc/leaves/bytebuf/BytebufManager.java b/src/main/java/org/leavesmc/leaves/bytebuf/BytebufManager.java new file mode 100644 diff --git a/patches/server/0135-Bytebuf-API.patch b/patches/server/0135-Bytebuf-API.patch index 8622d6d9..088f8278 100644 --- a/patches/server/0135-Bytebuf-API.patch +++ b/patches/server/0135-Bytebuf-API.patch @@ -105,14 +105,19 @@ index 0000000000000000000000000000000000000000..443f7f6e0b8d40eaafb8009b3b7e405c +} diff --git a/src/main/java/org/leavesmc/leaves/bytebuf/WrappedBytebuf.java b/src/main/java/org/leavesmc/leaves/bytebuf/WrappedBytebuf.java new file mode 100644 -index 0000000000000000000000000000000000000000..399b212fa20594ec8bb3f686d0cdc3ceb7dd2cfe +index 0000000000000000000000000000000000000000..1f4aca3138487ef69e674d27a6bbba033e56c4f1 --- /dev/null +++ b/src/main/java/org/leavesmc/leaves/bytebuf/WrappedBytebuf.java -@@ -0,0 +1,117 @@ +@@ -0,0 +1,163 @@ +package org.leavesmc.leaves.bytebuf; + +import io.netty.buffer.ByteBuf; ++import io.netty.buffer.Unpooled; ++import net.minecraft.core.RegistryAccess; +import net.minecraft.network.FriendlyByteBuf; ++import net.minecraft.network.RegistryFriendlyByteBuf; ++import net.minecraft.network.chat.Component; ++import net.minecraft.network.chat.ComponentSerialization; + +public class WrappedBytebuf implements Bytebuf { + @@ -183,6 +188,17 @@ index 0000000000000000000000000000000000000000..399b212fa20594ec8bb3f686d0cdc3ce + } + + @Override ++ public Bytebuf writeBoolean(boolean b) { ++ buf.writeBoolean(b); ++ return this; ++ } ++ ++ @Override ++ public boolean readBoolean() { ++ return buf.readBoolean(); ++ } ++ ++ @Override + public Bytebuf writeShort(int i) { + buf.writeShort(i); + return this; @@ -225,24 +241,56 @@ index 0000000000000000000000000000000000000000..399b212fa20594ec8bb3f686d0cdc3ce + public String readUTFString() { + return buf.readUtf(); + } ++ ++ @Override ++ public Bytebuf writeComponentPlain(String str) { ++ RegistryFriendlyByteBuf regBuf = new RegistryFriendlyByteBuf(Unpooled.buffer(), RegistryAccess.EMPTY); ++ ComponentSerialization.STREAM_CODEC.encode(regBuf, Component.literal(str)); ++ buf.writeBytes(regBuf.array()); ++ return this; ++ } ++ ++ @Override ++ public String readComponentPlain() { ++ return ComponentSerialization.STREAM_CODEC.decode(new RegistryFriendlyByteBuf(buf, RegistryAccess.EMPTY)).getString(); ++ } ++ ++ @Override ++ public Bytebuf writeComponentJson(String json) { ++ Component component = Component.Serializer.fromJson(json, RegistryAccess.EMPTY); ++ if (component == null) { ++ throw new IllegalArgumentException("The String " + json + " can not be serialize to Minecraft chat component"); ++ } ++ RegistryFriendlyByteBuf regBuf = new RegistryFriendlyByteBuf(Unpooled.buffer(), RegistryAccess.EMPTY); ++ ComponentSerialization.STREAM_CODEC.encode(regBuf, component); ++ buf.writeBytes(regBuf.array()); ++ return this; ++ } ++ ++ @Override ++ public String readComponentJson() { ++ return Component.Serializer.toJson(ComponentSerialization.STREAM_CODEC.decode(new RegistryFriendlyByteBuf(buf, RegistryAccess.EMPTY)), RegistryAccess.EMPTY); ++ } +} diff --git a/src/main/java/org/leavesmc/leaves/bytebuf/internal/InternalBytebufHandler.java b/src/main/java/org/leavesmc/leaves/bytebuf/internal/InternalBytebufHandler.java new file mode 100644 -index 0000000000000000000000000000000000000000..fdeec0625275862b289c7c59aaef11facc76dce7 +index 0000000000000000000000000000000000000000..35d66678dfe391dcde4061775f5735d68a6b8e0f --- /dev/null +++ b/src/main/java/org/leavesmc/leaves/bytebuf/internal/InternalBytebufHandler.java -@@ -0,0 +1,1005 @@ +@@ -0,0 +1,193 @@ +package org.leavesmc.leaves.bytebuf.internal; + ++import com.google.common.collect.ImmutableMap; +import io.netty.buffer.Unpooled; +import io.netty.channel.ChannelDuplexHandler; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelPromise; +import net.minecraft.network.Connection; ++import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.RegistryFriendlyByteBuf; ++import net.minecraft.network.codec.StreamCodec; +import net.minecraft.network.protocol.BundleDelimiterPacket; +import net.minecraft.network.protocol.BundlePacket; -+import net.minecraft.network.protocol.common.*; +import net.minecraft.network.protocol.game.*; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerPlayer; @@ -257,9 +305,12 @@ index 0000000000000000000000000000000000000000..fdeec0625275862b289c7c59aaef11fa +import org.leavesmc.leaves.bytebuf.packet.PacketListener; +import org.leavesmc.leaves.bytebuf.packet.PacketType; + ++import java.lang.reflect.Field; +import java.util.HashMap; +import java.util.Map; + ++import static org.leavesmc.leaves.bytebuf.packet.PacketType.*; ++ +public class InternalBytebufHandler { + + class PacketHandler extends ChannelDuplexHandler { @@ -307,6 +358,36 @@ index 0000000000000000000000000000000000000000..fdeec0625275862b289c7c59aaef11fa + + public final Map listenerMap = new HashMap<>(); + private final BytebufManager manager = new SimpleBytebufManager(this); ++ private final ImmutableMap type2CodecMap; ++ ++ public InternalBytebufHandler() { ++ ImmutableMap.Builder builder = ImmutableMap.builder(); ++ for (PacketType packet : PacketType.values()) { ++ Class packetClass = null; ++ try { ++ packetClass = Class.forName("net.minecraft.network.protocol.game." + packet.name() + "Packet"); ++ } catch (ClassNotFoundException e) { ++ try { ++ packetClass = Class.forName("net.minecraft.network.protocol.common." + packet.name() + "Packet"); ++ } catch (ClassNotFoundException e2) { ++ continue; ++ } ++ } ++ try { ++ Field field = packetClass.getDeclaredField("STREAM_CODEC"); ++ builder.put(packet, (StreamCodec>) field.get(null)); ++ } catch (Exception ignored) { ++ } ++ } ++ builder.put(ClientboundMoveEntityPos, ClientboundMoveEntityPacket.Pos.STREAM_CODEC); ++ builder.put(ClientboundMoveEntityPosRot, ClientboundMoveEntityPacket.PosRot.STREAM_CODEC); ++ builder.put(ClientboundMoveEntityRot, ClientboundMoveEntityPacket.Rot.STREAM_CODEC); ++ builder.put(ServerboundMovePlayerPos, ServerboundMovePlayerPacket.Pos.STREAM_CODEC); ++ builder.put(ServerboundMovePlayerPosRot, ServerboundMovePlayerPacket.PosRot.STREAM_CODEC); ++ builder.put(ServerboundMovePlayerRot, ServerboundMovePlayerPacket.Rot.STREAM_CODEC); ++ builder.put(ServerboundMovePlayerStatusOnly, ServerboundMovePlayerPacket.StatusOnly.STREAM_CODEC); ++ type2CodecMap = builder.build(); ++ } + + public void injectPlayer(ServerPlayer player) { + player.connection.connection.channel.pipeline().addBefore("packet_handler", PacketHandler.handlerName, new PacketHandler(player.getBukkitEntity())); @@ -342,898 +423,51 @@ index 0000000000000000000000000000000000000000..fdeec0625275862b289c7c59aaef11fa + + public void applyPacketToPlayer(Player player, Packet packet) { + Connection sp = ((CraftPlayer) player).getHandle().connection.connection; -+ sp.channel.writeAndFlush(createNMSPacket(packet)); ++ sp.send(createNMSPacket(packet)); + } + + public net.minecraft.network.protocol.Packet createNMSPacket(Packet packet) { + RegistryFriendlyByteBuf buf = new RegistryFriendlyByteBuf(((WrappedBytebuf) packet.bytebuf()).getFriendlyBytebuf(), MinecraftServer.getServer().registryAccess()); -+ PacketType type = packet.type(); -+ net.minecraft.network.protocol.Packet nmsPacket = null; -+ switch (type) { -+ case ClientboundAddEntity -> nmsPacket = ClientboundAddEntityPacket.STREAM_CODEC.decode(buf); -+ case ClientboundAddExperienceOrb -> nmsPacket = ClientboundAddExperienceOrbPacket.STREAM_CODEC.decode(buf); -+ case ClientboundAnimate -> nmsPacket = ClientboundAnimatePacket.STREAM_CODEC.decode(buf); -+ case ClientboundAwardStats -> nmsPacket = ClientboundAwardStatsPacket.STREAM_CODEC.decode(buf); -+ case ClientboundBlockChangedAck -> nmsPacket = ClientboundBlockChangedAckPacket.STREAM_CODEC.decode(buf); -+ case ClientboundBlockDestruction -> nmsPacket = ClientboundBlockDestructionPacket.STREAM_CODEC.decode(buf); -+ case ClientboundBlockEntityData -> nmsPacket = ClientboundBlockEntityDataPacket.STREAM_CODEC.decode(buf); -+ case ClientboundBlockEvent -> nmsPacket = ClientboundBlockEventPacket.STREAM_CODEC.decode(buf); -+ case ClientboundBlockUpdate -> nmsPacket = ClientboundBlockUpdatePacket.STREAM_CODEC.decode(buf); -+ case ClientboundBossEvent -> nmsPacket = ClientboundBossEventPacket.STREAM_CODEC.decode(buf); -+ case ClientboundChangeDifficulty -> nmsPacket = ClientboundChangeDifficultyPacket.STREAM_CODEC.decode(buf); -+ case ClientboundChunkBatchFinished -> nmsPacket = ClientboundChunkBatchFinishedPacket.STREAM_CODEC.decode(buf); -+ case ClientboundChunkBatchStart -> nmsPacket = ClientboundChunkBatchStartPacket.STREAM_CODEC.decode(buf); -+ case ClientboundChunksBiomes -> nmsPacket = ClientboundChunksBiomesPacket.STREAM_CODEC.decode(buf); -+ case ClientboundClearTitles -> nmsPacket = ClientboundClearTitlesPacket.STREAM_CODEC.decode(buf); -+ case ClientboundCommandSuggestions -> nmsPacket = ClientboundCommandSuggestionsPacket.STREAM_CODEC.decode(buf); -+ case ClientboundCommands -> nmsPacket = ClientboundCommandsPacket.STREAM_CODEC.decode(buf); -+ case ClientboundContainerClose -> nmsPacket = ClientboundContainerClosePacket.STREAM_CODEC.decode(buf); -+ case ClientboundContainerSetContent -> nmsPacket = ClientboundContainerSetContentPacket.STREAM_CODEC.decode(buf); -+ case ClientboundContainerSetData -> nmsPacket = ClientboundContainerSetDataPacket.STREAM_CODEC.decode(buf); -+ case ClientboundContainerSetSlot -> nmsPacket = ClientboundContainerSetSlotPacket.STREAM_CODEC.decode(buf); -+ case ClientboundCooldown -> nmsPacket = ClientboundCooldownPacket.STREAM_CODEC.decode(buf); -+ case ClientboundCustomChatCompletions -> nmsPacket = ClientboundCustomChatCompletionsPacket.STREAM_CODEC.decode(buf); -+ case ClientboundDamageEvent -> nmsPacket = ClientboundDamageEventPacket.STREAM_CODEC.decode(buf); -+ case ClientboundDebugSample -> nmsPacket = ClientboundDebugSamplePacket.STREAM_CODEC.decode(buf); -+ case ClientboundDeleteChat -> nmsPacket = ClientboundDeleteChatPacket.STREAM_CODEC.decode(buf); -+ case ClientboundDisguisedChat -> nmsPacket = ClientboundDisguisedChatPacket.STREAM_CODEC.decode(buf); -+ case ClientboundEntityEvent -> nmsPacket = ClientboundEntityEventPacket.STREAM_CODEC.decode(buf); -+ case ClientboundExplode -> nmsPacket = ClientboundExplodePacket.STREAM_CODEC.decode(buf); -+ case ClientboundForgetLevelChunk -> nmsPacket = ClientboundForgetLevelChunkPacket.STREAM_CODEC.decode(buf); -+ case ClientboundGameEvent -> nmsPacket = ClientboundGameEventPacket.STREAM_CODEC.decode(buf); -+ case ClientboundHorseScreenOpen -> nmsPacket = ClientboundHorseScreenOpenPacket.STREAM_CODEC.decode(buf); -+ case ClientboundHurtAnimation -> nmsPacket = ClientboundHurtAnimationPacket.STREAM_CODEC.decode(buf); -+ case ClientboundInitializeBorder -> nmsPacket = ClientboundInitializeBorderPacket.STREAM_CODEC.decode(buf); -+ case ClientboundLevelChunkWithLight -> nmsPacket = ClientboundLevelChunkWithLightPacket.STREAM_CODEC.decode(buf); -+ case ClientboundLevelEvent -> nmsPacket = ClientboundLevelEventPacket.STREAM_CODEC.decode(buf); -+ case ClientboundLevelParticles -> nmsPacket = ClientboundLevelParticlesPacket.STREAM_CODEC.decode(buf); -+ case ClientboundLightUpdate -> nmsPacket = ClientboundLightUpdatePacket.STREAM_CODEC.decode(buf); -+ case ClientboundLogin -> nmsPacket = ClientboundLoginPacket.STREAM_CODEC.decode(buf); -+ case ClientboundMapItemData -> nmsPacket = ClientboundMapItemDataPacket.STREAM_CODEC.decode(buf); -+ case ClientboundMerchantOffers -> nmsPacket = ClientboundMerchantOffersPacket.STREAM_CODEC.decode(buf); -+ case ClientboundMoveEntityPos -> nmsPacket = ClientboundMoveEntityPacket.Pos.STREAM_CODEC.decode(buf); -+ case ClientboundMoveEntityPosRot -> nmsPacket = ClientboundMoveEntityPacket.PosRot.STREAM_CODEC.decode(buf); -+ case ClientboundMoveEntityRot -> nmsPacket = ClientboundMoveEntityPacket.Rot.STREAM_CODEC.decode(buf); -+ case ClientboundMoveVehicle -> nmsPacket = ClientboundMoveVehiclePacket.STREAM_CODEC.decode(buf); -+ case ClientboundOpenBook -> nmsPacket = ClientboundOpenBookPacket.STREAM_CODEC.decode(buf); -+ case ClientboundOpenScreen -> nmsPacket = ClientboundOpenScreenPacket.STREAM_CODEC.decode(buf); -+ case ClientboundOpenSignEditor -> nmsPacket = ClientboundOpenSignEditorPacket.STREAM_CODEC.decode(buf); -+ case ClientboundPlaceGhostRecipe -> nmsPacket = ClientboundPlaceGhostRecipePacket.STREAM_CODEC.decode(buf); -+ case ClientboundPlayerAbilities -> nmsPacket = ClientboundPlayerAbilitiesPacket.STREAM_CODEC.decode(buf); -+ case ClientboundPlayerChat -> nmsPacket = ClientboundPlayerChatPacket.STREAM_CODEC.decode(buf); -+ case ClientboundPlayerCombatEnd -> nmsPacket = ClientboundPlayerCombatEndPacket.STREAM_CODEC.decode(buf); -+ case ClientboundPlayerCombatEnter -> nmsPacket = ClientboundPlayerCombatEnterPacket.STREAM_CODEC.decode(buf); -+ case ClientboundPlayerCombatKill -> nmsPacket = ClientboundPlayerCombatKillPacket.STREAM_CODEC.decode(buf); -+ case ClientboundPlayerInfoRemove -> nmsPacket = ClientboundPlayerInfoRemovePacket.STREAM_CODEC.decode(buf); -+ case ClientboundPlayerInfoUpdate -> nmsPacket = ClientboundPlayerInfoUpdatePacket.STREAM_CODEC.decode(buf); -+ case ClientboundPlayerLookAt -> nmsPacket = ClientboundPlayerLookAtPacket.STREAM_CODEC.decode(buf); -+ case ClientboundPlayerPosition -> nmsPacket = ClientboundPlayerPositionPacket.STREAM_CODEC.decode(buf); -+ case ClientboundRecipe -> nmsPacket = ClientboundRecipePacket.STREAM_CODEC.decode(buf); -+ case ClientboundRemoveEntities -> nmsPacket = ClientboundRemoveEntitiesPacket.STREAM_CODEC.decode(buf); -+ case ClientboundRemoveMobEffect -> nmsPacket = ClientboundRemoveMobEffectPacket.STREAM_CODEC.decode(buf); -+ case ClientboundRespawn -> nmsPacket = ClientboundRespawnPacket.STREAM_CODEC.decode(buf); -+ case ClientboundRotateHead -> nmsPacket = ClientboundRotateHeadPacket.STREAM_CODEC.decode(buf); -+ case ClientboundSectionBlocksUpdate -> nmsPacket = ClientboundSectionBlocksUpdatePacket.STREAM_CODEC.decode(buf); -+ case ClientboundSelectAdvancementsTab -> nmsPacket = ClientboundSelectAdvancementsTabPacket.STREAM_CODEC.decode(buf); -+ case ClientboundServerData -> nmsPacket = ClientboundServerDataPacket.STREAM_CODEC.decode(buf); -+ case ClientboundSetActionBarText -> nmsPacket = ClientboundSetActionBarTextPacket.STREAM_CODEC.decode(buf); -+ case ClientboundSetBorderCenter -> nmsPacket = ClientboundSetBorderCenterPacket.STREAM_CODEC.decode(buf); -+ case ClientboundSetBorderLerpSize -> nmsPacket = ClientboundSetBorderLerpSizePacket.STREAM_CODEC.decode(buf); -+ case ClientboundSetBorderSize -> nmsPacket = ClientboundSetBorderSizePacket.STREAM_CODEC.decode(buf); -+ case ClientboundSetBorderWarningDelay -> nmsPacket = ClientboundSetBorderWarningDelayPacket.STREAM_CODEC.decode(buf); -+ case ClientboundSetBorderWarningDistance -> nmsPacket = ClientboundSetBorderWarningDistancePacket.STREAM_CODEC.decode(buf); -+ case ClientboundSetCamera -> nmsPacket = ClientboundSetCameraPacket.STREAM_CODEC.decode(buf); -+ case ClientboundSetCarriedItem -> nmsPacket = ClientboundSetCarriedItemPacket.STREAM_CODEC.decode(buf); -+ case ClientboundSetChunkCacheCenter -> nmsPacket = ClientboundSetChunkCacheCenterPacket.STREAM_CODEC.decode(buf); -+ case ClientboundSetChunkCacheRadius -> nmsPacket = ClientboundSetChunkCacheRadiusPacket.STREAM_CODEC.decode(buf); -+ case ClientboundSetDefaultSpawnPosition -> nmsPacket = ClientboundSetDefaultSpawnPositionPacket.STREAM_CODEC.decode(buf); -+ case ClientboundSetDisplayObjective -> nmsPacket = ClientboundSetDisplayObjectivePacket.STREAM_CODEC.decode(buf); -+ case ClientboundSetEntityData -> nmsPacket = ClientboundSetEntityDataPacket.STREAM_CODEC.decode(buf); -+ case ClientboundSetEntityLink -> nmsPacket = ClientboundSetEntityLinkPacket.STREAM_CODEC.decode(buf); -+ case ClientboundSetEntityMotion -> nmsPacket = ClientboundSetEntityMotionPacket.STREAM_CODEC.decode(buf); -+ case ClientboundSetEquipment -> nmsPacket = ClientboundSetEquipmentPacket.STREAM_CODEC.decode(buf); -+ case ClientboundSetExperience -> nmsPacket = ClientboundSetExperiencePacket.STREAM_CODEC.decode(buf); -+ case ClientboundSetHealth -> nmsPacket = ClientboundSetHealthPacket.STREAM_CODEC.decode(buf); -+ case ClientboundSetObjective -> nmsPacket = ClientboundSetObjectivePacket.STREAM_CODEC.decode(buf); -+ case ClientboundSetPassengers -> nmsPacket = ClientboundSetPassengersPacket.STREAM_CODEC.decode(buf); -+ case ClientboundSetPlayerTeam -> nmsPacket = ClientboundSetPlayerTeamPacket.STREAM_CODEC.decode(buf); -+ case ClientboundSetScore -> nmsPacket = ClientboundSetScorePacket.STREAM_CODEC.decode(buf); -+ case ClientboundSetSimulationDistance -> nmsPacket = ClientboundSetSimulationDistancePacket.STREAM_CODEC.decode(buf); -+ case ClientboundSetSubtitleText -> nmsPacket = ClientboundSetSubtitleTextPacket.STREAM_CODEC.decode(buf); -+ case ClientboundSetTime -> nmsPacket = ClientboundSetTimePacket.STREAM_CODEC.decode(buf); -+ case ClientboundSetTitleText -> nmsPacket = ClientboundSetTitleTextPacket.STREAM_CODEC.decode(buf); -+ case ClientboundSetTitlesAnimation -> nmsPacket = ClientboundSetTitlesAnimationPacket.STREAM_CODEC.decode(buf); -+ case ClientboundSoundEntity -> nmsPacket = ClientboundSoundEntityPacket.STREAM_CODEC.decode(buf); -+ case ClientboundSound -> nmsPacket = ClientboundSoundPacket.STREAM_CODEC.decode(buf); -+ case ClientboundStartConfiguration -> nmsPacket = ClientboundStartConfigurationPacket.STREAM_CODEC.decode(buf); -+ case ClientboundStopSound -> nmsPacket = ClientboundStopSoundPacket.STREAM_CODEC.decode(buf); -+ case ClientboundSystemChat -> nmsPacket = ClientboundSystemChatPacket.STREAM_CODEC.decode(buf); -+ case ClientboundTabList -> nmsPacket = ClientboundTabListPacket.STREAM_CODEC.decode(buf); -+ case ClientboundTagQuery -> nmsPacket = ClientboundTagQueryPacket.STREAM_CODEC.decode(buf); -+ case ClientboundTakeItemEntity -> nmsPacket = ClientboundTakeItemEntityPacket.STREAM_CODEC.decode(buf); -+ case ClientboundTeleportEntity -> nmsPacket = ClientboundTeleportEntityPacket.STREAM_CODEC.decode(buf); -+ case ClientboundUpdateAdvancements -> nmsPacket = ClientboundUpdateAdvancementsPacket.STREAM_CODEC.decode(buf); -+ case ClientboundUpdateAttributes -> nmsPacket = ClientboundUpdateAttributesPacket.STREAM_CODEC.decode(buf); -+ case ClientboundUpdateMobEffect -> nmsPacket = ClientboundUpdateMobEffectPacket.STREAM_CODEC.decode(buf); -+ case ClientboundUpdateRecipes -> nmsPacket = ClientboundUpdateRecipesPacket.STREAM_CODEC.decode(buf); -+ case ClientboundProjectilePower -> nmsPacket = ClientboundProjectilePowerPacket.STREAM_CODEC.decode(buf); -+ case ServerboundAcceptTeleportation -> nmsPacket = ServerboundAcceptTeleportationPacket.STREAM_CODEC.decode(buf); -+ case ServerboundBlockEntityTagQuery -> nmsPacket = ServerboundBlockEntityTagQueryPacket.STREAM_CODEC.decode(buf); -+ case ServerboundChangeDifficulty -> nmsPacket = ServerboundChangeDifficultyPacket.STREAM_CODEC.decode(buf); -+ case ServerboundChatAck -> nmsPacket = ServerboundChatAckPacket.STREAM_CODEC.decode(buf); -+ case ServerboundChatCommand -> nmsPacket = ServerboundChatCommandPacket.STREAM_CODEC.decode(buf); -+ case ServerboundChatCommandSigned -> nmsPacket = ServerboundChatCommandSignedPacket.STREAM_CODEC.decode(buf); -+ case ServerboundChat -> nmsPacket = ServerboundChatPacket.STREAM_CODEC.decode(buf); -+ case ServerboundChatSessionUpdate -> nmsPacket = ServerboundChatSessionUpdatePacket.STREAM_CODEC.decode(buf); -+ case ServerboundChunkBatchReceived -> nmsPacket = ServerboundChunkBatchReceivedPacket.STREAM_CODEC.decode(buf); -+ case ServerboundClientCommand -> nmsPacket = ServerboundClientCommandPacket.STREAM_CODEC.decode(buf); -+ case ServerboundCommandSuggestion -> nmsPacket = ServerboundCommandSuggestionPacket.STREAM_CODEC.decode(buf); -+ case ServerboundConfigurationAcknowledged -> nmsPacket = ServerboundConfigurationAcknowledgedPacket.STREAM_CODEC.decode(buf); -+ case ServerboundContainerButtonClick -> nmsPacket = ServerboundContainerButtonClickPacket.STREAM_CODEC.decode(buf); -+ case ServerboundContainerClick -> nmsPacket = ServerboundContainerClickPacket.STREAM_CODEC.decode(buf); -+ case ServerboundContainerClose -> nmsPacket = ServerboundContainerClosePacket.STREAM_CODEC.decode(buf); -+ case ServerboundContainerSlotStateChanged -> nmsPacket = ServerboundContainerSlotStateChangedPacket.STREAM_CODEC.decode(buf); -+ case ServerboundDebugSampleSubscription -> nmsPacket = ServerboundDebugSampleSubscriptionPacket.STREAM_CODEC.decode(buf); -+ case ServerboundEditBook -> nmsPacket = ServerboundEditBookPacket.STREAM_CODEC.decode(buf); -+ case ServerboundEntityTagQuery -> nmsPacket = ServerboundEntityTagQueryPacket.STREAM_CODEC.decode(buf); -+ case ServerboundInteract -> nmsPacket = ServerboundInteractPacket.STREAM_CODEC.decode(buf); -+ case ServerboundJigsawGenerate -> nmsPacket = ServerboundJigsawGeneratePacket.STREAM_CODEC.decode(buf); -+ case ServerboundLockDifficulty -> nmsPacket = ServerboundLockDifficultyPacket.STREAM_CODEC.decode(buf); -+ case ServerboundMovePlayerPos -> nmsPacket = ServerboundMovePlayerPacket.Pos.STREAM_CODEC.decode(buf); -+ case ServerboundMovePlayerPosRot -> nmsPacket = ServerboundMovePlayerPacket.PosRot.STREAM_CODEC.decode(buf); -+ case ServerboundMovePlayerRot -> nmsPacket = ServerboundMovePlayerPacket.Rot.STREAM_CODEC.decode(buf); -+ case ServerboundMovePlayerStatusOnly -> nmsPacket = ServerboundMovePlayerPacket.StatusOnly.STREAM_CODEC.decode(buf); -+ case ServerboundMoveVehicle -> nmsPacket = ServerboundMoveVehiclePacket.STREAM_CODEC.decode(buf); -+ case ServerboundPaddleBoat -> nmsPacket = ServerboundPaddleBoatPacket.STREAM_CODEC.decode(buf); -+ case ServerboundPickItem -> nmsPacket = ServerboundPickItemPacket.STREAM_CODEC.decode(buf); -+ case ServerboundPlaceRecipe -> nmsPacket = ServerboundPlaceRecipePacket.STREAM_CODEC.decode(buf); -+ case ServerboundPlayerAbilities -> nmsPacket = ServerboundPlayerAbilitiesPacket.STREAM_CODEC.decode(buf); -+ case ServerboundPlayerAction -> nmsPacket = ServerboundPlayerActionPacket.STREAM_CODEC.decode(buf); -+ case ServerboundPlayerCommand -> nmsPacket = ServerboundPlayerCommandPacket.STREAM_CODEC.decode(buf); -+ case ServerboundPlayerInput -> nmsPacket = ServerboundPlayerInputPacket.STREAM_CODEC.decode(buf); -+ case ServerboundRecipeBookChangeSettings -> nmsPacket = ServerboundRecipeBookChangeSettingsPacket.STREAM_CODEC.decode(buf); -+ case ServerboundRecipeBookSeenRecipe -> nmsPacket = ServerboundRecipeBookSeenRecipePacket.STREAM_CODEC.decode(buf); -+ case ServerboundRenameItem -> nmsPacket = ServerboundRenameItemPacket.STREAM_CODEC.decode(buf); -+ case ServerboundSeenAdvancements -> nmsPacket = ServerboundSeenAdvancementsPacket.STREAM_CODEC.decode(buf); -+ case ServerboundSelectTrade -> nmsPacket = ServerboundSelectTradePacket.STREAM_CODEC.decode(buf); -+ case ServerboundSetBeacon -> nmsPacket = ServerboundSetBeaconPacket.STREAM_CODEC.decode(buf); -+ case ServerboundSetCarriedItem -> nmsPacket = ServerboundSetCarriedItemPacket.STREAM_CODEC.decode(buf); -+ case ServerboundSetCommandBlock -> nmsPacket = ServerboundSetCommandBlockPacket.STREAM_CODEC.decode(buf); -+ case ServerboundSetCommandMinecart -> nmsPacket = ServerboundSetCommandMinecartPacket.STREAM_CODEC.decode(buf); -+ case ServerboundSetCreativeModeSlot -> nmsPacket = ServerboundSetCreativeModeSlotPacket.STREAM_CODEC.decode(buf); -+ case ServerboundSetJigsawBlock -> nmsPacket = ServerboundSetJigsawBlockPacket.STREAM_CODEC.decode(buf); -+ case ServerboundSetStructureBlock -> nmsPacket = ServerboundSetStructureBlockPacket.STREAM_CODEC.decode(buf); -+ case ServerboundSignUpdate -> nmsPacket = ServerboundSignUpdatePacket.STREAM_CODEC.decode(buf); -+ case ServerboundSwing -> nmsPacket = ServerboundSwingPacket.STREAM_CODEC.decode(buf); -+ case ServerboundTeleportToEntity -> nmsPacket = ServerboundTeleportToEntityPacket.STREAM_CODEC.decode(buf); -+ case ServerboundUseItemOn -> nmsPacket = ServerboundUseItemOnPacket.STREAM_CODEC.decode(buf); -+ case ServerboundUseItem -> nmsPacket = ServerboundUseItemPacket.STREAM_CODEC.decode(buf); -+ case ClientboundResetScore -> nmsPacket = ClientboundResetScorePacket.STREAM_CODEC.decode(buf); -+ case ClientboundTickingState -> nmsPacket = ClientboundTickingStatePacket.STREAM_CODEC.decode(buf); -+ case ClientboundTickingStep -> nmsPacket = ClientboundTickingStepPacket.STREAM_CODEC.decode(buf); -+ //case ClientboundCustomPayload -> nmsPacket = ClientboundCustomPayloadPacket.STREAM_CODEC.decode(buf); -+ case ClientboundDisconnect -> nmsPacket = ClientboundDisconnectPacket.STREAM_CODEC.decode(buf); -+ case ClientboundKeepAlive -> nmsPacket = ClientboundKeepAlivePacket.STREAM_CODEC.decode(buf); -+ case ClientboundResourcePackPop -> nmsPacket = ClientboundResourcePackPopPacket.STREAM_CODEC.decode(buf); -+ case ClientboundResourcePackPush -> nmsPacket = ClientboundResourcePackPushPacket.STREAM_CODEC.decode(buf); -+ case ClientboundStoreCookie -> nmsPacket = ClientboundStoreCookiePacket.STREAM_CODEC.decode(buf); -+ case ClientboundTransfer -> nmsPacket = ClientboundTransferPacket.STREAM_CODEC.decode(buf); -+ case ClientboundUpdateTags -> nmsPacket = ClientboundUpdateTagsPacket.STREAM_CODEC.decode(buf); -+ case ServerboundClientInformation -> nmsPacket = ServerboundClientInformationPacket.STREAM_CODEC.decode(buf); -+ case ServerboundCustomPayload -> nmsPacket = ServerboundCustomPayloadPacket.STREAM_CODEC.decode(buf); -+ case ServerboundKeepAlive -> nmsPacket = ServerboundKeepAlivePacket.STREAM_CODEC.decode(buf); -+ case ServerboundPong -> nmsPacket = ServerboundPongPacket.STREAM_CODEC.decode(buf); -+ case ServerboundResourcePack -> nmsPacket = ServerboundResourcePackPacket.STREAM_CODEC.decode(buf); -+ default -> throw new UnsupportedOperationException("This feature is not completely finished yet, packet type " + type + " is not supported temporary."); ++ StreamCodec> codec = type2CodecMap.get(packet.type()); ++ if (codec == null) { ++ throw new UnsupportedOperationException("This feature is not completely finished yet, packet type " + packet.type() + " is not supported temporary."); ++ } ++ return codec.decode(buf); ++ } ++ ++ private PacketType toEnumType(net.minecraft.network.protocol.PacketType type) { ++ StringBuilder builder = new StringBuilder(); ++ String bound = type.toString().split("/")[0]; ++ String name = type.toString().split(":")[1]; ++ builder.append(bound.substring(0, 1).toUpperCase()).append(bound.substring(1)); ++ boolean flag = true; ++ for (int i = 0; i < name.length(); i++) { ++ if (flag) { ++ builder.append(name.substring(i, i + 1).toUpperCase()); ++ flag = false; ++ continue; ++ } ++ if (name.charAt(i) == '_') { ++ flag = true; ++ } else { ++ builder.append(name.charAt(i)); ++ } ++ } ++ try { ++ return PacketType.valueOf(builder.toString()); ++ } catch (IllegalArgumentException e) { ++ throw new RuntimeException(e); + } -+ return nmsPacket; + } + + public Packet createBytebufPacket(net.minecraft.network.protocol.Packet nmsPacket) { -+ PacketType type; ++ PacketType type = toEnumType(nmsPacket.type()); + RegistryFriendlyByteBuf buf = new RegistryFriendlyByteBuf(Unpooled.buffer(8192), MinecraftServer.getServer().registryAccess()); -+ switch (nmsPacket.type().toString()) { -+ case "clientbound/minecraft:add_entity" -> { -+ type = PacketType.ClientboundAddEntity; -+ ClientboundAddEntityPacket.STREAM_CODEC.encode(buf, (ClientboundAddEntityPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:add_experience_orb" -> { -+ type = PacketType.ClientboundAddExperienceOrb; -+ ClientboundAddExperienceOrbPacket.STREAM_CODEC.encode(buf, (ClientboundAddExperienceOrbPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:animate" -> { -+ type = PacketType.ClientboundAnimate; -+ ClientboundAnimatePacket.STREAM_CODEC.encode(buf, (ClientboundAnimatePacket) nmsPacket); -+ } -+ case "clientbound/minecraft:award_stats" -> { -+ type = PacketType.ClientboundAwardStats; -+ ClientboundAwardStatsPacket.STREAM_CODEC.encode(buf, (ClientboundAwardStatsPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:block_changed_ack" -> { -+ type = PacketType.ClientboundBlockChangedAck; -+ ClientboundBlockChangedAckPacket.STREAM_CODEC.encode(buf, (ClientboundBlockChangedAckPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:block_destruction" -> { -+ type = PacketType.ClientboundBlockDestruction; -+ ClientboundBlockDestructionPacket.STREAM_CODEC.encode(buf, (ClientboundBlockDestructionPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:block_entity_data" -> { -+ type = PacketType.ClientboundBlockEntityData; -+ ClientboundBlockEntityDataPacket.STREAM_CODEC.encode(buf, (ClientboundBlockEntityDataPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:block_event" -> { -+ type = PacketType.ClientboundBlockEvent; -+ ClientboundBlockEventPacket.STREAM_CODEC.encode(buf, (ClientboundBlockEventPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:block_update" -> { -+ type = PacketType.ClientboundBlockUpdate; -+ ClientboundBlockUpdatePacket.STREAM_CODEC.encode(buf, (ClientboundBlockUpdatePacket) nmsPacket); -+ } -+ case "clientbound/minecraft:boss_event" -> { -+ type = PacketType.ClientboundBossEvent; -+ ClientboundBossEventPacket.STREAM_CODEC.encode(buf, (ClientboundBossEventPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:change_difficulty" -> { -+ type = PacketType.ClientboundChangeDifficulty; -+ ClientboundChangeDifficultyPacket.STREAM_CODEC.encode(buf, (ClientboundChangeDifficultyPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:chunk_batch_finished" -> { -+ type = PacketType.ClientboundChunkBatchFinished; -+ ClientboundChunkBatchFinishedPacket.STREAM_CODEC.encode(buf, (ClientboundChunkBatchFinishedPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:chunk_batch_start" -> { -+ type = PacketType.ClientboundChunkBatchStart; -+ ClientboundChunkBatchStartPacket.STREAM_CODEC.encode(buf, (ClientboundChunkBatchStartPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:chunks_biomes" -> { -+ type = PacketType.ClientboundChunksBiomes; -+ ClientboundChunksBiomesPacket.STREAM_CODEC.encode(buf, (ClientboundChunksBiomesPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:clear_titles" -> { -+ type = PacketType.ClientboundClearTitles; -+ ClientboundClearTitlesPacket.STREAM_CODEC.encode(buf, (ClientboundClearTitlesPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:command_suggestions" -> { -+ type = PacketType.ClientboundCommandSuggestions; -+ ClientboundCommandSuggestionsPacket.STREAM_CODEC.encode(buf, (ClientboundCommandSuggestionsPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:commands" -> { -+ type = PacketType.ClientboundCommands; -+ ClientboundCommandsPacket.STREAM_CODEC.encode(buf, (ClientboundCommandsPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:container_close" -> { -+ type = PacketType.ClientboundContainerClose; -+ ClientboundContainerClosePacket.STREAM_CODEC.encode(buf, (ClientboundContainerClosePacket) nmsPacket); -+ } -+ case "clientbound/minecraft:container_set_content" -> { -+ type = PacketType.ClientboundContainerSetContent; -+ ClientboundContainerSetContentPacket.STREAM_CODEC.encode(buf, (ClientboundContainerSetContentPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:container_set_data" -> { -+ type = PacketType.ClientboundContainerSetData; -+ ClientboundContainerSetDataPacket.STREAM_CODEC.encode(buf, (ClientboundContainerSetDataPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:container_set_slot" -> { -+ type = PacketType.ClientboundContainerSetSlot; -+ ClientboundContainerSetSlotPacket.STREAM_CODEC.encode(buf, (ClientboundContainerSetSlotPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:cooldown" -> { -+ type = PacketType.ClientboundCooldown; -+ ClientboundCooldownPacket.STREAM_CODEC.encode(buf, (ClientboundCooldownPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:custom_chat_completions" -> { -+ type = PacketType.ClientboundCustomChatCompletions; -+ ClientboundCustomChatCompletionsPacket.STREAM_CODEC.encode(buf, (ClientboundCustomChatCompletionsPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:damage_event" -> { -+ type = PacketType.ClientboundDamageEvent; -+ ClientboundDamageEventPacket.STREAM_CODEC.encode(buf, (ClientboundDamageEventPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:debug_sample" -> { -+ type = PacketType.ClientboundDebugSample; -+ ClientboundDebugSamplePacket.STREAM_CODEC.encode(buf, (ClientboundDebugSamplePacket) nmsPacket); -+ } -+ case "clientbound/minecraft:delete_chat" -> { -+ type = PacketType.ClientboundDeleteChat; -+ ClientboundDeleteChatPacket.STREAM_CODEC.encode(buf, (ClientboundDeleteChatPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:disguised_chat" -> { -+ type = PacketType.ClientboundDisguisedChat; -+ ClientboundDisguisedChatPacket.STREAM_CODEC.encode(buf, (ClientboundDisguisedChatPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:entity_event" -> { -+ type = PacketType.ClientboundEntityEvent; -+ ClientboundEntityEventPacket.STREAM_CODEC.encode(buf, (ClientboundEntityEventPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:explode" -> { -+ type = PacketType.ClientboundExplode; -+ ClientboundExplodePacket.STREAM_CODEC.encode(buf, (ClientboundExplodePacket) nmsPacket); -+ } -+ case "clientbound/minecraft:forget_level_chunk" -> { -+ type = PacketType.ClientboundForgetLevelChunk; -+ ClientboundForgetLevelChunkPacket.STREAM_CODEC.encode(buf, (ClientboundForgetLevelChunkPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:game_event" -> { -+ type = PacketType.ClientboundGameEvent; -+ ClientboundGameEventPacket.STREAM_CODEC.encode(buf, (ClientboundGameEventPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:horse_screen_open" -> { -+ type = PacketType.ClientboundHorseScreenOpen; -+ ClientboundHorseScreenOpenPacket.STREAM_CODEC.encode(buf, (ClientboundHorseScreenOpenPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:hurt_animation" -> { -+ type = PacketType.ClientboundHurtAnimation; -+ ClientboundHurtAnimationPacket.STREAM_CODEC.encode(buf, (ClientboundHurtAnimationPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:initialize_border" -> { -+ type = PacketType.ClientboundInitializeBorder; -+ ClientboundInitializeBorderPacket.STREAM_CODEC.encode(buf, (ClientboundInitializeBorderPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:level_chunk_with_light" -> { -+ type = PacketType.ClientboundLevelChunkWithLight; -+ ClientboundLevelChunkWithLightPacket.STREAM_CODEC.encode(buf, (ClientboundLevelChunkWithLightPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:level_event" -> { -+ type = PacketType.ClientboundLevelEvent; -+ ClientboundLevelEventPacket.STREAM_CODEC.encode(buf, (ClientboundLevelEventPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:level_particles" -> { -+ type = PacketType.ClientboundLevelParticles; -+ ClientboundLevelParticlesPacket.STREAM_CODEC.encode(buf, (ClientboundLevelParticlesPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:light_update" -> { -+ type = PacketType.ClientboundLightUpdate; -+ ClientboundLightUpdatePacket.STREAM_CODEC.encode(buf, (ClientboundLightUpdatePacket) nmsPacket); -+ } -+ case "clientbound/minecraft:login" -> { -+ type = PacketType.ClientboundLogin; -+ ClientboundLoginPacket.STREAM_CODEC.encode(buf, (ClientboundLoginPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:map_item_data" -> { -+ type = PacketType.ClientboundMapItemData; -+ ClientboundMapItemDataPacket.STREAM_CODEC.encode(buf, (ClientboundMapItemDataPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:merchant_offers" -> { -+ type = PacketType.ClientboundMerchantOffers; -+ ClientboundMerchantOffersPacket.STREAM_CODEC.encode(buf, (ClientboundMerchantOffersPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:move_entity_pos" -> { -+ type = PacketType.ClientboundMoveEntityPos; -+ ClientboundMoveEntityPacket.Pos.STREAM_CODEC.encode(buf, (ClientboundMoveEntityPacket.Pos) nmsPacket); -+ } -+ case "clientbound/minecraft:move_entity_pos_rot" -> { -+ type = PacketType.ClientboundMoveEntityPosRot; -+ ClientboundMoveEntityPacket.PosRot.STREAM_CODEC.encode(buf, (ClientboundMoveEntityPacket.PosRot) nmsPacket); -+ } -+ case "clientbound/minecraft:move_entity_rot" -> { -+ type = PacketType.ClientboundMoveEntityRot; -+ ClientboundMoveEntityPacket.Rot.STREAM_CODEC.encode(buf, (ClientboundMoveEntityPacket.Rot) nmsPacket); -+ } -+ case "clientbound/minecraft:move_vehicle" -> { -+ type = PacketType.ClientboundMoveVehicle; -+ ClientboundMoveVehiclePacket.STREAM_CODEC.encode(buf, (ClientboundMoveVehiclePacket) nmsPacket); -+ } -+ case "clientbound/minecraft:open_book" -> { -+ type = PacketType.ClientboundOpenBook; -+ ClientboundOpenBookPacket.STREAM_CODEC.encode(buf, (ClientboundOpenBookPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:open_screen" -> { -+ type = PacketType.ClientboundOpenScreen; -+ ClientboundOpenScreenPacket.STREAM_CODEC.encode(buf, (ClientboundOpenScreenPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:open_sign_editor" -> { -+ type = PacketType.ClientboundOpenSignEditor; -+ ClientboundOpenSignEditorPacket.STREAM_CODEC.encode(buf, (ClientboundOpenSignEditorPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:place_ghost_recipe" -> { -+ type = PacketType.ClientboundPlaceGhostRecipe; -+ ClientboundPlaceGhostRecipePacket.STREAM_CODEC.encode(buf, (ClientboundPlaceGhostRecipePacket) nmsPacket); -+ } -+ case "clientbound/minecraft:player_abilities" -> { -+ type = PacketType.ClientboundPlayerAbilities; -+ ClientboundPlayerAbilitiesPacket.STREAM_CODEC.encode(buf, (ClientboundPlayerAbilitiesPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:player_chat" -> { -+ type = PacketType.ClientboundPlayerChat; -+ ClientboundPlayerChatPacket.STREAM_CODEC.encode(buf, (ClientboundPlayerChatPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:player_combat_end" -> { -+ type = PacketType.ClientboundPlayerCombatEnd; -+ ClientboundPlayerCombatEndPacket.STREAM_CODEC.encode(buf, (ClientboundPlayerCombatEndPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:player_combat_enter" -> { -+ type = PacketType.ClientboundPlayerCombatEnter; -+ ClientboundPlayerCombatEnterPacket.STREAM_CODEC.encode(buf, (ClientboundPlayerCombatEnterPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:player_combat_kill" -> { -+ type = PacketType.ClientboundPlayerCombatKill; -+ ClientboundPlayerCombatKillPacket.STREAM_CODEC.encode(buf, (ClientboundPlayerCombatKillPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:player_info_remove" -> { -+ type = PacketType.ClientboundPlayerInfoRemove; -+ ClientboundPlayerInfoRemovePacket.STREAM_CODEC.encode(buf, (ClientboundPlayerInfoRemovePacket) nmsPacket); -+ } -+ case "clientbound/minecraft:player_info_update" -> { -+ type = PacketType.ClientboundPlayerInfoUpdate; -+ ClientboundPlayerInfoUpdatePacket.STREAM_CODEC.encode(buf, (ClientboundPlayerInfoUpdatePacket) nmsPacket); -+ } -+ case "clientbound/minecraft:player_look_at" -> { -+ type = PacketType.ClientboundPlayerLookAt; -+ ClientboundPlayerLookAtPacket.STREAM_CODEC.encode(buf, (ClientboundPlayerLookAtPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:player_position" -> { -+ type = PacketType.ClientboundPlayerPosition; -+ ClientboundPlayerPositionPacket.STREAM_CODEC.encode(buf, (ClientboundPlayerPositionPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:recipe" -> { -+ type = PacketType.ClientboundRecipe; -+ ClientboundRecipePacket.STREAM_CODEC.encode(buf, (ClientboundRecipePacket) nmsPacket); -+ } -+ case "clientbound/minecraft:remove_entities" -> { -+ type = PacketType.ClientboundRemoveEntities; -+ ClientboundRemoveEntitiesPacket.STREAM_CODEC.encode(buf, (ClientboundRemoveEntitiesPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:remove_mob_effect" -> { -+ type = PacketType.ClientboundRemoveMobEffect; -+ ClientboundRemoveMobEffectPacket.STREAM_CODEC.encode(buf, (ClientboundRemoveMobEffectPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:respawn" -> { -+ type = PacketType.ClientboundRespawn; -+ ClientboundRespawnPacket.STREAM_CODEC.encode(buf, (ClientboundRespawnPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:rotate_head" -> { -+ type = PacketType.ClientboundRotateHead; -+ ClientboundRotateHeadPacket.STREAM_CODEC.encode(buf, (ClientboundRotateHeadPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:section_blocks_update" -> { -+ type = PacketType.ClientboundSectionBlocksUpdate; -+ ClientboundSectionBlocksUpdatePacket.STREAM_CODEC.encode(buf, (ClientboundSectionBlocksUpdatePacket) nmsPacket); -+ } -+ case "clientbound/minecraft:select_advancements_tab" -> { -+ type = PacketType.ClientboundSelectAdvancementsTab; -+ ClientboundSelectAdvancementsTabPacket.STREAM_CODEC.encode(buf, (ClientboundSelectAdvancementsTabPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:server_data" -> { -+ type = PacketType.ClientboundServerData; -+ ClientboundServerDataPacket.STREAM_CODEC.encode(buf, (ClientboundServerDataPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:set_action_bar_text" -> { -+ type = PacketType.ClientboundSetActionBarText; -+ ClientboundSetActionBarTextPacket.STREAM_CODEC.encode(buf, (ClientboundSetActionBarTextPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:set_border_center" -> { -+ type = PacketType.ClientboundSetBorderCenter; -+ ClientboundSetBorderCenterPacket.STREAM_CODEC.encode(buf, (ClientboundSetBorderCenterPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:set_border_lerp_size" -> { -+ type = PacketType.ClientboundSetBorderLerpSize; -+ ClientboundSetBorderLerpSizePacket.STREAM_CODEC.encode(buf, (ClientboundSetBorderLerpSizePacket) nmsPacket); -+ } -+ case "clientbound/minecraft:set_border_size" -> { -+ type = PacketType.ClientboundSetBorderSize; -+ ClientboundSetBorderSizePacket.STREAM_CODEC.encode(buf, (ClientboundSetBorderSizePacket) nmsPacket); -+ } -+ case "clientbound/minecraft:set_border_warning_delay" -> { -+ type = PacketType.ClientboundSetBorderWarningDelay; -+ ClientboundSetBorderWarningDelayPacket.STREAM_CODEC.encode(buf, (ClientboundSetBorderWarningDelayPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:set_border_warning_distance" -> { -+ type = PacketType.ClientboundSetBorderWarningDistance; -+ ClientboundSetBorderWarningDistancePacket.STREAM_CODEC.encode(buf, (ClientboundSetBorderWarningDistancePacket) nmsPacket); -+ } -+ case "clientbound/minecraft:set_camera" -> { -+ type = PacketType.ClientboundSetCamera; -+ ClientboundSetCameraPacket.STREAM_CODEC.encode(buf, (ClientboundSetCameraPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:set_carried_item" -> { -+ type = PacketType.ClientboundSetCarriedItem; -+ ClientboundSetCarriedItemPacket.STREAM_CODEC.encode(buf, (ClientboundSetCarriedItemPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:set_chunk_cache_center" -> { -+ type = PacketType.ClientboundSetChunkCacheCenter; -+ ClientboundSetChunkCacheCenterPacket.STREAM_CODEC.encode(buf, (ClientboundSetChunkCacheCenterPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:set_chunk_cache_radius" -> { -+ type = PacketType.ClientboundSetChunkCacheRadius; -+ ClientboundSetChunkCacheRadiusPacket.STREAM_CODEC.encode(buf, (ClientboundSetChunkCacheRadiusPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:set_default_spawn_position" -> { -+ type = PacketType.ClientboundSetDefaultSpawnPosition; -+ ClientboundSetDefaultSpawnPositionPacket.STREAM_CODEC.encode(buf, (ClientboundSetDefaultSpawnPositionPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:set_display_objective" -> { -+ type = PacketType.ClientboundSetDisplayObjective; -+ ClientboundSetDisplayObjectivePacket.STREAM_CODEC.encode(buf, (ClientboundSetDisplayObjectivePacket) nmsPacket); -+ } -+ case "clientbound/minecraft:set_entity_data" -> { -+ type = PacketType.ClientboundSetEntityData; -+ ClientboundSetEntityDataPacket.STREAM_CODEC.encode(buf, (ClientboundSetEntityDataPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:set_entity_link" -> { -+ type = PacketType.ClientboundSetEntityLink; -+ ClientboundSetEntityLinkPacket.STREAM_CODEC.encode(buf, (ClientboundSetEntityLinkPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:set_entity_motion" -> { -+ type = PacketType.ClientboundSetEntityMotion; -+ ClientboundSetEntityMotionPacket.STREAM_CODEC.encode(buf, (ClientboundSetEntityMotionPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:set_equipment" -> { -+ type = PacketType.ClientboundSetEquipment; -+ ClientboundSetEquipmentPacket.STREAM_CODEC.encode(buf, (ClientboundSetEquipmentPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:set_experience" -> { -+ type = PacketType.ClientboundSetExperience; -+ ClientboundSetExperiencePacket.STREAM_CODEC.encode(buf, (ClientboundSetExperiencePacket) nmsPacket); -+ } -+ case "clientbound/minecraft:set_health" -> { -+ type = PacketType.ClientboundSetHealth; -+ ClientboundSetHealthPacket.STREAM_CODEC.encode(buf, (ClientboundSetHealthPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:set_objective" -> { -+ type = PacketType.ClientboundSetObjective; -+ ClientboundSetObjectivePacket.STREAM_CODEC.encode(buf, (ClientboundSetObjectivePacket) nmsPacket); -+ } -+ case "clientbound/minecraft:set_passengers" -> { -+ type = PacketType.ClientboundSetPassengers; -+ ClientboundSetPassengersPacket.STREAM_CODEC.encode(buf, (ClientboundSetPassengersPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:set_player_team" -> { -+ type = PacketType.ClientboundSetPlayerTeam; -+ ClientboundSetPlayerTeamPacket.STREAM_CODEC.encode(buf, (ClientboundSetPlayerTeamPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:set_score" -> { -+ type = PacketType.ClientboundSetScore; -+ ClientboundSetScorePacket.STREAM_CODEC.encode(buf, (ClientboundSetScorePacket) nmsPacket); -+ } -+ case "clientbound/minecraft:set_simulation_distance" -> { -+ type = PacketType.ClientboundSetSimulationDistance; -+ ClientboundSetSimulationDistancePacket.STREAM_CODEC.encode(buf, (ClientboundSetSimulationDistancePacket) nmsPacket); -+ } -+ case "clientbound/minecraft:set_subtitle_text" -> { -+ type = PacketType.ClientboundSetSubtitleText; -+ ClientboundSetSubtitleTextPacket.STREAM_CODEC.encode(buf, (ClientboundSetSubtitleTextPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:set_time" -> { -+ type = PacketType.ClientboundSetTime; -+ ClientboundSetTimePacket.STREAM_CODEC.encode(buf, (ClientboundSetTimePacket) nmsPacket); -+ } -+ case "clientbound/minecraft:set_title_text" -> { -+ type = PacketType.ClientboundSetTitleText; -+ ClientboundSetTitleTextPacket.STREAM_CODEC.encode(buf, (ClientboundSetTitleTextPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:set_titles_animation" -> { -+ type = PacketType.ClientboundSetTitlesAnimation; -+ ClientboundSetTitlesAnimationPacket.STREAM_CODEC.encode(buf, (ClientboundSetTitlesAnimationPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:sound_entity" -> { -+ type = PacketType.ClientboundSoundEntity; -+ ClientboundSoundEntityPacket.STREAM_CODEC.encode(buf, (ClientboundSoundEntityPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:sound" -> { -+ type = PacketType.ClientboundSound; -+ ClientboundSoundPacket.STREAM_CODEC.encode(buf, (ClientboundSoundPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:start_configuration" -> { -+ type = PacketType.ClientboundStartConfiguration; -+ ClientboundStartConfigurationPacket.STREAM_CODEC.encode(buf, (ClientboundStartConfigurationPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:stop_sound" -> { -+ type = PacketType.ClientboundStopSound; -+ ClientboundStopSoundPacket.STREAM_CODEC.encode(buf, (ClientboundStopSoundPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:system_chat" -> { -+ type = PacketType.ClientboundSystemChat; -+ ClientboundSystemChatPacket.STREAM_CODEC.encode(buf, (ClientboundSystemChatPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:tab_list" -> { -+ type = PacketType.ClientboundTabList; -+ ClientboundTabListPacket.STREAM_CODEC.encode(buf, (ClientboundTabListPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:tag_query" -> { -+ type = PacketType.ClientboundTagQuery; -+ ClientboundTagQueryPacket.STREAM_CODEC.encode(buf, (ClientboundTagQueryPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:take_item_entity" -> { -+ type = PacketType.ClientboundTakeItemEntity; -+ ClientboundTakeItemEntityPacket.STREAM_CODEC.encode(buf, (ClientboundTakeItemEntityPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:teleport_entity" -> { -+ type = PacketType.ClientboundTeleportEntity; -+ ClientboundTeleportEntityPacket.STREAM_CODEC.encode(buf, (ClientboundTeleportEntityPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:update_advancements" -> { -+ type = PacketType.ClientboundUpdateAdvancements; -+ ClientboundUpdateAdvancementsPacket.STREAM_CODEC.encode(buf, (ClientboundUpdateAdvancementsPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:update_attributes" -> { -+ type = PacketType.ClientboundUpdateAttributes; -+ ClientboundUpdateAttributesPacket.STREAM_CODEC.encode(buf, (ClientboundUpdateAttributesPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:update_mob_effect" -> { -+ type = PacketType.ClientboundUpdateMobEffect; -+ ClientboundUpdateMobEffectPacket.STREAM_CODEC.encode(buf, (ClientboundUpdateMobEffectPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:update_recipes" -> { -+ type = PacketType.ClientboundUpdateRecipes; -+ ClientboundUpdateRecipesPacket.STREAM_CODEC.encode(buf, (ClientboundUpdateRecipesPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:projectile_power" -> { -+ type = PacketType.ClientboundProjectilePower; -+ ClientboundProjectilePowerPacket.STREAM_CODEC.encode(buf, (ClientboundProjectilePowerPacket) nmsPacket); -+ } -+ case "serverbound/minecraft:accept_teleportation" -> { -+ type = PacketType.ServerboundAcceptTeleportation; -+ ServerboundAcceptTeleportationPacket.STREAM_CODEC.encode(buf, (ServerboundAcceptTeleportationPacket) nmsPacket); -+ } -+ case "serverbound/minecraft:block_entity_tag_query" -> { -+ type = PacketType.ServerboundBlockEntityTagQuery; -+ ServerboundBlockEntityTagQueryPacket.STREAM_CODEC.encode(buf, (ServerboundBlockEntityTagQueryPacket) nmsPacket); -+ } -+ case "serverbound/minecraft:change_difficulty" -> { -+ type = PacketType.ServerboundChangeDifficulty; -+ ServerboundChangeDifficultyPacket.STREAM_CODEC.encode(buf, (ServerboundChangeDifficultyPacket) nmsPacket); -+ } -+ case "serverbound/minecraft:chat_ack" -> { -+ type = PacketType.ServerboundChatAck; -+ ServerboundChatAckPacket.STREAM_CODEC.encode(buf, (ServerboundChatAckPacket) nmsPacket); -+ } -+ case "serverbound/minecraft:chat_command" -> { -+ type = PacketType.ServerboundChatCommand; -+ ServerboundChatCommandPacket.STREAM_CODEC.encode(buf, (ServerboundChatCommandPacket) nmsPacket); -+ } -+ case "serverbound/minecraft:chat_command_signed" -> { -+ type = PacketType.ServerboundChatCommandSigned; -+ ServerboundChatCommandSignedPacket.STREAM_CODEC.encode(buf, (ServerboundChatCommandSignedPacket) nmsPacket); -+ } -+ case "serverbound/minecraft:chat" -> { -+ type = PacketType.ServerboundChat; -+ ServerboundChatPacket.STREAM_CODEC.encode(buf, (ServerboundChatPacket) nmsPacket); -+ } -+ case "serverbound/minecraft:chat_session_update" -> { -+ type = PacketType.ServerboundChatSessionUpdate; -+ ServerboundChatSessionUpdatePacket.STREAM_CODEC.encode(buf, (ServerboundChatSessionUpdatePacket) nmsPacket); -+ } -+ case "serverbound/minecraft:chunk_batch_received" -> { -+ type = PacketType.ServerboundChunkBatchReceived; -+ ServerboundChunkBatchReceivedPacket.STREAM_CODEC.encode(buf, (ServerboundChunkBatchReceivedPacket) nmsPacket); -+ } -+ case "serverbound/minecraft:client_command" -> { -+ type = PacketType.ServerboundClientCommand; -+ ServerboundClientCommandPacket.STREAM_CODEC.encode(buf, (ServerboundClientCommandPacket) nmsPacket); -+ } -+ case "serverbound/minecraft:command_suggestion" -> { -+ type = PacketType.ServerboundCommandSuggestion; -+ ServerboundCommandSuggestionPacket.STREAM_CODEC.encode(buf, (ServerboundCommandSuggestionPacket) nmsPacket); -+ } -+ case "serverbound/minecraft:configuration_acknowledged" -> { -+ type = PacketType.ServerboundConfigurationAcknowledged; -+ ServerboundConfigurationAcknowledgedPacket.STREAM_CODEC.encode(buf, (ServerboundConfigurationAcknowledgedPacket) nmsPacket); -+ } -+ case "serverbound/minecraft:container_button_click" -> { -+ type = PacketType.ServerboundContainerButtonClick; -+ ServerboundContainerButtonClickPacket.STREAM_CODEC.encode(buf, (ServerboundContainerButtonClickPacket) nmsPacket); -+ } -+ case "serverbound/minecraft:container_click" -> { -+ type = PacketType.ServerboundContainerClick; -+ ServerboundContainerClickPacket.STREAM_CODEC.encode(buf, (ServerboundContainerClickPacket) nmsPacket); -+ } -+ case "serverbound/minecraft:container_close" -> { -+ type = PacketType.ServerboundContainerClose; -+ ServerboundContainerClosePacket.STREAM_CODEC.encode(buf, (ServerboundContainerClosePacket) nmsPacket); -+ } -+ case "serverbound/minecraft:container_slot_state_changed" -> { -+ type = PacketType.ServerboundContainerSlotStateChanged; -+ ServerboundContainerSlotStateChangedPacket.STREAM_CODEC.encode(buf, (ServerboundContainerSlotStateChangedPacket) nmsPacket); -+ } -+ case "serverbound/minecraft:debug_sample_subscription" -> { -+ type = PacketType.ServerboundDebugSampleSubscription; -+ ServerboundDebugSampleSubscriptionPacket.STREAM_CODEC.encode(buf, (ServerboundDebugSampleSubscriptionPacket) nmsPacket); -+ } -+ case "serverbound/minecraft:edit_book" -> { -+ type = PacketType.ServerboundEditBook; -+ ServerboundEditBookPacket.STREAM_CODEC.encode(buf, (ServerboundEditBookPacket) nmsPacket); -+ } -+ case "serverbound/minecraft:entity_tag_query" -> { -+ type = PacketType.ServerboundEntityTagQuery; -+ ServerboundEntityTagQueryPacket.STREAM_CODEC.encode(buf, (ServerboundEntityTagQueryPacket) nmsPacket); -+ } -+ case "serverbound/minecraft:interact" -> { -+ type = PacketType.ServerboundInteract; -+ ServerboundInteractPacket.STREAM_CODEC.encode(buf, (ServerboundInteractPacket) nmsPacket); -+ } -+ case "serverbound/minecraft:jigsaw_generate" -> { -+ type = PacketType.ServerboundJigsawGenerate; -+ ServerboundJigsawGeneratePacket.STREAM_CODEC.encode(buf, (ServerboundJigsawGeneratePacket) nmsPacket); -+ } -+ case "serverbound/minecraft:lock_difficulty" -> { -+ type = PacketType.ServerboundLockDifficulty; -+ ServerboundLockDifficultyPacket.STREAM_CODEC.encode(buf, (ServerboundLockDifficultyPacket) nmsPacket); -+ } -+ case "serverbound/minecraft:move_player_pos" -> { -+ type = PacketType.ServerboundMovePlayerPos; -+ ServerboundMovePlayerPacket.Pos.STREAM_CODEC.encode(buf, (ServerboundMovePlayerPacket.Pos) nmsPacket); -+ } -+ case "serverbound/minecraft:move_player_pos_rot" -> { -+ type = PacketType.ServerboundMovePlayerPosRot; -+ ServerboundMovePlayerPacket.PosRot.STREAM_CODEC.encode(buf, (ServerboundMovePlayerPacket.PosRot) nmsPacket); -+ } -+ case "serverbound/minecraft:move_player_rot" -> { -+ type = PacketType.ServerboundMovePlayerRot; -+ ServerboundMovePlayerPacket.Rot.STREAM_CODEC.encode(buf, (ServerboundMovePlayerPacket.Rot) nmsPacket); -+ } -+ case "serverbound/minecraft:move_player_status_only" -> { -+ type = PacketType.ServerboundMovePlayerStatusOnly; -+ ServerboundMovePlayerPacket.StatusOnly.STREAM_CODEC.encode(buf, (ServerboundMovePlayerPacket.StatusOnly) nmsPacket); -+ } -+ case "serverbound/minecraft:move_vehicle" -> { -+ type = PacketType.ServerboundMoveVehicle; -+ ServerboundMoveVehiclePacket.STREAM_CODEC.encode(buf, (ServerboundMoveVehiclePacket) nmsPacket); -+ } -+ case "serverbound/minecraft:paddle_boat" -> { -+ type = PacketType.ServerboundPaddleBoat; -+ ServerboundPaddleBoatPacket.STREAM_CODEC.encode(buf, (ServerboundPaddleBoatPacket) nmsPacket); -+ } -+ case "serverbound/minecraft:pick_item" -> { -+ type = PacketType.ServerboundPickItem; -+ ServerboundPickItemPacket.STREAM_CODEC.encode(buf, (ServerboundPickItemPacket) nmsPacket); -+ } -+ case "serverbound/minecraft:place_recipe" -> { -+ type = PacketType.ServerboundPlaceRecipe; -+ ServerboundPlaceRecipePacket.STREAM_CODEC.encode(buf, (ServerboundPlaceRecipePacket) nmsPacket); -+ } -+ case "serverbound/minecraft:player_abilities" -> { -+ type = PacketType.ServerboundPlayerAbilities; -+ ServerboundPlayerAbilitiesPacket.STREAM_CODEC.encode(buf, (ServerboundPlayerAbilitiesPacket) nmsPacket); -+ } -+ case "serverbound/minecraft:player_action" -> { -+ type = PacketType.ServerboundPlayerAction; -+ ServerboundPlayerActionPacket.STREAM_CODEC.encode(buf, (ServerboundPlayerActionPacket) nmsPacket); -+ } -+ case "serverbound/minecraft:player_command" -> { -+ type = PacketType.ServerboundPlayerCommand; -+ ServerboundPlayerCommandPacket.STREAM_CODEC.encode(buf, (ServerboundPlayerCommandPacket) nmsPacket); -+ } -+ case "serverbound/minecraft:player_input" -> { -+ type = PacketType.ServerboundPlayerInput; -+ ServerboundPlayerInputPacket.STREAM_CODEC.encode(buf, (ServerboundPlayerInputPacket) nmsPacket); -+ } -+ case "serverbound/minecraft:recipe_book_change_settings" -> { -+ type = PacketType.ServerboundRecipeBookChangeSettings; -+ ServerboundRecipeBookChangeSettingsPacket.STREAM_CODEC.encode(buf, (ServerboundRecipeBookChangeSettingsPacket) nmsPacket); -+ } -+ case "serverbound/minecraft:recipe_book_seen_recipe" -> { -+ type = PacketType.ServerboundRecipeBookSeenRecipe; -+ ServerboundRecipeBookSeenRecipePacket.STREAM_CODEC.encode(buf, (ServerboundRecipeBookSeenRecipePacket) nmsPacket); -+ } -+ case "serverbound/minecraft:rename_item" -> { -+ type = PacketType.ServerboundRenameItem; -+ ServerboundRenameItemPacket.STREAM_CODEC.encode(buf, (ServerboundRenameItemPacket) nmsPacket); -+ } -+ case "serverbound/minecraft:seen_advancements" -> { -+ type = PacketType.ServerboundSeenAdvancements; -+ ServerboundSeenAdvancementsPacket.STREAM_CODEC.encode(buf, (ServerboundSeenAdvancementsPacket) nmsPacket); -+ } -+ case "serverbound/minecraft:select_trade" -> { -+ type = PacketType.ServerboundSelectTrade; -+ ServerboundSelectTradePacket.STREAM_CODEC.encode(buf, (ServerboundSelectTradePacket) nmsPacket); -+ } -+ case "serverbound/minecraft:set_beacon" -> { -+ type = PacketType.ServerboundSetBeacon; -+ ServerboundSetBeaconPacket.STREAM_CODEC.encode(buf, (ServerboundSetBeaconPacket) nmsPacket); -+ } -+ case "serverbound/minecraft:set_carried_item" -> { -+ type = PacketType.ServerboundSetCarriedItem; -+ ServerboundSetCarriedItemPacket.STREAM_CODEC.encode(buf, (ServerboundSetCarriedItemPacket) nmsPacket); -+ } -+ case "serverbound/minecraft:set_command_block" -> { -+ type = PacketType.ServerboundSetCommandBlock; -+ ServerboundSetCommandBlockPacket.STREAM_CODEC.encode(buf, (ServerboundSetCommandBlockPacket) nmsPacket); -+ } -+ case "serverbound/minecraft:set_command_minecart" -> { -+ type = PacketType.ServerboundSetCommandMinecart; -+ ServerboundSetCommandMinecartPacket.STREAM_CODEC.encode(buf, (ServerboundSetCommandMinecartPacket) nmsPacket); -+ } -+ case "serverbound/minecraft:set_creative_mode_slot" -> { -+ type = PacketType.ServerboundSetCreativeModeSlot; -+ ServerboundSetCreativeModeSlotPacket.STREAM_CODEC.encode(buf, (ServerboundSetCreativeModeSlotPacket) nmsPacket); -+ } -+ case "serverbound/minecraft:set_jigsaw_block" -> { -+ type = PacketType.ServerboundSetJigsawBlock; -+ ServerboundSetJigsawBlockPacket.STREAM_CODEC.encode(buf, (ServerboundSetJigsawBlockPacket) nmsPacket); -+ } -+ case "serverbound/minecraft:set_structure_block" -> { -+ type = PacketType.ServerboundSetStructureBlock; -+ ServerboundSetStructureBlockPacket.STREAM_CODEC.encode(buf, (ServerboundSetStructureBlockPacket) nmsPacket); -+ } -+ case "serverbound/minecraft:sign_update" -> { -+ type = PacketType.ServerboundSignUpdate; -+ ServerboundSignUpdatePacket.STREAM_CODEC.encode(buf, (ServerboundSignUpdatePacket) nmsPacket); -+ } -+ case "serverbound/minecraft:swing" -> { -+ type = PacketType.ServerboundSwing; -+ ServerboundSwingPacket.STREAM_CODEC.encode(buf, (ServerboundSwingPacket) nmsPacket); -+ } -+ case "serverbound/minecraft:teleport_to_entity" -> { -+ type = PacketType.ServerboundTeleportToEntity; -+ ServerboundTeleportToEntityPacket.STREAM_CODEC.encode(buf, (ServerboundTeleportToEntityPacket) nmsPacket); -+ } -+ case "serverbound/minecraft:use_item_on" -> { -+ type = PacketType.ServerboundUseItemOn; -+ ServerboundUseItemOnPacket.STREAM_CODEC.encode(buf, (ServerboundUseItemOnPacket) nmsPacket); -+ } -+ case "serverbound/minecraft:use_item" -> { -+ type = PacketType.ServerboundUseItem; -+ ServerboundUseItemPacket.STREAM_CODEC.encode(buf, (ServerboundUseItemPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:reset_score" -> { -+ type = PacketType.ClientboundResetScore; -+ ClientboundResetScorePacket.STREAM_CODEC.encode(buf, (ClientboundResetScorePacket) nmsPacket); -+ } -+ case "clientbound/minecraft:ticking_state" -> { -+ type = PacketType.ClientboundTickingState; -+ ClientboundTickingStatePacket.STREAM_CODEC.encode(buf, (ClientboundTickingStatePacket) nmsPacket); -+ } -+ case "clientbound/minecraft:ticking_step" -> { -+ type = PacketType.ClientboundTickingStep; -+ ClientboundTickingStepPacket.STREAM_CODEC.encode(buf, (ClientboundTickingStepPacket) nmsPacket); -+ } -+ /* -+ case "clientbound/minecraft:custom_payload" -> { -+ type = PacketType.ClientboundCustomPayload; -+ ClientboundCustomPayloadPacket.STREAM_CODEC.encode(buf, (ClientboundCustomPayloadPacket) nmsPacket); -+ } -+ -+ */ -+ case "clientbound/minecraft:disconnect" -> { -+ type = PacketType.ClientboundDisconnect; -+ ClientboundDisconnectPacket.STREAM_CODEC.encode(buf, (ClientboundDisconnectPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:keep_alive" -> { -+ type = PacketType.ClientboundKeepAlive; -+ ClientboundKeepAlivePacket.STREAM_CODEC.encode(buf, (ClientboundKeepAlivePacket) nmsPacket); -+ } -+ case "clientbound/minecraft:resource_pack_pop" -> { -+ type = PacketType.ClientboundResourcePackPop; -+ ClientboundResourcePackPopPacket.STREAM_CODEC.encode(buf, (ClientboundResourcePackPopPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:resource_pack_push" -> { -+ type = PacketType.ClientboundResourcePackPush; -+ ClientboundResourcePackPushPacket.STREAM_CODEC.encode(buf, (ClientboundResourcePackPushPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:store_cookie" -> { -+ type = PacketType.ClientboundStoreCookie; -+ ClientboundStoreCookiePacket.STREAM_CODEC.encode(buf, (ClientboundStoreCookiePacket) nmsPacket); -+ } -+ case "clientbound/minecraft:transfer" -> { -+ type = PacketType.ClientboundTransfer; -+ ClientboundTransferPacket.STREAM_CODEC.encode(buf, (ClientboundTransferPacket) nmsPacket); -+ } -+ case "clientbound/minecraft:update_tags" -> { -+ type = PacketType.ClientboundUpdateTags; -+ ClientboundUpdateTagsPacket.STREAM_CODEC.encode(buf, (ClientboundUpdateTagsPacket) nmsPacket); -+ } -+ case "serverbound/minecraft:client_information" -> { -+ type = PacketType.ServerboundClientInformation; -+ ServerboundClientInformationPacket.STREAM_CODEC.encode(buf, (ServerboundClientInformationPacket) nmsPacket); -+ } -+ case "serverbound/minecraft:custom_payload" -> { -+ type = PacketType.ServerboundCustomPayload; -+ ServerboundCustomPayloadPacket.STREAM_CODEC.encode(buf, (ServerboundCustomPayloadPacket) nmsPacket); -+ } -+ case "serverbound/minecraft:keep_alive" -> { -+ type = PacketType.ServerboundKeepAlive; -+ ServerboundKeepAlivePacket.STREAM_CODEC.encode(buf, (ServerboundKeepAlivePacket) nmsPacket); -+ } -+ case "serverbound/minecraft:pong" -> { -+ type = PacketType.ServerboundPong; -+ ServerboundPongPacket.STREAM_CODEC.encode(buf, (ServerboundPongPacket) nmsPacket); -+ } -+ case "serverbound/minecraft:resource_pack" -> { -+ type = PacketType.ServerboundResourcePack; -+ ServerboundResourcePackPacket.STREAM_CODEC.encode(buf, (ServerboundResourcePackPacket) nmsPacket); -+ } -+ default -> throw new UnsupportedOperationException("This feature is not completely finished yet, packet " + nmsPacket + " is not supported temporary."); ++ StreamCodec> codec = type2CodecMap.get(type); ++ if (codec == null) { ++ throw new UnsupportedOperationException("This feature is not completely finished yet, packet type " + type + " is not supported temporary."); + } ++ codec.encode(buf, nmsPacket); + return new Packet(type, Bytebuf.of(buf.array())); + } +} From 29f52dd2bc90cccfa4099479e67562d9f314dd26 Mon Sep 17 00:00:00 2001 From: violetc <58360096+s-yh-china@users.noreply.github.com> Date: Sat, 25 May 2024 02:09:36 +0800 Subject: [PATCH 9/9] Better --- ...tebuf-API.patch => 0010-Bytebuf-API.patch} | 73 ++++-- .../0010-Placeholder-for-Bytebuf-API.patch | 15 -- patches/server/0135-Bytebuf-API.patch | 222 ++++++++++++++---- 3 files changed, 227 insertions(+), 83 deletions(-) rename patches/api/{0011-Bytebuf-API.patch => 0010-Bytebuf-API.patch} (87%) delete mode 100644 patches/api/0010-Placeholder-for-Bytebuf-API.patch diff --git a/patches/api/0011-Bytebuf-API.patch b/patches/api/0010-Bytebuf-API.patch similarity index 87% rename from patches/api/0011-Bytebuf-API.patch rename to patches/api/0010-Bytebuf-API.patch index e3d75bbb..d09af222 100644 --- a/patches/api/0011-Bytebuf-API.patch +++ b/patches/api/0010-Bytebuf-API.patch @@ -5,58 +5,65 @@ Subject: [PATCH] Bytebuf API diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java -index 3c2b252243c1fa0d3adcc9c860c24af73165de33..acb3d0bb285b489f19fc7b1743f0b8f8f7ff1fbc 100644 +index 3c2b252243c1fa0d3adcc9c860c24af73165de33..1caffc8771680505be1c51a2f5050528435cdc33 100644 --- a/src/main/java/org/bukkit/Bukkit.java +++ b/src/main/java/org/bukkit/Bukkit.java -@@ -2918,6 +2918,11 @@ public final class Bukkit { - return server.getPhotographerManager(); +@@ -2919,6 +2919,12 @@ public final class Bukkit { } // Leaves end - Photographer API + + // Leaves start - Bytebuf API + public static org.leavesmc.leaves.bytebuf.BytebufManager getBytebufManager() { + return server.getBytebufManager(); + } + // Leaves end - Bytebuf API - ++ @NotNull public static Server.Spigot spigot() { + return server.spigot(); diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java -index 4a03044938630e4a0e701bc481f15da5a3323115..66a3de19167e7c1052ae1ed6230aaa250e21503d 100644 +index 4a03044938630e4a0e701bc481f15da5a3323115..7a006d2582cd91b83ab05aeb6d6a6f96b77d2dbc 100644 --- a/src/main/java/org/bukkit/Server.java +++ b/src/main/java/org/bukkit/Server.java -@@ -2564,4 +2564,7 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi +@@ -2564,4 +2564,8 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi // Leaves start - Photographer API @NotNull PhotographerManager getPhotographerManager(); // Leaves end - Photographer API ++ + // Leaves start - Bytebuf API + org.leavesmc.leaves.bytebuf.BytebufManager getBytebufManager(); + // Leaves end - Bytebuf API } diff --git a/src/main/java/org/bukkit/entity/Player.java b/src/main/java/org/bukkit/entity/Player.java -index 6c327a07bf8a6aa11a2d7dad12b2830acc539484..939bdc02b917ad72a8b7e6640067da1966337e2a 100644 +index 6c327a07bf8a6aa11a2d7dad12b2830acc539484..e3e4bed888133422bd879479793a01eadbdef85e 100644 --- a/src/main/java/org/bukkit/entity/Player.java +++ b/src/main/java/org/bukkit/entity/Player.java -@@ -3801,7 +3801,10 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM - */ +@@ -3802,6 +3802,12 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM boolean isChunkSent(long chunkKey); // Paper end -- + + // Leaves start - Bytebuf API + void sendPacket(org.leavesmc.leaves.bytebuf.packet.Packet packet); ++ + void sendPacket(org.leavesmc.leaves.bytebuf.Bytebuf buf, org.leavesmc.leaves.bytebuf.packet.PacketType type); + // Leaves end - Bytebuf API ++ @NotNull @Override Spigot spigot(); diff --git a/src/main/java/org/leavesmc/leaves/bytebuf/Bytebuf.java b/src/main/java/org/leavesmc/leaves/bytebuf/Bytebuf.java new file mode 100644 -index 0000000000000000000000000000000000000000..f0f28cfdfc61e6dd6e91e68dfa8c2742e391feef +index 0000000000000000000000000000000000000000..657eee1d4a18f765480135ef50f5ef65fdc3ed28 --- /dev/null +++ b/src/main/java/org/leavesmc/leaves/bytebuf/Bytebuf.java -@@ -0,0 +1,66 @@ +@@ -0,0 +1,102 @@ +package org.leavesmc.leaves.bytebuf; + ++import com.google.gson.JsonElement; +import org.bukkit.Bukkit; ++import org.bukkit.inventory.ItemStack; ++ ++import java.util.UUID; + +public interface Bytebuf { + @@ -96,6 +103,14 @@ index 0000000000000000000000000000000000000000..f0f28cfdfc61e6dd6e91e68dfa8c2742 + + boolean readBoolean(); + ++ Bytebuf writeFloat(float f); ++ ++ float readFloat(); ++ ++ Bytebuf writeDouble(double d); ++ ++ double readDouble(); ++ + Bytebuf writeShort(int i); + + short readShort(); @@ -108,6 +123,22 @@ index 0000000000000000000000000000000000000000..f0f28cfdfc61e6dd6e91e68dfa8c2742 + + long readLong(); + ++ Bytebuf writeVarInt(int i); ++ ++ int readVarInt(); ++ ++ Bytebuf writeVarLong(long i); ++ ++ long readVarLong(); ++ ++ Bytebuf writeUUID(UUID uuid); ++ ++ UUID readUUID(); ++ ++ Bytebuf writeEnum(Enum instance); ++ ++ > T readEnum(Class enumClass); ++ + Bytebuf writeUTFString(String utf); + + String readUTFString(); @@ -116,9 +147,17 @@ index 0000000000000000000000000000000000000000..f0f28cfdfc61e6dd6e91e68dfa8c2742 + + String readComponentPlain(); + -+ Bytebuf writeComponentJson(String json); ++ Bytebuf writeComponentJson(JsonElement json); ++ ++ JsonElement readComponentJson(); ++ ++ Bytebuf writeItemStack(ItemStack itemStack); ++ ++ ItemStack readItemStack(); ++ ++ Bytebuf copy(); + -+ String readComponentJson(); ++ boolean release(); +} diff --git a/src/main/java/org/leavesmc/leaves/bytebuf/BytebufManager.java b/src/main/java/org/leavesmc/leaves/bytebuf/BytebufManager.java new file mode 100644 @@ -171,15 +210,15 @@ index 0000000000000000000000000000000000000000..e246c0a8725fa3b2be065433652a19a5 +} diff --git a/src/main/java/org/leavesmc/leaves/bytebuf/packet/PacketType.java b/src/main/java/org/leavesmc/leaves/bytebuf/packet/PacketType.java new file mode 100644 -index 0000000000000000000000000000000000000000..604a65efc497267db126c6585f806d98bb5783a1 +index 0000000000000000000000000000000000000000..4fd80d703653b8fb2f2bec329b1c5d04ae419d2d --- /dev/null +++ b/src/main/java/org/leavesmc/leaves/bytebuf/packet/PacketType.java @@ -0,0 +1,180 @@ +package org.leavesmc.leaves.bytebuf.packet; + +public enum PacketType { -+ //ClientboundBundle, -+ //ClientboundBundleDelimiter, ++ // ClientboundBundle, ++ // ClientboundBundleDelimiter, + ClientboundAddEntity, + ClientboundAddExperienceOrb, + ClientboundAnimate, diff --git a/patches/api/0010-Placeholder-for-Bytebuf-API.patch b/patches/api/0010-Placeholder-for-Bytebuf-API.patch deleted file mode 100644 index 4a069c17..00000000 --- a/patches/api/0010-Placeholder-for-Bytebuf-API.patch +++ /dev/null @@ -1,15 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: MC_XiaoHei -Date: Sat, 11 May 2024 00:00:18 +0800 -Subject: [PATCH] Placeholder for Bytebuf-API - - -diff --git a/.gitignore b/.gitignore -index 97e78e27ee0eea2c8b24886eeb19164d552323fe..9764fa643039f215627c20a33ca70c9e36b2d599 100644 ---- a/.gitignore -+++ b/.gitignore -@@ -38,3 +38,4 @@ - # vs code - /.vscode - /.factorypath -+ diff --git a/patches/server/0135-Bytebuf-API.patch b/patches/server/0135-Bytebuf-API.patch index 088f8278..d7ac29fa 100644 --- a/patches/server/0135-Bytebuf-API.patch +++ b/patches/server/0135-Bytebuf-API.patch @@ -4,21 +4,38 @@ Date: Wed, 22 May 2024 10:12:22 +0800 Subject: [PATCH] Bytebuf API +diff --git a/src/main/java/net/minecraft/network/chat/Component.java b/src/main/java/net/minecraft/network/chat/Component.java +index 6dcade427f19771b08e04cfa036dedcfac30b5cd..3306d9f5aefe5863cff79374c75cc309c1699c3f 100644 +--- a/src/main/java/net/minecraft/network/chat/Component.java ++++ b/src/main/java/net/minecraft/network/chat/Component.java +@@ -291,7 +291,7 @@ public interface Component extends Message, FormattedText, Iterable { + return (MutableComponent) ComponentSerialization.CODEC.parse(registries.createSerializationContext(JsonOps.INSTANCE), json).getOrThrow(JsonParseException::new); + } + +- static JsonElement serialize(Component text, HolderLookup.Provider registries) { ++ public static JsonElement serialize(Component text, HolderLookup.Provider registries) { // Leaves - package -> public + return (JsonElement) ComponentSerialization.CODEC.encodeStart(registries.createSerializationContext(JsonOps.INSTANCE), text).getOrThrow(JsonParseException::new); + } + diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java -index 975062e67278614220eab0c301019a235c7953b7..c7623096107a2fd7efd54146b952669fc627a149 100644 +index 975062e67278614220eab0c301019a235c7953b7..810d92c033b556e8ae3a5e133a4e471e561eef2c 100644 --- a/src/main/java/net/minecraft/server/players/PlayerList.java +++ b/src/main/java/net/minecraft/server/players/PlayerList.java -@@ -469,7 +469,7 @@ public abstract class PlayerList { - if (!player.connection.isAcceptingMessages()) { +@@ -470,6 +470,12 @@ public abstract class PlayerList { return; } -- -+ getServer().server.getBytebufHandler().injectPlayer(player); + ++ // Leaves start - Bytebuf API ++ if (!(player instanceof ServerBot)) { ++ this.cserver.getBytebufHandler().injectPlayer(player); ++ } ++ // Leaves end - Bytebuf API ++ org.leavesmc.leaves.protocol.core.LeavesProtocolManager.handlePlayerJoin(player); // Leaves - protocol // Leaves start - bot support diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java -index 405a04f2711e26e22d7dd091745b5b5a01d724d9..dea7f028f0bd81e0811f37ce226da50dd4ed158b 100644 +index 405a04f2711e26e22d7dd091745b5b5a01d724d9..68a0a3a792c998a9cc67ec4269e8821817394cfa 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -307,6 +307,7 @@ public final class CraftServer implements Server { @@ -29,36 +46,40 @@ index 405a04f2711e26e22d7dd091745b5b5a01d724d9..dea7f028f0bd81e0811f37ce226da50d // Paper start - Folia region threading API private final io.papermc.paper.threadedregions.scheduler.FallbackRegionScheduler regionizedScheduler = new io.papermc.paper.threadedregions.scheduler.FallbackRegionScheduler(); -@@ -3291,4 +3292,13 @@ public final class CraftServer implements Server { +@@ -3291,4 +3292,15 @@ public final class CraftServer implements Server { return photographerManager; } // Leaves end - replay mod api ++ + // Leaves start - Bytebuf API + @Override + public org.leavesmc.leaves.bytebuf.BytebufManager getBytebufManager() { + return internalBytebufHandler.getManager(); + } ++ + public org.leavesmc.leaves.bytebuf.internal.InternalBytebufHandler getBytebufHandler() { + return internalBytebufHandler; + } + // Leaves end - Bytebuf API } diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java -index 25a5ce110c0515f5a0ee5f287a7f3dd029a8f29f..1eb60f1d9bec4b11bb1d0242266d6e084e53b372 100644 +index 25a5ce110c0515f5a0ee5f287a7f3dd029a8f29f..fb65a871d7cff135f0c8bc262b0666a3556fbfb0 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java -@@ -3519,4 +3519,14 @@ public class CraftPlayer extends CraftHumanEntity implements Player { +@@ -3519,4 +3519,16 @@ public class CraftPlayer extends CraftHumanEntity implements Player { public void setSendViewDistance(final int viewDistance) { this.getHandle().setSendViewDistance(viewDistance); } ++ + // Leaves start - Bytebuf API + @Override + public void sendPacket(org.leavesmc.leaves.bytebuf.packet.Packet packet) { -+ ((CraftServer) getServer()).getBytebufHandler().applyPacketToPlayer(this, packet); ++ this.server.getBytebufHandler().applyPacketToPlayer(this, packet); + } ++ + @Override + public void sendPacket(org.leavesmc.leaves.bytebuf.Bytebuf bytebuf, org.leavesmc.leaves.bytebuf.packet.PacketType type) { -+ ((CraftServer) getServer()).getBytebufHandler().applyPacketToPlayer(this, new org.leavesmc.leaves.bytebuf.packet.Packet(type, bytebuf)); ++ this.server.getBytebufHandler().applyPacketToPlayer(this, new org.leavesmc.leaves.bytebuf.packet.Packet(type, bytebuf)); + } + // Leaves end - Bytebuf API } @@ -105,30 +126,37 @@ index 0000000000000000000000000000000000000000..443f7f6e0b8d40eaafb8009b3b7e405c +} diff --git a/src/main/java/org/leavesmc/leaves/bytebuf/WrappedBytebuf.java b/src/main/java/org/leavesmc/leaves/bytebuf/WrappedBytebuf.java new file mode 100644 -index 0000000000000000000000000000000000000000..1f4aca3138487ef69e674d27a6bbba033e56c4f1 +index 0000000000000000000000000000000000000000..d9277d14b8df71600196ab434b0d4c7f549eb84b --- /dev/null +++ b/src/main/java/org/leavesmc/leaves/bytebuf/WrappedBytebuf.java -@@ -0,0 +1,163 @@ +@@ -0,0 +1,255 @@ +package org.leavesmc.leaves.bytebuf; + ++import com.google.gson.JsonElement; +import io.netty.buffer.ByteBuf; -+import io.netty.buffer.Unpooled; +import net.minecraft.core.RegistryAccess; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.ComponentSerialization; ++import net.minecraft.server.MinecraftServer; ++import org.bukkit.inventory.ItemStack; ++import org.bukkit.craftbukkit.inventory.CraftItemStack; ++ ++import java.util.UUID; + +public class WrappedBytebuf implements Bytebuf { + + private final FriendlyByteBuf buf; ++ private final RegistryFriendlyByteBuf registryBuf; + + public WrappedBytebuf(ByteBuf buf) { + this.buf = new FriendlyByteBuf(buf); ++ this.registryBuf = new RegistryFriendlyByteBuf(this.buf, MinecraftServer.getServer().registryAccess()); + } + -+ public FriendlyByteBuf getFriendlyBytebuf() { -+ return buf; ++ public RegistryFriendlyByteBuf getRegistryBuf() { ++ return registryBuf; + } + + @Override @@ -199,6 +227,28 @@ index 0000000000000000000000000000000000000000..1f4aca3138487ef69e674d27a6bbba03 + } + + @Override ++ public Bytebuf writeFloat(float f) { ++ buf.writeFloat(f); ++ return this; ++ } ++ ++ @Override ++ public float readFloat() { ++ return buf.readFloat(); ++ } ++ ++ @Override ++ public Bytebuf writeDouble(double d) { ++ buf.writeDouble(d); ++ return this; ++ } ++ ++ @Override ++ public double readDouble() { ++ return buf.readDouble(); ++ } ++ ++ @Override + public Bytebuf writeShort(int i) { + buf.writeShort(i); + return this; @@ -232,6 +282,50 @@ index 0000000000000000000000000000000000000000..1f4aca3138487ef69e674d27a6bbba03 + } + + @Override ++ public Bytebuf writeVarInt(int i) { ++ this.buf.writeVarInt(i); ++ return this; ++ } ++ ++ @Override ++ public int readVarInt() { ++ return this.buf.readVarInt(); ++ } ++ ++ @Override ++ public Bytebuf writeVarLong(long i) { ++ this.buf.writeVarLong(i); ++ return this; ++ } ++ ++ @Override ++ public long readVarLong() { ++ return this.buf.readVarLong(); ++ } ++ ++ @Override ++ public Bytebuf writeUUID(UUID uuid) { ++ this.buf.writeUUID(uuid); ++ return this; ++ } ++ ++ @Override ++ public UUID readUUID() { ++ return this.buf.readUUID(); ++ } ++ ++ @Override ++ public Bytebuf writeEnum(Enum instance) { ++ this.buf.writeEnum(instance); ++ return this; ++ } ++ ++ @Override ++ public > T readEnum(Class enumClass) { ++ return this.buf.readEnum(enumClass); ++ } ++ ++ @Override + public Bytebuf writeUTFString(String utf) { + buf.writeUtf(utf); + return this; @@ -244,9 +338,7 @@ index 0000000000000000000000000000000000000000..1f4aca3138487ef69e674d27a6bbba03 + + @Override + public Bytebuf writeComponentPlain(String str) { -+ RegistryFriendlyByteBuf regBuf = new RegistryFriendlyByteBuf(Unpooled.buffer(), RegistryAccess.EMPTY); -+ ComponentSerialization.STREAM_CODEC.encode(regBuf, Component.literal(str)); -+ buf.writeBytes(regBuf.array()); ++ ComponentSerialization.STREAM_CODEC.encode(new RegistryFriendlyByteBuf(this.buf, RegistryAccess.EMPTY), Component.literal(str)); + return this; + } + @@ -256,30 +348,53 @@ index 0000000000000000000000000000000000000000..1f4aca3138487ef69e674d27a6bbba03 + } + + @Override -+ public Bytebuf writeComponentJson(String json) { ++ public Bytebuf writeComponentJson(JsonElement json) { + Component component = Component.Serializer.fromJson(json, RegistryAccess.EMPTY); + if (component == null) { -+ throw new IllegalArgumentException("The String " + json + " can not be serialize to Minecraft chat component"); ++ throw new IllegalArgumentException("Null can not be serialize to Minecraft chat component"); + } -+ RegistryFriendlyByteBuf regBuf = new RegistryFriendlyByteBuf(Unpooled.buffer(), RegistryAccess.EMPTY); -+ ComponentSerialization.STREAM_CODEC.encode(regBuf, component); -+ buf.writeBytes(regBuf.array()); ++ ComponentSerialization.STREAM_CODEC.encode(new RegistryFriendlyByteBuf(buf, RegistryAccess.EMPTY), component); ++ return this; ++ } ++ ++ @Override ++ public JsonElement readComponentJson() { ++ return Component.Serializer.serialize(ComponentSerialization.STREAM_CODEC.decode(new RegistryFriendlyByteBuf(buf, RegistryAccess.EMPTY)), RegistryAccess.EMPTY); ++ } ++ ++ @Override ++ public Bytebuf writeItemStack(ItemStack itemStack) { ++ net.minecraft.world.item.ItemStack nmsItem = CraftItemStack.unwrap(itemStack); ++ net.minecraft.world.item.ItemStack.OPTIONAL_STREAM_CODEC.encode(this.registryBuf, nmsItem); + return this; + } + + @Override -+ public String readComponentJson() { -+ return Component.Serializer.toJson(ComponentSerialization.STREAM_CODEC.decode(new RegistryFriendlyByteBuf(buf, RegistryAccess.EMPTY)), RegistryAccess.EMPTY); ++ public ItemStack readItemStack() { ++ net.minecraft.world.item.ItemStack nmsItem = net.minecraft.world.item.ItemStack.OPTIONAL_STREAM_CODEC.decode(this.registryBuf); ++ return nmsItem.asBukkitMirror(); ++ } ++ ++ @Override ++ public Bytebuf copy() { ++ return new WrappedBytebuf(this.buf.copy()); ++ } ++ ++ @Override ++ public boolean release() { ++ return this.buf.release(); + } +} diff --git a/src/main/java/org/leavesmc/leaves/bytebuf/internal/InternalBytebufHandler.java b/src/main/java/org/leavesmc/leaves/bytebuf/internal/InternalBytebufHandler.java new file mode 100644 -index 0000000000000000000000000000000000000000..35d66678dfe391dcde4061775f5735d68a6b8e0f +index 0000000000000000000000000000000000000000..0e8fd87ca5159dd0367f8cc59dd4a3ef13eb37b8 --- /dev/null +++ b/src/main/java/org/leavesmc/leaves/bytebuf/internal/InternalBytebufHandler.java -@@ -0,0 +1,193 @@ +@@ -0,0 +1,200 @@ +package org.leavesmc.leaves.bytebuf.internal; + ++import com.google.common.cache.Cache; ++import com.google.common.cache.CacheBuilder; +import com.google.common.collect.ImmutableMap; +import io.netty.buffer.Unpooled; +import io.netty.channel.ChannelDuplexHandler; @@ -308,12 +423,13 @@ index 0000000000000000000000000000000000000000..35d66678dfe391dcde4061775f5735d6 +import java.lang.reflect.Field; +import java.util.HashMap; +import java.util.Map; ++import java.util.concurrent.ExecutionException; + +import static org.leavesmc.leaves.bytebuf.packet.PacketType.*; + +public class InternalBytebufHandler { + -+ class PacketHandler extends ChannelDuplexHandler { ++ private class PacketHandler extends ChannelDuplexHandler { + + private final static String handlerName = "leaves-bytebuf-handler"; + private final Player player; @@ -359,11 +475,12 @@ index 0000000000000000000000000000000000000000..35d66678dfe391dcde4061775f5735d6 + public final Map listenerMap = new HashMap<>(); + private final BytebufManager manager = new SimpleBytebufManager(this); + private final ImmutableMap type2CodecMap; ++ private final Cache, PacketType> resultCache = CacheBuilder.newBuilder().build(); + + public InternalBytebufHandler() { + ImmutableMap.Builder builder = ImmutableMap.builder(); + for (PacketType packet : PacketType.values()) { -+ Class packetClass = null; ++ Class packetClass; + try { + packetClass = Class.forName("net.minecraft.network.protocol.game." + packet.name() + "Packet"); + } catch (ClassNotFoundException e) { @@ -379,6 +496,7 @@ index 0000000000000000000000000000000000000000..35d66678dfe391dcde4061775f5735d6 + } catch (Exception ignored) { + } + } ++ + builder.put(ClientboundMoveEntityPos, ClientboundMoveEntityPacket.Pos.STREAM_CODEC); + builder.put(ClientboundMoveEntityPosRot, ClientboundMoveEntityPacket.PosRot.STREAM_CODEC); + builder.put(ClientboundMoveEntityRot, ClientboundMoveEntityPacket.Rot.STREAM_CODEC); @@ -386,6 +504,7 @@ index 0000000000000000000000000000000000000000..35d66678dfe391dcde4061775f5735d6 + builder.put(ServerboundMovePlayerPosRot, ServerboundMovePlayerPacket.PosRot.STREAM_CODEC); + builder.put(ServerboundMovePlayerRot, ServerboundMovePlayerPacket.Rot.STREAM_CODEC); + builder.put(ServerboundMovePlayerStatusOnly, ServerboundMovePlayerPacket.StatusOnly.STREAM_CODEC); ++ + type2CodecMap = builder.build(); + } + @@ -427,35 +546,36 @@ index 0000000000000000000000000000000000000000..35d66678dfe391dcde4061775f5735d6 + } + + public net.minecraft.network.protocol.Packet createNMSPacket(Packet packet) { -+ RegistryFriendlyByteBuf buf = new RegistryFriendlyByteBuf(((WrappedBytebuf) packet.bytebuf()).getFriendlyBytebuf(), MinecraftServer.getServer().registryAccess()); + StreamCodec> codec = type2CodecMap.get(packet.type()); + if (codec == null) { + throw new UnsupportedOperationException("This feature is not completely finished yet, packet type " + packet.type() + " is not supported temporary."); + } -+ return codec.decode(buf); ++ return codec.decode(((WrappedBytebuf) packet.bytebuf()).getRegistryBuf()); + } + + private PacketType toEnumType(net.minecraft.network.protocol.PacketType type) { -+ StringBuilder builder = new StringBuilder(); -+ String bound = type.toString().split("/")[0]; -+ String name = type.toString().split(":")[1]; -+ builder.append(bound.substring(0, 1).toUpperCase()).append(bound.substring(1)); -+ boolean flag = true; -+ for (int i = 0; i < name.length(); i++) { -+ if (flag) { -+ builder.append(name.substring(i, i + 1).toUpperCase()); -+ flag = false; -+ continue; -+ } -+ if (name.charAt(i) == '_') { -+ flag = true; -+ } else { -+ builder.append(name.charAt(i)); -+ } -+ } + try { -+ return PacketType.valueOf(builder.toString()); -+ } catch (IllegalArgumentException e) { ++ return this.resultCache.get(type, () -> { ++ StringBuilder builder = new StringBuilder(); ++ String bound = type.toString().split("/")[0]; ++ String name = type.toString().split(":")[1]; ++ builder.append(bound.substring(0, 1).toUpperCase()).append(bound.substring(1)); ++ boolean flag = true; ++ for (int i = 0; i < name.length(); i++) { ++ if (flag) { ++ builder.append(name.substring(i, i + 1).toUpperCase()); ++ flag = false; ++ continue; ++ } ++ if (name.charAt(i) == '_') { ++ flag = true; ++ } else { ++ builder.append(name.charAt(i)); ++ } ++ } ++ return PacketType.valueOf(builder.toString()); ++ }); ++ } catch (ExecutionException e) { + throw new RuntimeException(e); + } + }