From 65e89bf1791a2b0afe688a4ca77579cac88359ff Mon Sep 17 00:00:00 2001 From: MiniDigger | Martin Date: Fri, 22 Sep 2023 19:31:02 +0200 Subject: [PATCH] some compile fixes --- .../Add-Velocity-IP-Forwarding-Support.patch | 2 +- ...ent-to-allow-plugins-to-handle-clien.patch | 2 +- .../server/Add-recipe-to-cook-events.patch | 2 +- ...d-PlayerStonecutterRecipeSelectEvent.patch | 4 +- patches/server/Adventure.patch | 2 +- patches/server/Basic-PlayerProfile-API.patch | 2 +- .../Call-missing-BlockDispenseEvent.patch | 4 +- ...o-not-accept-invalid-client-settings.patch | 2 +- ...nt-protocol-version-and-virtual-host.patch | 4 +- ...k-event-leave-message-not-being-sent.patch | 2 +- patches/server/Furnace-RecipesUsed-API.patch | 4 +- .../Optimise-random-block-ticking.patch | 2 +- ...ocity-compression-and-cipher-natives.patch | 125 +++++++++++++----- 13 files changed, 108 insertions(+), 49 deletions(-) diff --git a/patches/server/Add-Velocity-IP-Forwarding-Support.patch b/patches/server/Add-Velocity-IP-Forwarding-Support.patch index 7a12b0b129..9fda0d15a5 100644 --- a/patches/server/Add-Velocity-IP-Forwarding-Support.patch +++ b/patches/server/Add-Velocity-IP-Forwarding-Support.patch @@ -169,7 +169,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 @Override public void handleCustomQueryPacket(ServerboundCustomQueryAnswerPacket packet) { + // Paper start - Velocity support -+ if (io.papermc.paper.configuration.GlobalConfiguration.get().proxies.velocity.enabled && packet.getTransactionId() == this.velocityLoginMessageId) { ++ if (io.papermc.paper.configuration.GlobalConfiguration.get().proxies.velocity.enabled && packet.transactionId() == this.velocityLoginMessageId) { + net.minecraft.network.FriendlyByteBuf buf = packet.getData(); + if (buf == null) { + this.disconnect("This server requires you to connect with Velocity."); diff --git a/patches/server/Add-handshake-event-to-allow-plugins-to-handle-clien.patch b/patches/server/Add-handshake-event-to-allow-plugins-to-handle-clien.patch index 31a89cc11a..47082fd779 100644 --- a/patches/server/Add-handshake-event-to-allow-plugins-to-handle-clien.patch +++ b/patches/server/Add-handshake-event-to-allow-plugins-to-handle-clien.patch @@ -20,7 +20,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + if (com.destroystokyo.paper.event.player.PlayerHandshakeEvent.getHandlerList().getRegisteredListeners().length != 0) { // Hello? Can you hear me? + java.net.SocketAddress socketAddress = this.connection.address; + String hostnameOfRemote = socketAddress instanceof java.net.InetSocketAddress ? ((java.net.InetSocketAddress) socketAddress).getHostString() : InetAddress.getLoopbackAddress().getHostAddress(); -+ com.destroystokyo.paper.event.player.PlayerHandshakeEvent event = new com.destroystokyo.paper.event.player.PlayerHandshakeEvent(packet.hostName, hostnameOfRemote, !proxyLogicEnabled); ++ com.destroystokyo.paper.event.player.PlayerHandshakeEvent event = new com.destroystokyo.paper.event.player.PlayerHandshakeEvent(packet.hostName(), hostnameOfRemote, !proxyLogicEnabled); + if (event.callEvent()) { + // If we've failed somehow, let the client know so and go no further. + if (event.isFailed()) { diff --git a/patches/server/Add-recipe-to-cook-events.patch b/patches/server/Add-recipe-to-cook-events.patch index 83c285ec8d..e5f38005ab 100644 --- a/patches/server/Add-recipe-to-cook-events.patch +++ b/patches/server/Add-recipe-to-cook-events.patch @@ -13,7 +13,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 org.bukkit.inventory.ItemStack result = CraftItemStack.asBukkitCopy(itemstack1); - FurnaceSmeltEvent furnaceSmeltEvent = new FurnaceSmeltEvent(CraftBlock.at(world, blockposition), source, result); -+ FurnaceSmeltEvent furnaceSmeltEvent = new FurnaceSmeltEvent(CraftBlock.at(world, blockposition), source, result, (org.bukkit.inventory.CookingRecipe) irecipe.toBukkitRecipe()); // Paper ++ FurnaceSmeltEvent furnaceSmeltEvent = new FurnaceSmeltEvent(CraftBlock.at(world, blockposition), source, result, (org.bukkit.inventory.CookingRecipe) recipeholder.toBukkitRecipe()); // Paper world.getCraftServer().getPluginManager().callEvent(furnaceSmeltEvent); if (furnaceSmeltEvent.isCancelled()) { diff --git a/patches/server/Added-PlayerStonecutterRecipeSelectEvent.patch b/patches/server/Added-PlayerStonecutterRecipeSelectEvent.patch index 6e802d6a49..23b072daed 100644 --- a/patches/server/Added-PlayerStonecutterRecipeSelectEvent.patch +++ b/patches/server/Added-PlayerStonecutterRecipeSelectEvent.patch @@ -34,9 +34,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + return false; + } + int newRecipeIndex; -+ if (!this.getRecipes().get(recipeIndex).getId().equals(org.bukkit.craftbukkit.util.CraftNamespacedKey.toMinecraft(event.getStonecuttingRecipe().getKey()))) { // If the recipe did NOT stay the same ++ if (!this.getRecipes().get(recipeIndex).id().equals(org.bukkit.craftbukkit.util.CraftNamespacedKey.toMinecraft(event.getStonecuttingRecipe().getKey()))) { // If the recipe did NOT stay the same + for (newRecipeIndex = 0; newRecipeIndex < this.getRecipes().size(); newRecipeIndex++) { -+ if (this.getRecipes().get(newRecipeIndex).getId().equals(org.bukkit.craftbukkit.util.CraftNamespacedKey.toMinecraft(event.getStonecuttingRecipe().getKey()))) { ++ if (this.getRecipes().get(newRecipeIndex).id().equals(org.bukkit.craftbukkit.util.CraftNamespacedKey.toMinecraft(event.getStonecuttingRecipe().getKey()))) { + recipeIndex = newRecipeIndex; + break; + } diff --git a/patches/server/Adventure.patch b/patches/server/Adventure.patch index 8d60f71caf..b788c64d00 100644 --- a/patches/server/Adventure.patch +++ b/patches/server/Adventure.patch @@ -4725,7 +4725,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 MapDecoration decoration = worldMap.decorations.get(key); - cursors.addCursor(decoration.x(), decoration.y(), (byte) (decoration.rot() & 15), decoration.type().getIcon(), true, CraftChatMessage.fromComponent(decoration.name())); -+ cursors.addCursor(decoration.x(), decoration.y(), (byte) (decoration.rot() & 15), decoration.type().getIcon(), true, decoration.getName() == null ? null : io.papermc.paper.adventure.PaperAdventure.asAdventure(decoration.getName())); // Paper ++ cursors.addCursor(decoration.x(), decoration.y(), (byte) (decoration.rot() & 15), decoration.type().getIcon(), true, decoration.name() == null ? null : io.papermc.paper.adventure.PaperAdventure.asAdventure(decoration.name())); // Paper } } diff --git a/patches/server/Basic-PlayerProfile-API.patch b/patches/server/Basic-PlayerProfile-API.patch index 3a1522bc8c..f64862f6a9 100644 --- a/patches/server/Basic-PlayerProfile-API.patch +++ b/patches/server/Basic-PlayerProfile-API.patch @@ -448,7 +448,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + + @Override + public MinecraftSessionService createMinecraftSessionService() { -+ return new PaperMinecraftSessionService(this, this.environment); ++ return new PaperMinecraftSessionService(this.getServicesKeySet(), this.getProxy(), this.environment); + } + + @Override diff --git a/patches/server/Call-missing-BlockDispenseEvent.patch b/patches/server/Call-missing-BlockDispenseEvent.patch index cc118c9270..aaddedbaa8 100644 --- a/patches/server/Call-missing-BlockDispenseEvent.patch +++ b/patches/server/Call-missing-BlockDispenseEvent.patch @@ -59,8 +59,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + // Paper start - missing BlockDispenseEvent calls + @Nullable -+ public static ItemStack handleBlockDispenseEvent(net.minecraft.core.BlockSource pointer, BlockPos to, ItemStack itemStack, net.minecraft.core.dispenser.DispenseItemBehavior instance) { -+ org.bukkit.block.Block bukkitBlock = pointer.getLevel().getWorld().getBlockAt(pointer.getPos().getX(), pointer.getPos().getY(), pointer.getPos().getZ()); ++ public static ItemStack handleBlockDispenseEvent(net.minecraft.core.dispenser.BlockSource pointer, BlockPos to, ItemStack itemStack, net.minecraft.core.dispenser.DispenseItemBehavior instance) { ++ org.bukkit.block.Block bukkitBlock = pointer.level().getWorld().getBlockAt(pointer.pos().getX(), pointer.pos().getY(), pointer.pos().getZ()); + CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemStack.copyWithCount(1)); + + org.bukkit.event.block.BlockDispenseEvent event = new org.bukkit.event.block.BlockDispenseEvent(bukkitBlock, craftItem.clone(), new org.bukkit.util.Vector(to.getX(), to.getY(), to.getZ())); diff --git a/patches/server/Do-not-accept-invalid-client-settings.patch b/patches/server/Do-not-accept-invalid-client-settings.patch index d59df26062..5143abdf3a 100644 --- a/patches/server/Do-not-accept-invalid-client-settings.patch +++ b/patches/server/Do-not-accept-invalid-client-settings.patch @@ -15,7 +15,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + // Paper start - do not accept invalid information + if (packet.information().viewDistance() < 0) { + LOGGER.warn("Disconnecting " + this.player.getScoreboardName() + " for invalid view distance: " + packet.information().viewDistance()); -+ this.disconnect("Invalid client settings", PlayerKickEvent.Cause.ILLEGAL_ACTION); ++ this.disconnect("Invalid client settings", org.bukkit.event.player.PlayerKickEvent.Cause.ILLEGAL_ACTION); + return; + } + // Paper end - do not accept invalid information diff --git a/patches/server/Expose-client-protocol-version-and-virtual-host.patch b/patches/server/Expose-client-protocol-version-and-virtual-host.patch index b3e692ffd8..63fdacbbfb 100644 --- a/patches/server/Expose-client-protocol-version-and-virtual-host.patch +++ b/patches/server/Expose-client-protocol-version-and-virtual-host.patch @@ -83,8 +83,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 } + // Paper start - NetworkClient implementation -+ this.connection.protocolVersion = packet.getProtocolVersion(); -+ this.connection.virtualHost = com.destroystokyo.paper.network.PaperNetworkClient.prepareVirtualHost(packet.hostName, packet.port); ++ this.connection.protocolVersion = packet.protocolVersion(); ++ this.connection.virtualHost = com.destroystokyo.paper.network.PaperNetworkClient.prepareVirtualHost(packet.hostName(), packet.port()); + // Paper end } diff --git a/patches/server/Fixes-kick-event-leave-message-not-being-sent.patch b/patches/server/Fixes-kick-event-leave-message-not-being-sent.patch index 0ef108de8f..de1bc53d84 100644 --- a/patches/server/Fixes-kick-event-leave-message-not-being-sent.patch +++ b/patches/server/Fixes-kick-event-leave-message-not-being-sent.patch @@ -103,7 +103,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 public net.kyori.adventure.text.Component remove(ServerPlayer entityplayer) { // CraftBukkit - return string // Paper - return Component + // Paper start -+ return this.remove(entityplayer, net.kyori.adventure.text.Component.translatable("multiplayer.player.left", net.kyori.adventure.text.format.NamedTextColor.YELLOW, io.papermc.paper.configuration.GlobalConfiguration.get().messages.useDisplayNameInQuitMessage ? entityplayer.getBukkitEntity().displayName() : PaperAdventure.asAdventure(entityplayer.getDisplayName()))); ++ return this.remove(entityplayer, net.kyori.adventure.text.Component.translatable("multiplayer.player.left", net.kyori.adventure.text.format.NamedTextColor.YELLOW, io.papermc.paper.configuration.GlobalConfiguration.get().messages.useDisplayNameInQuitMessage ? entityplayer.getBukkitEntity().displayName() : io.papermc.paper.adventure.PaperAdventure.asAdventure(entityplayer.getDisplayName()))); + } + public net.kyori.adventure.text.Component remove(ServerPlayer entityplayer, net.kyori.adventure.text.Component leaveMessage) { + // Paper end diff --git a/patches/server/Furnace-RecipesUsed-API.patch b/patches/server/Furnace-RecipesUsed-API.patch index dc0eacd039..f01e10c040 100644 --- a/patches/server/Furnace-RecipesUsed-API.patch +++ b/patches/server/Furnace-RecipesUsed-API.patch @@ -26,8 +26,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + @Override + public void setRecipeUsedCount(org.bukkit.inventory.CookingRecipe furnaceRecipe, int count) { + final net.minecraft.resources.ResourceLocation location = org.bukkit.craftbukkit.util.CraftNamespacedKey.toMinecraft(furnaceRecipe.getKey()); -+ java.util.Optional> nmsRecipe = (this.isPlaced() ? this.world.getHandle().getRecipeManager() : net.minecraft.server.MinecraftServer.getServer().getRecipeManager()).byKey(location); -+ com.google.common.base.Preconditions.checkArgument(nmsRecipe.isPresent() && nmsRecipe.get() instanceof net.minecraft.world.item.crafting.AbstractCookingRecipe, furnaceRecipe.getKey() + " is not recognized as a valid and registered furnace recipe"); ++ java.util.Optional> nmsRecipe = (this.isPlaced() ? this.world.getHandle().getRecipeManager() : net.minecraft.server.MinecraftServer.getServer().getRecipeManager()).byKey(location); ++ com.google.common.base.Preconditions.checkArgument(nmsRecipe.isPresent() && nmsRecipe.get().value() instanceof net.minecraft.world.item.crafting.AbstractCookingRecipe, furnaceRecipe.getKey() + " is not recognized as a valid and registered furnace recipe"); + if (count > 0) { + this.getSnapshot().getRecipesUsed().put(location, count); + } else { diff --git a/patches/server/Optimise-random-block-ticking.patch b/patches/server/Optimise-random-block-ticking.patch index 69b3ebec97..6a32121c48 100644 --- a/patches/server/Optimise-random-block-ticking.patch +++ b/patches/server/Optimise-random-block-ticking.patch @@ -122,7 +122,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 if (this.random.nextInt(48) == 0) { - this.tickIceAndSnow(flag, this.getBlockRandomPos(j, 0, k, 15)); + this.getRandomBlockPosition(j, 0, k, 15, blockposition); -+ this.tickIceAndSnow(flag, blockposition); ++ this.tickIceAndSnow(flag, blockposition, chunk); } } } // Paper diff --git a/patches/server/Use-Velocity-compression-and-cipher-natives.patch b/patches/server/Use-Velocity-compression-and-cipher-natives.patch index 8ffa261553..eb8fa2715a 100644 --- a/patches/server/Use-Velocity-compression-and-cipher-natives.patch +++ b/patches/server/Use-Velocity-compression-and-cipher-natives.patch @@ -174,23 +174,73 @@ diff --git a/src/main/java/net/minecraft/network/CompressionEncoder.java b/src/m index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/network/CompressionEncoder.java +++ b/src/main/java/net/minecraft/network/CompressionEncoder.java -@@ -0,0 +0,0 @@ import io.netty.handler.codec.MessageToByteEncoder; - import java.util.zip.Deflater; - - public class CompressionEncoder extends MessageToByteEncoder { +@@ -0,0 +0,0 @@ +-package net.minecraft.network; +- +-import io.netty.buffer.ByteBuf; +-import io.netty.channel.ChannelHandlerContext; +-import io.netty.handler.codec.MessageToByteEncoder; +-import java.util.zip.Deflater; +- +-public class CompressionEncoder extends MessageToByteEncoder { - private final byte[] encodeBuf = new byte[8192]; +- private final Deflater deflater; +- private int threshold; +- +- public CompressionEncoder(int compressionThreshold) { +- this.threshold = compressionThreshold; +- this.deflater = new Deflater(); +- } +- +- protected void encode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, ByteBuf byteBuf2) { +- int i = byteBuf.readableBytes(); +- if (i < this.threshold) { +- VarInt.write(byteBuf2, 0); +- byteBuf2.writeBytes(byteBuf); +- } else { +- byte[] bs = new byte[i]; +- byteBuf.readBytes(bs); +- VarInt.write(byteBuf2, bs.length); +- this.deflater.setInput(bs, 0, i); +- this.deflater.finish(); +- +- while(!this.deflater.finished()) { +- int j = this.deflater.deflate(this.encodeBuf); +- byteBuf2.writeBytes(this.encodeBuf, 0, j); +- } +- +- this.deflater.reset(); +- } +- +- } +- +- public int getThreshold() { +- return this.threshold; +- } +- +- public void setThreshold(int compressionThreshold) { +- this.threshold = compressionThreshold; +- } +-} ++package net.minecraft.network; ++ ++import io.netty.buffer.ByteBuf; ++import io.netty.channel.ChannelHandlerContext; ++import io.netty.handler.codec.MessageToByteEncoder; ++import java.util.zip.Deflater; ++ ++public class CompressionEncoder extends MessageToByteEncoder { + private final byte[] encodeBuf; // Paper - private final Deflater deflater; ++ private final Deflater deflater; + private final com.velocitypowered.natives.compression.VelocityCompressor compressor; // Paper - private int threshold; - ++ private int threshold; ++ + // Paper start - public CompressionEncoder(int compressionThreshold) { ++ public CompressionEncoder(int compressionThreshold) { + this(null, compressionThreshold); + } + public CompressionEncoder(com.velocitypowered.natives.compression.VelocityCompressor compressor, int compressionThreshold) { - this.threshold = compressionThreshold; -- this.deflater = new Deflater(); ++ this.threshold = compressionThreshold; + if (compressor == null) { + this.encodeBuf = new byte[8192]; + this.deflater = new Deflater(); @@ -200,28 +250,32 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + } + this.compressor = compressor; + // Paper end - } - -- protected void encode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, ByteBuf byteBuf2) { ++ } ++ + protected void encode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, ByteBuf byteBuf2) throws Exception { // Paper - int i = byteBuf.readableBytes(); - if (i < this.threshold) { - VarInt.write(byteBuf2, 0); - byteBuf2.writeBytes(byteBuf); - } else { ++ int i = byteBuf.readableBytes(); ++ if (i < this.threshold) { ++ VarInt.write(byteBuf2, 0); ++ byteBuf2.writeBytes(byteBuf); ++ } else { + // Paper start + if (this.deflater != null) { - byte[] bs = new byte[i]; - byteBuf.readBytes(bs); - VarInt.write(byteBuf2, bs.length); -@@ -0,0 +0,0 @@ public class CompressionEncoder extends MessageToByteEncoder { - } - - this.deflater.reset(); ++ byte[] bs = new byte[i]; ++ byteBuf.readBytes(bs); ++ VarInt.write(byteBuf2, bs.length); ++ this.deflater.setInput(bs, 0, i); ++ this.deflater.finish(); ++ ++ while(!this.deflater.finished()) { ++ int j = this.deflater.deflate(this.encodeBuf); ++ byteBuf2.writeBytes(this.encodeBuf, 0, j); ++ } ++ ++ this.deflater.reset(); + return; + } + -+ friendlyByteBuf.writeVarInt(i); ++ VarInt.write(byteBuf2, i); + ByteBuf compatibleIn = com.velocitypowered.natives.util.MoreByteBufUtils.ensureCompatible(channelHandlerContext.alloc(), this.compressor, byteBuf); + try { + this.compressor.deflate(compatibleIn, byteBuf2); @@ -229,10 +283,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + compatibleIn.release(); + } + // Paper end - } - - } - ++ } ++ ++ } ++ + // Paper start + @Override + protected ByteBuf allocateBuffer(ChannelHandlerContext ctx, ByteBuf msg, boolean preferDirect) throws Exception{ @@ -260,9 +314,14 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + } + // Paper end + - public int getThreshold() { - return this.threshold; - } ++ public int getThreshold() { ++ return this.threshold; ++ } ++ ++ public void setThreshold(int compressionThreshold) { ++ this.threshold = compressionThreshold; ++ } ++} diff --git a/src/main/java/net/minecraft/network/Connection.java b/src/main/java/net/minecraft/network/Connection.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/network/Connection.java