From 6e55a9016c2b37aa45f6d499675e30aa7ebbf135 Mon Sep 17 00:00:00 2001 From: Moulberry Date: Sat, 4 May 2024 23:13:31 +0800 Subject: [PATCH] Update to 1.20.6 --- build.gradle.kts | 16 +++--- .../java/com/moulberry/axiom/AxiomPaper.java | 49 ++++++++++--------- .../com/moulberry/axiom/VersionHelper.java | 5 +- .../com/moulberry/axiom/WorldExtension.java | 8 +-- .../axiom/blueprint/BlueprintIo.java | 5 +- .../blueprint/ServerBlueprintManager.java | 2 +- .../PlotSquaredIntegrationImpl.java | 12 ++--- .../worldguard/WorldGuardIntegrationImpl.java | 12 ++--- .../BlueprintRequestPacketListener.java | 2 +- .../axiom/packet/CustomByteArrayPayload.java | 12 ----- .../packet/DeleteEntityPacketListener.java | 4 +- .../axiom/packet/HelloPacketListener.java | 16 +++--- .../ManipulateEntityPacketListener.java | 4 +- .../MarkerNbtRequestPacketListener.java | 2 +- .../RequestChunkDataPacketListener.java | 8 +-- .../packet/SetBlockBufferPacketListener.java | 4 +- .../axiom/packet/SetBlockPacketListener.java | 8 +-- .../packet/SetFlySpeedPacketListener.java | 2 +- .../packet/SetGamemodePacketListener.java | 2 +- .../packet/SetHotbarSlotPacketListener.java | 9 ++-- .../axiom/packet/SetTimePacketListener.java | 2 +- .../packet/SpawnEntityPacketListener.java | 4 +- .../SwitchActiveHotbarPacketListener.java | 8 +-- .../axiom/packet/TeleportPacketListener.java | 4 +- .../axiom/persistence/ItemStackDataType.java | 10 ++-- .../WorldPropertyDataType.java | 8 +-- .../server/ServerWorldPropertiesRegistry.java | 2 +- .../server/ServerWorldPropertyBase.java | 2 +- .../server/ServerWorldPropertyHolder.java | 2 +- 29 files changed, 111 insertions(+), 113 deletions(-) delete mode 100644 src/main/java/com/moulberry/axiom/packet/CustomByteArrayPayload.java diff --git a/build.gradle.kts b/build.gradle.kts index c38834c..5235057 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,10 +1,10 @@ plugins { `java-library` - id("io.papermc.paperweight.userdev") version "1.5.11" - id("xyz.jpenilla.run-paper") version "2.2.2" // Adds runServer and runMojangMappedServer tasks for testing + id("io.papermc.paperweight.userdev") version "1.6.3" + id("xyz.jpenilla.run-paper") version "2.2.4" // Adds runServer and runMojangMappedServer tasks for testing // Shades and relocates dependencies into our plugin jar. See https://imperceptiblethoughts.com/shadow/introduction/ - id("com.github.johnrengelman.shadow") version "8.1.1" + id("io.github.goooler.shadow") version "8.1.7" } group = "com.moulberry.axiom" @@ -12,8 +12,8 @@ version = "1.5.9" description = "Serverside component for Axiom on Paper" java { - // Configure the java toolchain. This allows gradle to auto-provision JDK 17 on systems that only have JDK 8 installed for example. - toolchain.languageVersion.set(JavaLanguageVersion.of(17)) + // Configure the java toolchain. This allows gradle to auto-provision JDK 21 on systems that only have JDK 11 installed for example. + toolchain.languageVersion.set(JavaLanguageVersion.of(21)) } repositories { @@ -26,9 +26,9 @@ repositories { } dependencies { - paperweight.paperDevBundle("1.20.4-R0.1-SNAPSHOT") + paperweight.paperDevBundle("1.20.6-R0.1-SNAPSHOT") implementation("xyz.jpenilla:reflection-remapper:0.1.0-SNAPSHOT") - implementation("org.incendo:cloud-paper:2.0.0-beta.2") + implementation("org.incendo:cloud-paper:2.0.0-SNAPSHOT") // Zstd Compression Library implementation("com.github.luben:zstd-jni:1.5.5-4") @@ -56,7 +56,7 @@ tasks { // Set the release flag. This configures what version bytecode the compiler will emit, as well as what JDK APIs are usable. // See https://openjdk.java.net/jeps/247 for more information. - options.release.set(17) + options.release.set(21) } javadoc { options.encoding = Charsets.UTF_8.name() // We want UTF-8 for everything diff --git a/src/main/java/com/moulberry/axiom/AxiomPaper.java b/src/main/java/com/moulberry/axiom/AxiomPaper.java index e0fe969..6c782c6 100644 --- a/src/main/java/com/moulberry/axiom/AxiomPaper.java +++ b/src/main/java/com/moulberry/axiom/AxiomPaper.java @@ -9,6 +9,7 @@ import com.moulberry.axiom.event.AxiomModifyWorldEvent; import com.moulberry.axiom.integration.plotsquared.PlotSquaredIntegration; import com.moulberry.axiom.packet.*; import com.moulberry.axiom.world_properties.server.ServerWorldPropertiesRegistry; +import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.Channel; import io.papermc.paper.event.player.PlayerFailMoveEvent; @@ -18,12 +19,15 @@ import io.papermc.paper.network.ChannelInitializeListenerHolder; import net.kyori.adventure.key.Key; import net.minecraft.core.BlockPos; import net.minecraft.core.IdMapper; -import net.minecraft.network.Connection; -import net.minecraft.network.ConnectionProtocol; -import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.*; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.PacketFlow; import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; +import net.minecraft.network.protocol.common.custom.DiscardedPayload; +import net.minecraft.network.protocol.game.GameProtocols; +import net.minecraft.network.protocol.game.ServerGamePacketListener; +import net.minecraft.resources.ResourceLocation; import net.minecraft.server.MinecraftServer; import net.minecraft.world.level.block.state.BlockState; import org.bukkit.*; @@ -159,21 +163,16 @@ public class AxiomPaper extends JavaPlugin implements Listener { RequestChunkDataPacketListener requestChunkDataPacketListener = allowLargeChunkDataRequest ? new RequestChunkDataPacketListener(this) : null; + // Hack to figure out the id of the CustomPayload packet + ProtocolInfo protocol = GameProtocols.SERVERBOUND.bind(k -> new RegistryFriendlyByteBuf(k, + MinecraftServer.getServer().registryAccess())); + RegistryFriendlyByteBuf friendlyByteBuf = new RegistryFriendlyByteBuf(Unpooled.buffer(), MinecraftServer.getServer().registryAccess()); + protocol.codec().encode(friendlyByteBuf, new ServerboundCustomPayloadPacket(new DiscardedPayload(new ResourceLocation("dummy"), Unpooled.buffer()))); + int payloadId = friendlyByteBuf.readVarInt(); + ChannelInitializeListenerHolder.addListener(Key.key("axiom:handle_big_payload"), new ChannelInitializeListener() { @Override public void afterInitChannel(@NonNull Channel channel) { - var packets = ConnectionProtocol.PLAY.getPacketsByIds(PacketFlow.SERVERBOUND); - int payloadId = -1; - for (Map.Entry>> entry : packets.entrySet()) { - if (entry.getValue() == ServerboundCustomPayloadPacket.class) { - payloadId = entry.getKey(); - break; - } - } - if (payloadId < 0) { - throw new RuntimeException("Failed to find ServerboundCustomPayloadPacket id"); - } - Connection connection = (Connection) channel.pipeline().get("packet_handler"); channel.pipeline().addBefore("decoder", "axiom-big-payload-handler", new AxiomBigPayloadHandler(payloadId, connection, setBlockBufferPacketListener, @@ -285,16 +284,20 @@ public class AxiomPaper extends JavaPlugin implements Listener { WorldExtension.tick(MinecraftServer.getServer(), sendMarkers, maxChunkRelightsPerTick, maxChunkSendsPerTick); }, 1, 1); - PaperCommandManager manager = PaperCommandManager.createNative( - this, - ExecutionCoordinator.simpleCoordinator() - ); + try { + PaperCommandManager manager = PaperCommandManager.createNative( + this, + ExecutionCoordinator.simpleCoordinator() + ); - if (manager.hasCapability(CloudBukkitCapabilities.NATIVE_BRIGADIER)) { - manager.registerBrigadier(); + if (manager.hasCapability(CloudBukkitCapabilities.NATIVE_BRIGADIER)) { + manager.registerBrigadier(); + } + + AxiomDebugCommand.register(this, manager); + } catch (Exception e) { + e.printStackTrace(); } - - AxiomDebugCommand.register(this, manager); } public boolean logLargeBlockBufferChanges() { diff --git a/src/main/java/com/moulberry/axiom/VersionHelper.java b/src/main/java/com/moulberry/axiom/VersionHelper.java index 2729968..902c9f0 100644 --- a/src/main/java/com/moulberry/axiom/VersionHelper.java +++ b/src/main/java/com/moulberry/axiom/VersionHelper.java @@ -1,14 +1,15 @@ package com.moulberry.axiom; -import com.moulberry.axiom.packet.CustomByteArrayPayload; +import io.netty.buffer.Unpooled; import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket; +import net.minecraft.network.protocol.common.custom.DiscardedPayload; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerPlayer; public class VersionHelper { public static void sendCustomPayload(ServerPlayer serverPlayer, ResourceLocation id, byte[] data) { - serverPlayer.connection.send(new ClientboundCustomPayloadPacket(new CustomByteArrayPayload(id, data))); + serverPlayer.connection.send(new ClientboundCustomPayloadPacket(new DiscardedPayload(id, Unpooled.wrappedBuffer(data)))); } } diff --git a/src/main/java/com/moulberry/axiom/WorldExtension.java b/src/main/java/com/moulberry/axiom/WorldExtension.java index 2152bb2..7f610a8 100644 --- a/src/main/java/com/moulberry/axiom/WorldExtension.java +++ b/src/main/java/com/moulberry/axiom/WorldExtension.java @@ -16,8 +16,8 @@ import net.minecraft.world.level.ChunkPos; import net.minecraft.world.level.Level; import net.minecraft.world.level.chunk.LevelChunk; import org.bukkit.World; -import org.bukkit.craftbukkit.v1_20_R3.CraftWorld; -import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer; +import org.bukkit.craftbukkit.CraftWorld; +import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.entity.Player; import java.util.*; @@ -65,7 +65,7 @@ public class WorldExtension { FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer()); buf.writeCollection(markerData, MarkerData::write); - buf.writeCollection(Set.of(), FriendlyByteBuf::writeUUID); + buf.writeCollection(Set.of(), (buffer, uuid) -> buffer.writeUUID(uuid)); byte[] bytes = new byte[buf.writerIndex()]; buf.getBytes(0, bytes); @@ -106,7 +106,7 @@ public class WorldExtension { if (!changedData.isEmpty() || !oldUuids.isEmpty()) { FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer()); buf.writeCollection(changedData, MarkerData::write); - buf.writeCollection(oldUuids, FriendlyByteBuf::writeUUID); + buf.writeCollection(oldUuids, (buffer, uuid) -> buffer.writeUUID(uuid)); byte[] bytes = new byte[buf.writerIndex()]; buf.getBytes(0, bytes); diff --git a/src/main/java/com/moulberry/axiom/blueprint/BlueprintIo.java b/src/main/java/com/moulberry/axiom/blueprint/BlueprintIo.java index 59bb487..01f56df 100644 --- a/src/main/java/com/moulberry/axiom/blueprint/BlueprintIo.java +++ b/src/main/java/com/moulberry/axiom/blueprint/BlueprintIo.java @@ -128,7 +128,7 @@ public class BlueprintIo { CompoundTag blockStates = compoundTag.getCompound("BlockStates"); blockStates = DFUHelper.updatePalettedContainer(blockStates, dataVersion); PalettedContainer container = BLOCK_STATE_CODEC.parse(NbtOps.INSTANCE, blockStates) - .getOrThrow(false, err -> {}); + .getOrThrow(); map.put(BlockPos.asLong(cx, cy, cz), container); } } @@ -205,8 +205,7 @@ public class BlueprintIo { tag.putInt("X", cx); tag.putInt("Y", cy); tag.putInt("Z", cz); - Tag encoded = BlueprintIo.BLOCK_STATE_CODEC.encodeStart(NbtOps.INSTANCE, container) - .getOrThrow(false, err -> {}); + Tag encoded = BlueprintIo.BLOCK_STATE_CODEC.encodeStart(NbtOps.INSTANCE, container).getOrThrow(); tag.put("BlockStates", encoded); savedBlockRegions.add(tag); } diff --git a/src/main/java/com/moulberry/axiom/blueprint/ServerBlueprintManager.java b/src/main/java/com/moulberry/axiom/blueprint/ServerBlueprintManager.java index daec893..d6939cd 100644 --- a/src/main/java/com/moulberry/axiom/blueprint/ServerBlueprintManager.java +++ b/src/main/java/com/moulberry/axiom/blueprint/ServerBlueprintManager.java @@ -6,7 +6,7 @@ import io.netty.buffer.Unpooled; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerPlayer; -import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer; +import org.bukkit.craftbukkit.entity.CraftPlayer; import java.io.BufferedInputStream; import java.io.IOException; diff --git a/src/main/java/com/moulberry/axiom/integration/plotsquared/PlotSquaredIntegrationImpl.java b/src/main/java/com/moulberry/axiom/integration/plotsquared/PlotSquaredIntegrationImpl.java index 87fa49e..d9ea465 100644 --- a/src/main/java/com/moulberry/axiom/integration/plotsquared/PlotSquaredIntegrationImpl.java +++ b/src/main/java/com/moulberry/axiom/integration/plotsquared/PlotSquaredIntegrationImpl.java @@ -220,12 +220,12 @@ public class PlotSquaredIntegrationImpl { BlockVector3 minPoint = region.getMinimumPoint(); BlockVector3 maxPoint = region.getMaximumPoint(); - int minPlotX = Math.max(minPoint.getX(), minX); - int minPlotY = Math.max(minPoint.getY(), minY); - int minPlotZ = Math.max(minPoint.getZ(), minZ); - int maxPlotX = Math.min(maxPoint.getX(), maxX); - int maxPlotY = Math.min(maxPoint.getY(), maxY); - int maxPlotZ = Math.min(maxPoint.getZ(), maxZ); + int minPlotX = Math.max(minPoint.x(), minX); + int minPlotY = Math.max(minPoint.y(), minY); + int minPlotZ = Math.max(minPoint.z(), minZ); + int maxPlotX = Math.min(maxPoint.x(), maxX); + int maxPlotY = Math.min(maxPoint.y(), maxY); + int maxPlotZ = Math.min(maxPoint.z(), maxZ); if (minPlotX > maxPlotX) continue; if (minPlotY > maxPlotY) continue; diff --git a/src/main/java/com/moulberry/axiom/integration/worldguard/WorldGuardIntegrationImpl.java b/src/main/java/com/moulberry/axiom/integration/worldguard/WorldGuardIntegrationImpl.java index 4787e18..1eb3d07 100644 --- a/src/main/java/com/moulberry/axiom/integration/worldguard/WorldGuardIntegrationImpl.java +++ b/src/main/java/com/moulberry/axiom/integration/worldguard/WorldGuardIntegrationImpl.java @@ -122,12 +122,12 @@ public class WorldGuardIntegrationImpl { BlockVector3 regionMin = region.getMinimumPoint(); BlockVector3 regionMax = region.getMaximumPoint(); - int regionMinX = Math.max(regionMin.getX(), cx*16) - minX; - int regionMinY = Math.max(regionMin.getY(), cy*16) - minY; - int regionMinZ = Math.max(regionMin.getZ(), cz*16) - minZ; - int regionMaxX = Math.min(regionMax.getX(), cx*16+15) - minX; - int regionMaxY = Math.min(regionMax.getY(), cy*16+15) - minY; - int regionMaxZ = Math.min(regionMax.getZ(), cz*16+15) - minZ; + int regionMinX = Math.max(regionMin.x(), cx*16) - minX; + int regionMinY = Math.max(regionMin.y(), cy*16) - minY; + int regionMinZ = Math.max(regionMin.z(), cz*16) - minZ; + int regionMaxX = Math.min(regionMax.x(), cx*16+15) - minX; + int regionMaxY = Math.min(regionMax.y(), cy*16+15) - minY; + int regionMaxZ = Math.min(regionMax.z(), cz*16+15) - minZ; Box box = new Box(regionMinX, regionMinY, regionMinZ, regionMaxX, regionMaxY, regionMaxZ); if (value == StateFlag.State.DENY) { diff --git a/src/main/java/com/moulberry/axiom/packet/BlueprintRequestPacketListener.java b/src/main/java/com/moulberry/axiom/packet/BlueprintRequestPacketListener.java index cd23dd3..6d3741e 100644 --- a/src/main/java/com/moulberry/axiom/packet/BlueprintRequestPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/BlueprintRequestPacketListener.java @@ -10,7 +10,7 @@ import net.kyori.adventure.text.Component; import net.minecraft.SharedConstants; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; -import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer; +import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.entity.Player; import org.bukkit.plugin.messaging.PluginMessageListener; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/com/moulberry/axiom/packet/CustomByteArrayPayload.java b/src/main/java/com/moulberry/axiom/packet/CustomByteArrayPayload.java deleted file mode 100644 index cb2bcd7..0000000 --- a/src/main/java/com/moulberry/axiom/packet/CustomByteArrayPayload.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.moulberry.axiom.packet; - -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.network.protocol.common.custom.CustomPacketPayload; -import net.minecraft.resources.ResourceLocation; - -public record CustomByteArrayPayload(ResourceLocation id, byte[] bytes) implements CustomPacketPayload { - @Override - public void write(FriendlyByteBuf buf) { - buf.writeBytes(bytes); - } -} diff --git a/src/main/java/com/moulberry/axiom/packet/DeleteEntityPacketListener.java b/src/main/java/com/moulberry/axiom/packet/DeleteEntityPacketListener.java index 4e60979..bfddcb0 100644 --- a/src/main/java/com/moulberry/axiom/packet/DeleteEntityPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/DeleteEntityPacketListener.java @@ -9,7 +9,7 @@ import net.minecraft.network.FriendlyByteBuf; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; -import org.bukkit.craftbukkit.v1_20_R3.CraftWorld; +import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.entity.Player; import org.bukkit.plugin.messaging.PluginMessageListener; import org.jetbrains.annotations.NotNull; @@ -49,7 +49,7 @@ public class DeleteEntityPacketListener implements PluginMessageListener { FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.wrappedBuffer(message)); List delete = friendlyByteBuf.readCollection(FriendlyByteBuf.limitValue(ArrayList::new, 1000), - FriendlyByteBuf::readUUID); + buf -> buf.readUUID()); ServerLevel serverLevel = ((CraftWorld)player.getWorld()).getHandle(); diff --git a/src/main/java/com/moulberry/axiom/packet/HelloPacketListener.java b/src/main/java/com/moulberry/axiom/packet/HelloPacketListener.java index 36ab08b..0bdfcac 100644 --- a/src/main/java/com/moulberry/axiom/packet/HelloPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/HelloPacketListener.java @@ -22,12 +22,14 @@ import net.minecraft.SharedConstants; import net.minecraft.core.IdMapper; import net.minecraft.nbt.NbtIo; import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.server.MinecraftServer; import net.minecraft.world.level.block.state.BlockState; import org.bukkit.Bukkit; import org.bukkit.NamespacedKey; import org.bukkit.World; -import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftItemStack; +import org.bukkit.craftbukkit.entity.CraftPlayer; +import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.persistence.PersistentDataContainer; @@ -155,7 +157,7 @@ public class HelloPacketListener implements PluginMessageListener { } // Enable - FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer()); + RegistryFriendlyByteBuf buf = new RegistryFriendlyByteBuf(Unpooled.buffer(), MinecraftServer.getServer().registryAccess()); buf.writeBoolean(true); buf.writeInt(handshakeEvent.getMaxBufferSize()); // Max Buffer Size buf.writeBoolean(false); // No source info @@ -174,15 +176,15 @@ public class HelloPacketListener implements PluginMessageListener { int activeHotbarIndex = container.getOrDefault(AxiomConstants.ACTIVE_HOTBAR_INDEX, PersistentDataType.BYTE, (byte) 0); PersistentDataContainer hotbarItems = container.get(AxiomConstants.HOTBAR_DATA, PersistentDataType.TAG_CONTAINER); if (hotbarItems != null) { - buf = new FriendlyByteBuf(Unpooled.buffer()); + buf = new RegistryFriendlyByteBuf(Unpooled.buffer(), MinecraftServer.getServer().registryAccess()); buf.writeByte((byte) activeHotbarIndex); for (int i=0; i<9*9; i++) { // Ignore selected hotbar if (i / 9 == activeHotbarIndex) { - buf.writeItem(net.minecraft.world.item.ItemStack.EMPTY); + net.minecraft.world.item.ItemStack.OPTIONAL_STREAM_CODEC.encode(buf, net.minecraft.world.item.ItemStack.EMPTY); } else { ItemStack stack = hotbarItems.get(new NamespacedKey("axiom", "slot_"+i), ItemStackDataType.INSTANCE); - buf.writeItem(CraftItemStack.asNMSCopy(stack)); + net.minecraft.world.item.ItemStack.OPTIONAL_STREAM_CODEC.encode(buf, CraftItemStack.asNMSCopy(stack)); } } @@ -195,7 +197,7 @@ public class HelloPacketListener implements PluginMessageListener { // Initialize Views UUID activeView = container.get(AxiomConstants.ACTIVE_VIEW, UUIDDataType.INSTANCE); if (activeView != null) { - buf = new FriendlyByteBuf(Unpooled.buffer()); + buf = new RegistryFriendlyByteBuf(Unpooled.buffer(), MinecraftServer.getServer().registryAccess()); buf.writeUUID(activeView); PersistentDataContainer[] views = container.get(AxiomConstants.VIEWS, PersistentDataType.TAG_CONTAINER_ARRAY); diff --git a/src/main/java/com/moulberry/axiom/packet/ManipulateEntityPacketListener.java b/src/main/java/com/moulberry/axiom/packet/ManipulateEntityPacketListener.java index 1e84e75..c382666 100644 --- a/src/main/java/com/moulberry/axiom/packet/ManipulateEntityPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/ManipulateEntityPacketListener.java @@ -21,7 +21,7 @@ import net.minecraft.world.entity.decoration.ItemFrame; import net.minecraft.world.level.block.Rotation; import net.minecraft.world.phys.Vec3; import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_20_R3.CraftWorld; +import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.entity.Player; import org.bukkit.plugin.messaging.PluginMessageListener; import org.jetbrains.annotations.NotNull; @@ -69,7 +69,7 @@ public class ManipulateEntityPacketListener implements PluginMessageListener { List passengers = List.of(); if (passengerManipulation == PassengerManipulation.ADD_LIST || passengerManipulation == PassengerManipulation.REMOVE_LIST) { passengers = friendlyByteBuf.readCollection(FriendlyByteBuf.limitValue(ArrayList::new, 1000), - FriendlyByteBuf::readUUID); + buffer -> buffer.readUUID()); } return new ManipulateEntry(uuid, relativeMovementSet, position, yaw, pitch, nbt, diff --git a/src/main/java/com/moulberry/axiom/packet/MarkerNbtRequestPacketListener.java b/src/main/java/com/moulberry/axiom/packet/MarkerNbtRequestPacketListener.java index b572bce..1856c13 100644 --- a/src/main/java/com/moulberry/axiom/packet/MarkerNbtRequestPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/MarkerNbtRequestPacketListener.java @@ -9,7 +9,7 @@ import net.minecraft.network.FriendlyByteBuf; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Marker; -import org.bukkit.craftbukkit.v1_20_R3.CraftWorld; +import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.entity.Player; import org.bukkit.plugin.messaging.PluginMessageListener; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/com/moulberry/axiom/packet/RequestChunkDataPacketListener.java b/src/main/java/com/moulberry/axiom/packet/RequestChunkDataPacketListener.java index 516ef53..0aae6cd 100644 --- a/src/main/java/com/moulberry/axiom/packet/RequestChunkDataPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/RequestChunkDataPacketListener.java @@ -22,11 +22,11 @@ import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.chunk.ChunkStatus; +import net.minecraft.world.level.chunk.status.ChunkStatus; import net.minecraft.world.level.chunk.LevelChunk; import net.minecraft.world.level.chunk.LevelChunkSection; import net.minecraft.world.level.chunk.PalettedContainer; -import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer; +import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.entity.Player; import org.bukkit.plugin.messaging.PluginMessageListener; import org.jetbrains.annotations.NotNull; @@ -115,7 +115,7 @@ public class RequestChunkDataPacketListener implements PluginMessageListener { BlockEntity blockEntity = chunk.getBlockEntity(mutableBlockPos, LevelChunk.EntityCreationType.IMMEDIATE); if (blockEntity != null) { - CompoundTag tag = blockEntity.saveWithoutMetadata(); + CompoundTag tag = blockEntity.saveWithoutMetadata(player.registryAccess()); blockEntityMap.put(pos, CompressedBlockEntity.compress(tag, baos)); } } @@ -154,7 +154,7 @@ public class RequestChunkDataPacketListener implements PluginMessageListener { mutableBlockPos.set(sx*16 + x, sy*16 + y, sz*16 + z); BlockEntity blockEntity = chunk.getBlockEntity(mutableBlockPos, LevelChunk.EntityCreationType.CHECK); if (blockEntity != null) { - CompoundTag tag = blockEntity.saveWithoutMetadata(); + CompoundTag tag = blockEntity.saveWithoutMetadata(player.registryAccess()); blockEntityMap.put(mutableBlockPos.asLong(), CompressedBlockEntity.compress(tag, baos)); } } diff --git a/src/main/java/com/moulberry/axiom/packet/SetBlockBufferPacketListener.java b/src/main/java/com/moulberry/axiom/packet/SetBlockBufferPacketListener.java index aaf85f7..8b42520 100644 --- a/src/main/java/com/moulberry/axiom/packet/SetBlockBufferPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/SetBlockBufferPacketListener.java @@ -34,7 +34,7 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.EntityBlock; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.chunk.ChunkStatus; +import net.minecraft.world.level.chunk.status.ChunkStatus; import net.minecraft.world.level.chunk.LevelChunk; import net.minecraft.world.level.chunk.LevelChunkSection; import net.minecraft.world.level.chunk.PalettedContainer; @@ -282,7 +282,7 @@ public class SetBlockBufferPacketListener { int key = x | (y << 4) | (z << 8); CompressedBlockEntity savedBlockEntity = blockEntityChunkMap.get((short) key); if (savedBlockEntity != null) { - blockEntity.load(savedBlockEntity.decompress()); + blockEntity.loadWithComponents(savedBlockEntity.decompress(), player.registryAccess()); } } } else if (old.hasBlockEntity()) { diff --git a/src/main/java/com/moulberry/axiom/packet/SetBlockPacketListener.java b/src/main/java/com/moulberry/axiom/packet/SetBlockPacketListener.java index 91c3856..98b289e 100644 --- a/src/main/java/com/moulberry/axiom/packet/SetBlockPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/SetBlockPacketListener.java @@ -31,9 +31,9 @@ import net.minecraft.world.phys.HitResult; import net.minecraft.world.phys.Vec3; import org.bukkit.Location; import org.bukkit.block.BlockFace; -import org.bukkit.craftbukkit.v1_20_R3.CraftWorld; -import org.bukkit.craftbukkit.v1_20_R3.block.CraftBlock; -import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer; +import org.bukkit.craftbukkit.CraftWorld; +import org.bukkit.craftbukkit.block.CraftBlock; +import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.entity.Player; import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; @@ -91,7 +91,7 @@ public class SetBlockPacketListener implements PluginMessageListener { IntFunction> mapFunction = FriendlyByteBuf.limitValue(Maps::newLinkedHashMapWithExpectedSize, 512); IdMapper registry = this.plugin.getBlockRegistry(bukkitPlayer.getUniqueId()); Map blocks = friendlyByteBuf.readMap(mapFunction, - FriendlyByteBuf::readBlockPos, buf -> buf.readById(registry)); + buf -> buf.readBlockPos(), buf -> buf.readById(registry::byIdOrThrow)); boolean updateNeighbors = friendlyByteBuf.readBoolean(); int reason = friendlyByteBuf.readVarInt(); diff --git a/src/main/java/com/moulberry/axiom/packet/SetFlySpeedPacketListener.java b/src/main/java/com/moulberry/axiom/packet/SetFlySpeedPacketListener.java index ecf9ec4..e488f3b 100644 --- a/src/main/java/com/moulberry/axiom/packet/SetFlySpeedPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/SetFlySpeedPacketListener.java @@ -6,7 +6,7 @@ import io.netty.buffer.Unpooled; import net.kyori.adventure.text.Component; import net.minecraft.network.FriendlyByteBuf; import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer; +import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.entity.Player; import org.bukkit.plugin.messaging.PluginMessageListener; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/com/moulberry/axiom/packet/SetGamemodePacketListener.java b/src/main/java/com/moulberry/axiom/packet/SetGamemodePacketListener.java index cdafc54..be24422 100644 --- a/src/main/java/com/moulberry/axiom/packet/SetGamemodePacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/SetGamemodePacketListener.java @@ -8,7 +8,7 @@ import net.minecraft.network.FriendlyByteBuf; import net.minecraft.world.level.GameType; import org.bukkit.Bukkit; import org.bukkit.GameMode; -import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer; +import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.entity.Player; import org.bukkit.plugin.messaging.PluginMessageListener; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/com/moulberry/axiom/packet/SetHotbarSlotPacketListener.java b/src/main/java/com/moulberry/axiom/packet/SetHotbarSlotPacketListener.java index 99f9327..685a7f0 100644 --- a/src/main/java/com/moulberry/axiom/packet/SetHotbarSlotPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/SetHotbarSlotPacketListener.java @@ -7,8 +7,11 @@ import com.viaversion.viaversion.api.Via; import io.netty.buffer.Unpooled; import net.kyori.adventure.text.Component; import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.world.item.ItemStack; import org.bukkit.NamespacedKey; -import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftItemStack; +import org.bukkit.craftbukkit.entity.CraftPlayer; +import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.entity.Player; import org.bukkit.persistence.PersistentDataContainer; import org.bukkit.persistence.PersistentDataType; @@ -36,10 +39,10 @@ public class SetHotbarSlotPacketListener implements PluginMessageListener { return; } - FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.wrappedBuffer(message)); + RegistryFriendlyByteBuf friendlyByteBuf = new RegistryFriendlyByteBuf(Unpooled.wrappedBuffer(message), ((CraftPlayer)player).getHandle().registryAccess()); int index = friendlyByteBuf.readByte(); if (index < 0 || index >= 9*9) return; - net.minecraft.world.item.ItemStack nmsStack = friendlyByteBuf.readItem(); + net.minecraft.world.item.ItemStack nmsStack = ItemStack.OPTIONAL_STREAM_CODEC.decode(friendlyByteBuf); PersistentDataContainer container = player.getPersistentDataContainer(); PersistentDataContainer hotbarItems = container.get(AxiomConstants.HOTBAR_DATA, PersistentDataType.TAG_CONTAINER); diff --git a/src/main/java/com/moulberry/axiom/packet/SetTimePacketListener.java b/src/main/java/com/moulberry/axiom/packet/SetTimePacketListener.java index c6ccb82..a3b0c7b 100644 --- a/src/main/java/com/moulberry/axiom/packet/SetTimePacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/SetTimePacketListener.java @@ -12,7 +12,7 @@ import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.GameRules; import net.minecraft.world.level.Level; import org.bukkit.Bukkit; -import org.bukkit.craftbukkit.v1_20_R3.CraftWorld; +import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.entity.Player; import org.bukkit.plugin.messaging.PluginMessageListener; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/com/moulberry/axiom/packet/SpawnEntityPacketListener.java b/src/main/java/com/moulberry/axiom/packet/SpawnEntityPacketListener.java index 7e2d419..a9ea16e 100644 --- a/src/main/java/com/moulberry/axiom/packet/SpawnEntityPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/SpawnEntityPacketListener.java @@ -20,7 +20,7 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Rotation; import net.minecraft.world.phys.Vec3; import org.bukkit.Location; -import org.bukkit.craftbukkit.v1_20_R3.CraftWorld; +import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.entity.Player; import org.bukkit.plugin.messaging.PluginMessageListener; import org.jetbrains.annotations.NotNull; @@ -70,7 +70,7 @@ public class SpawnEntityPacketListener implements PluginMessageListener { List entries = friendlyByteBuf.readCollection(FriendlyByteBuf.limitValue(ArrayList::new, 1000), buf -> new SpawnEntry(buf.readUUID(), buf.readDouble(), buf.readDouble(), buf.readDouble(), buf.readFloat(), buf.readFloat(), - buf.readNullable(FriendlyByteBuf::readUUID), ViaVersionHelper.readTagUnknown(buf, player))); + buf.readNullable(buffer -> buffer.readUUID()), ViaVersionHelper.readTagUnknown(buf, player))); ServerLevel serverLevel = ((CraftWorld)player.getWorld()).getHandle(); diff --git a/src/main/java/com/moulberry/axiom/packet/SwitchActiveHotbarPacketListener.java b/src/main/java/com/moulberry/axiom/packet/SwitchActiveHotbarPacketListener.java index 13c2861..90a7338 100644 --- a/src/main/java/com/moulberry/axiom/packet/SwitchActiveHotbarPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/SwitchActiveHotbarPacketListener.java @@ -6,10 +6,12 @@ import com.moulberry.axiom.persistence.ItemStackDataType; import io.netty.buffer.Unpooled; import net.kyori.adventure.text.Component; import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.RegistryFriendlyByteBuf; import org.bukkit.GameMode; import org.bukkit.Material; import org.bukkit.NamespacedKey; -import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftItemStack; +import org.bukkit.craftbukkit.entity.CraftPlayer; +import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.persistence.PersistentDataContainer; @@ -38,13 +40,13 @@ public class SwitchActiveHotbarPacketListener implements PluginMessageListener { return; } - FriendlyByteBuf friendlyByteBuf = new FriendlyByteBuf(Unpooled.wrappedBuffer(message)); + RegistryFriendlyByteBuf friendlyByteBuf = new RegistryFriendlyByteBuf(Unpooled.wrappedBuffer(message), ((CraftPlayer)player).getHandle().registryAccess()); int oldHotbarIndex = friendlyByteBuf.readByte(); int activeHotbarIndex = friendlyByteBuf.readByte(); ItemStack[] hotbarItems = new ItemStack[9]; for (int i=0; i<9; i++) { - hotbarItems[i] = CraftItemStack.asCraftMirror(friendlyByteBuf.readItem()); + hotbarItems[i] = CraftItemStack.asCraftMirror(net.minecraft.world.item.ItemStack.OPTIONAL_STREAM_CODEC.decode(friendlyByteBuf)); } PersistentDataContainer container = player.getPersistentDataContainer(); diff --git a/src/main/java/com/moulberry/axiom/packet/TeleportPacketListener.java b/src/main/java/com/moulberry/axiom/packet/TeleportPacketListener.java index 54ec61f..cdb93b5 100644 --- a/src/main/java/com/moulberry/axiom/packet/TeleportPacketListener.java +++ b/src/main/java/com/moulberry/axiom/packet/TeleportPacketListener.java @@ -10,8 +10,8 @@ import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceKey; import net.minecraft.world.level.Level; import org.bukkit.*; -import org.bukkit.craftbukkit.v1_20_R3.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_20_R3.util.CraftNamespacedKey; +import org.bukkit.craftbukkit.entity.CraftPlayer; +import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.entity.Player; import org.bukkit.plugin.messaging.PluginMessageListener; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/com/moulberry/axiom/persistence/ItemStackDataType.java b/src/main/java/com/moulberry/axiom/persistence/ItemStackDataType.java index 14a2fe6..963d503 100644 --- a/src/main/java/com/moulberry/axiom/persistence/ItemStackDataType.java +++ b/src/main/java/com/moulberry/axiom/persistence/ItemStackDataType.java @@ -1,8 +1,9 @@ package com.moulberry.axiom.persistence; import net.minecraft.nbt.CompoundTag; -import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftItemStack; -import org.bukkit.craftbukkit.v1_20_R3.persistence.CraftPersistentDataContainer; +import net.minecraft.server.MinecraftServer; +import org.bukkit.craftbukkit.inventory.CraftItemStack; +import org.bukkit.craftbukkit.persistence.CraftPersistentDataContainer; import org.bukkit.inventory.ItemStack; import org.bukkit.persistence.PersistentDataAdapterContext; import org.bukkit.persistence.PersistentDataContainer; @@ -28,8 +29,7 @@ public class ItemStackDataType implements PersistentDataType { if (value == null) value = Items.AIR; FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer(8)); - buf.writeId(BuiltInRegistries.ITEM, value); + buf.writeById(BuiltInRegistries.ITEM::getIdOrThrow, value); byte[] bytes = new byte[buf.writerIndex()]; buf.getBytes(0, bytes); @@ -97,7 +97,7 @@ public abstract class WorldPropertyDataType { @Override public Item deserialize(byte[] bytes) { FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.wrappedBuffer(bytes)); - return buf.readById(BuiltInRegistries.ITEM); + return buf.readById(BuiltInRegistries.ITEM::byIdOrThrow); } }; @@ -112,7 +112,7 @@ public abstract class WorldPropertyDataType { if (value == null) value = Blocks.AIR; FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer(8)); - buf.writeId(BuiltInRegistries.BLOCK, value); + buf.writeById(BuiltInRegistries.BLOCK::getIdOrThrow, value); byte[] bytes = new byte[buf.writerIndex()]; buf.getBytes(0, bytes); @@ -122,7 +122,7 @@ public abstract class WorldPropertyDataType { @Override public Block deserialize(byte[] bytes) { FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.wrappedBuffer(bytes)); - return buf.readById(BuiltInRegistries.BLOCK); + return buf.readById(BuiltInRegistries.BLOCK::byIdOrThrow); } }; diff --git a/src/main/java/com/moulberry/axiom/world_properties/server/ServerWorldPropertiesRegistry.java b/src/main/java/com/moulberry/axiom/world_properties/server/ServerWorldPropertiesRegistry.java index 09e0b9d..f8fa272 100644 --- a/src/main/java/com/moulberry/axiom/world_properties/server/ServerWorldPropertiesRegistry.java +++ b/src/main/java/com/moulberry/axiom/world_properties/server/ServerWorldPropertiesRegistry.java @@ -9,7 +9,7 @@ import net.minecraft.server.level.ServerLevel; import org.bukkit.GameRule; import org.bukkit.NamespacedKey; import org.bukkit.World; -import org.bukkit.craftbukkit.v1_20_R3.CraftWorld; +import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; diff --git a/src/main/java/com/moulberry/axiom/world_properties/server/ServerWorldPropertyBase.java b/src/main/java/com/moulberry/axiom/world_properties/server/ServerWorldPropertyBase.java index 2d7837b..9a3c300 100644 --- a/src/main/java/com/moulberry/axiom/world_properties/server/ServerWorldPropertyBase.java +++ b/src/main/java/com/moulberry/axiom/world_properties/server/ServerWorldPropertyBase.java @@ -6,7 +6,7 @@ import com.moulberry.axiom.world_properties.WorldPropertyWidgetType; import net.minecraft.resources.ResourceLocation; import org.bukkit.NamespacedKey; import org.bukkit.World; -import org.bukkit.craftbukkit.v1_20_R3.util.CraftNamespacedKey; +import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.entity.Player; public abstract class ServerWorldPropertyBase { diff --git a/src/main/java/com/moulberry/axiom/world_properties/server/ServerWorldPropertyHolder.java b/src/main/java/com/moulberry/axiom/world_properties/server/ServerWorldPropertyHolder.java index 0755b69..28cfbe0 100644 --- a/src/main/java/com/moulberry/axiom/world_properties/server/ServerWorldPropertyHolder.java +++ b/src/main/java/com/moulberry/axiom/world_properties/server/ServerWorldPropertyHolder.java @@ -9,7 +9,7 @@ import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; import org.bukkit.NamespacedKey; import org.bukkit.World; -import org.bukkit.craftbukkit.v1_20_R3.util.CraftNamespacedKey; +import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.entity.Player; import java.util.Objects;