Move CraftBukkit per-file patches

By: Initial <noreply+automated@papermc.io>
This commit is contained in:
CraftBukkit/Spigot
2024-12-11 22:26:36 +01:00
parent a4de181b77
commit a265d64138
583 changed files with 71 additions and 857 deletions

View File

@@ -0,0 +1,37 @@
--- a/net/minecraft/network/NetworkManager.java
+++ b/net/minecraft/network/NetworkManager.java
@@ -114,6 +114,7 @@
private volatile DisconnectionDetails delayedDisconnect;
@Nullable
BandwidthDebugMonitor bandwidthDebugMonitor;
+ public String hostname = ""; // CraftBukkit - add field
public NetworkManager(EnumProtocolDirection enumprotocoldirection) {
this.receiving = enumprotocoldirection;
@@ -205,7 +206,7 @@
}
private static <T extends PacketListener> void genericsFtw(Packet<T> packet, PacketListener packetlistener) {
- packet.handle(packetlistener);
+ packet.handle((T) packetlistener); // CraftBukkit - decompile error
}
private void validateListener(ProtocolInfo<?> protocolinfo, PacketListener packetlistener) {
@@ -469,7 +470,7 @@
}
if (this.isConnected()) {
- this.channel.close().awaitUninterruptibly();
+ this.channel.close(); // We can't wait as this may be called from an event loop.
this.disconnectionDetails = disconnectiondetails;
}
@@ -537,7 +538,7 @@
}
public void configurePacketHandler(ChannelPipeline channelpipeline) {
- channelpipeline.addLast("hackfix", new ChannelOutboundHandlerAdapter(this) {
+ channelpipeline.addLast("hackfix", new ChannelOutboundHandlerAdapter() { // CraftBukkit - decompile error
public void write(ChannelHandlerContext channelhandlercontext, Object object, ChannelPromise channelpromise) throws Exception {
super.write(channelhandlercontext, object, channelpromise);
}

View File

@@ -0,0 +1,71 @@
--- a/net/minecraft/network/PacketDataSerializer.java
+++ b/net/minecraft/network/PacketDataSerializer.java
@@ -139,7 +139,7 @@
public <T, C extends Collection<T>> C readCollection(IntFunction<C> intfunction, StreamDecoder<? super PacketDataSerializer, T> streamdecoder) {
int i = this.readVarInt();
- C c0 = (Collection) intfunction.apply(i);
+ C c0 = intfunction.apply(i); // CraftBukkit - decompile error
for (int j = 0; j < i; ++j) {
c0.add(streamdecoder.decode(this));
@@ -150,7 +150,7 @@
public <T> void writeCollection(Collection<T> collection, StreamEncoder<? super PacketDataSerializer, T> streamencoder) {
this.writeVarInt(collection.size());
- Iterator iterator = collection.iterator();
+ Iterator<T> iterator = collection.iterator(); // CraftBukkit - decompile error
while (iterator.hasNext()) {
T t0 = iterator.next();
@@ -177,12 +177,12 @@
public void writeIntIdList(IntList intlist) {
this.writeVarInt(intlist.size());
- intlist.forEach(this::writeVarInt);
+ intlist.forEach((java.util.function.IntConsumer) this::writeVarInt); // CraftBukkit - decompile error
}
public <K, V, M extends Map<K, V>> M readMap(IntFunction<M> intfunction, StreamDecoder<? super PacketDataSerializer, K> streamdecoder, StreamDecoder<? super PacketDataSerializer, V> streamdecoder1) {
int i = this.readVarInt();
- M m0 = (Map) intfunction.apply(i);
+ M m0 = intfunction.apply(i); // CraftBukkit - decompile error
for (int j = 0; j < i; ++j) {
K k0 = streamdecoder.decode(this);
@@ -216,7 +216,7 @@
}
public <E extends Enum<E>> void writeEnumSet(EnumSet<E> enumset, Class<E> oclass) {
- E[] ae = (Enum[]) oclass.getEnumConstants();
+ E[] ae = oclass.getEnumConstants(); // CraftBukkit - decompile error
BitSet bitset = new BitSet(ae.length);
for (int i = 0; i < ae.length; ++i) {
@@ -227,7 +227,7 @@
}
public <E extends Enum<E>> EnumSet<E> readEnumSet(Class<E> oclass) {
- E[] ae = (Enum[]) oclass.getEnumConstants();
+ E[] ae = oclass.getEnumConstants(); // CraftBukkit - decompile error
BitSet bitset = this.readFixedBitSet(ae.length);
EnumSet<E> enumset = EnumSet.noneOf(oclass);
@@ -498,7 +498,7 @@
}
public <T extends Enum<T>> T readEnum(Class<T> oclass) {
- return ((Enum[]) oclass.getEnumConstants())[this.readVarInt()];
+ return ((T[]) oclass.getEnumConstants())[this.readVarInt()]; // CraftBukkit - fix decompile error
}
public PacketDataSerializer writeEnum(Enum<?> oenum) {
@@ -565,7 +565,7 @@
try {
NBTCompressedStreamTools.writeAnyTag((NBTBase) nbtbase, new ByteBufOutputStream(bytebuf));
- } catch (IOException ioexception) {
+ } catch (Exception ioexception) { // CraftBukkit - IOException -> Exception
throw new EncoderException(ioexception);
}
}

View File

@@ -0,0 +1,35 @@
--- a/net/minecraft/network/chat/ChatHexColor.java
+++ b/net/minecraft/network/chat/ChatHexColor.java
@@ -17,7 +17,7 @@
private static final String CUSTOM_COLOR_PREFIX = "#";
public static final Codec<ChatHexColor> CODEC = Codec.STRING.comapFlatMap(ChatHexColor::parseColor, ChatHexColor::serialize);
private static final Map<EnumChatFormat, ChatHexColor> LEGACY_FORMAT_TO_COLOR = (Map) Stream.of(EnumChatFormat.values()).filter(EnumChatFormat::isColor).collect(ImmutableMap.toImmutableMap(Function.identity(), (enumchatformat) -> {
- return new ChatHexColor(enumchatformat.getColor(), enumchatformat.getName());
+ return new ChatHexColor(enumchatformat.getColor(), enumchatformat.getName(), enumchatformat); // CraftBukkit
}));
private static final Map<String, ChatHexColor> NAMED_COLORS = (Map) ChatHexColor.LEGACY_FORMAT_TO_COLOR.values().stream().collect(ImmutableMap.toImmutableMap((chathexcolor) -> {
return chathexcolor.name;
@@ -25,16 +25,22 @@
private final int value;
@Nullable
public final String name;
+ // CraftBukkit start
+ @Nullable
+ public final EnumChatFormat format;
- private ChatHexColor(int i, String s) {
+ private ChatHexColor(int i, String s, EnumChatFormat format) {
this.value = i & 16777215;
this.name = s;
+ this.format = format;
}
private ChatHexColor(int i) {
this.value = i & 16777215;
this.name = null;
+ this.format = null;
}
+ // CraftBukkit end
public int getValue() {
return this.value;

View File

@@ -0,0 +1,26 @@
--- a/net/minecraft/network/chat/IChatBaseComponent.java
+++ b/net/minecraft/network/chat/IChatBaseComponent.java
@@ -38,7 +38,22 @@
import net.minecraft.util.FormattedString;
import net.minecraft.world.level.ChunkCoordIntPair;
-public interface IChatBaseComponent extends Message, IChatFormatted {
+// CraftBukkit start
+import java.util.stream.Stream;
+// CraftBukkit end
+
+public interface IChatBaseComponent extends Message, IChatFormatted, Iterable<IChatBaseComponent> { // CraftBukkit
+
+ // CraftBukkit start
+ default Stream<IChatBaseComponent> stream() {
+ return com.google.common.collect.Streams.concat(new Stream[]{Stream.of(this), this.getSiblings().stream().flatMap(IChatBaseComponent::stream)});
+ }
+
+ @Override
+ default Iterator<IChatBaseComponent> iterator() {
+ return this.stream().iterator();
+ }
+ // CraftBukkit end
ChatModifier getStyle();

View File

@@ -0,0 +1,22 @@
--- a/net/minecraft/network/protocol/PlayerConnectionUtils.java
+++ b/net/minecraft/network/protocol/PlayerConnectionUtils.java
@@ -11,6 +11,11 @@
import net.minecraft.util.thread.IAsyncTaskHandler;
import org.slf4j.Logger;
+// CraftBukkit start
+import net.minecraft.server.MinecraftServer;
+import net.minecraft.server.network.ServerCommonPacketListenerImpl;
+// CraftBukkit end
+
public class PlayerConnectionUtils {
private static final Logger LOGGER = LogUtils.getLogger();
@@ -24,6 +29,7 @@
public static <T extends PacketListener> void ensureRunningOnSameThread(Packet<T> packet, T t0, IAsyncTaskHandler<?> iasynctaskhandler) throws CancelledPacketHandleException {
if (!iasynctaskhandler.isSameThread()) {
iasynctaskhandler.executeIfPossible(() -> {
+ if (t0 instanceof ServerCommonPacketListenerImpl serverCommonPacketListener && serverCommonPacketListener.processedDisconnect) return; // CraftBukkit - Don't handle sync packets for kicked players
if (t0.shouldHandleMessage(packet)) {
try {
packet.handle(t0);

View File

@@ -0,0 +1,12 @@
--- a/net/minecraft/network/protocol/common/ServerboundCustomPayloadPacket.java
+++ b/net/minecraft/network/protocol/common/ServerboundCustomPayloadPacket.java
@@ -16,8 +16,7 @@
private static final int MAX_PAYLOAD_SIZE = 32767;
public static final StreamCodec<PacketDataSerializer, ServerboundCustomPayloadPacket> STREAM_CODEC = CustomPacketPayload.codec((minecraftkey) -> {
return DiscardedPayload.codec(minecraftkey, 32767);
- }, (List) SystemUtils.make(Lists.newArrayList(new CustomPacketPayload.c[]{new CustomPacketPayload.c<>(BrandPayload.TYPE, BrandPayload.STREAM_CODEC)}), (arraylist) -> {
- })).map(ServerboundCustomPayloadPacket::new, ServerboundCustomPayloadPacket::payload);
+ }, java.util.Collections.emptyList()).map(ServerboundCustomPayloadPacket::new, ServerboundCustomPayloadPacket::payload); // CraftBukkit - treat all packets the same
@Override
public PacketType<ServerboundCustomPayloadPacket> type() {

View File

@@ -0,0 +1,24 @@
--- a/net/minecraft/network/protocol/common/custom/DiscardedPayload.java
+++ b/net/minecraft/network/protocol/common/custom/DiscardedPayload.java
@@ -4,16 +4,18 @@
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.resources.MinecraftKey;
-public record DiscardedPayload(MinecraftKey id) implements CustomPacketPayload {
+public record DiscardedPayload(MinecraftKey id, io.netty.buffer.ByteBuf data) implements CustomPacketPayload { // CraftBukkit - store data
public static <T extends PacketDataSerializer> StreamCodec<T, DiscardedPayload> codec(MinecraftKey minecraftkey, int i) {
return CustomPacketPayload.codec((discardedpayload, packetdataserializer) -> {
+ packetdataserializer.writeBytes(discardedpayload.data); // CraftBukkit - serialize
}, (packetdataserializer) -> {
int j = packetdataserializer.readableBytes();
if (j >= 0 && j <= i) {
- packetdataserializer.skipBytes(j);
- return new DiscardedPayload(minecraftkey);
+ // CraftBukkit start
+ return new DiscardedPayload(minecraftkey, packetdataserializer.readBytes(j));
+ // CraftBukkit end
} else {
throw new IllegalArgumentException("Payload may not be larger than " + i + " bytes");
}

View File

@@ -0,0 +1,15 @@
--- a/net/minecraft/network/protocol/game/ClientboundInitializeBorderPacket.java
+++ b/net/minecraft/network/protocol/game/ClientboundInitializeBorderPacket.java
@@ -30,8 +30,10 @@
}
public ClientboundInitializeBorderPacket(WorldBorder worldborder) {
- this.newCenterX = worldborder.getCenterX();
- this.newCenterZ = worldborder.getCenterZ();
+ // CraftBukkit start - multiply out nether border
+ this.newCenterX = worldborder.getCenterX() * worldborder.world.dimensionType().coordinateScale();
+ this.newCenterZ = worldborder.getCenterZ() * worldborder.world.dimensionType().coordinateScale();
+ // CraftBukkit end
this.oldSize = worldborder.getSize();
this.newSize = worldborder.getLerpTarget();
this.lerpTime = worldborder.getLerpRemainingTime();

View File

@@ -0,0 +1,15 @@
--- a/net/minecraft/network/protocol/game/ClientboundSetBorderCenterPacket.java
+++ b/net/minecraft/network/protocol/game/ClientboundSetBorderCenterPacket.java
@@ -13,8 +13,10 @@
private final double newCenterZ;
public ClientboundSetBorderCenterPacket(WorldBorder worldborder) {
- this.newCenterX = worldborder.getCenterX();
- this.newCenterZ = worldborder.getCenterZ();
+ // CraftBukkit start - multiply out nether border
+ this.newCenterX = worldborder.getCenterX() * (worldborder.world != null ? worldborder.world.dimensionType().coordinateScale() : 1.0);
+ this.newCenterZ = worldborder.getCenterZ() * (worldborder.world != null ? worldborder.world.dimensionType().coordinateScale() : 1.0);
+ // CraftBukkit end
}
private ClientboundSetBorderCenterPacket(PacketDataSerializer packetdataserializer) {

View File

@@ -0,0 +1,7 @@
--- a/net/minecraft/network/protocol/game/ClientboundSystemChatPacket.java
+++ b/net/minecraft/network/protocol/game/ClientboundSystemChatPacket.java
@@ -1,3 +1,4 @@
+// mc-dev import
package net.minecraft.network.protocol.game;
import net.minecraft.network.RegistryFriendlyByteBuf;

View File

@@ -0,0 +1,7 @@
--- a/net/minecraft/network/protocol/game/PacketPlayInBlockPlace.java
+++ b/net/minecraft/network/protocol/game/PacketPlayInBlockPlace.java
@@ -1,3 +1,4 @@
+// mc-dev import
package net.minecraft.network.protocol.game;
import net.minecraft.network.PacketDataSerializer;

View File

@@ -0,0 +1,7 @@
--- a/net/minecraft/network/protocol/game/PacketPlayInUseItem.java
+++ b/net/minecraft/network/protocol/game/PacketPlayInUseItem.java
@@ -1,3 +1,4 @@
+// mc-dev import
package net.minecraft.network.protocol.game;
import net.minecraft.network.PacketDataSerializer;

View File

@@ -0,0 +1,23 @@
--- a/net/minecraft/network/protocol/game/PacketPlayOutMultiBlockChange.java
+++ b/net/minecraft/network/protocol/game/PacketPlayOutMultiBlockChange.java
@@ -33,11 +33,19 @@
short short0 = (Short) shortiterator.next();
this.positions[j] = short0;
- this.states[j] = chunksection.getBlockState(SectionPosition.sectionRelativeX(short0), SectionPosition.sectionRelativeY(short0), SectionPosition.sectionRelativeZ(short0));
+ this.states[j] = (chunksection != null) ? chunksection.getBlockState(SectionPosition.sectionRelativeX(short0), SectionPosition.sectionRelativeY(short0), SectionPosition.sectionRelativeZ(short0)) : net.minecraft.world.level.block.Blocks.AIR.defaultBlockState(); // CraftBukkit - SPIGOT-6076, Mojang bug when empty chunk section notified
}
}
+ // CraftBukkit start - Add constructor
+ public PacketPlayOutMultiBlockChange(SectionPosition sectionposition, ShortSet shortset, IBlockData[] states) {
+ this.sectionPos = sectionposition;
+ this.positions = shortset.toShortArray();
+ this.states = states;
+ }
+ // CraftBukkit end
+
private PacketPlayOutMultiBlockChange(PacketDataSerializer packetdataserializer) {
this.sectionPos = SectionPosition.of(packetdataserializer.readLong());
int i = packetdataserializer.readVarInt();

View File

@@ -0,0 +1,7 @@
--- a/net/minecraft/network/protocol/handshake/PacketHandshakingInSetProtocol.java
+++ b/net/minecraft/network/protocol/handshake/PacketHandshakingInSetProtocol.java
@@ -1,3 +1,4 @@
+// mc-dev import
package net.minecraft.network.protocol.handshake;
import net.minecraft.network.PacketDataSerializer;

View File

@@ -0,0 +1,46 @@
--- a/net/minecraft/network/syncher/DataWatcher.java
+++ b/net/minecraft/network/syncher/DataWatcher.java
@@ -14,6 +14,11 @@
import org.apache.commons.lang3.ObjectUtils;
import org.slf4j.Logger;
+// CraftBukkit start
+import net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata;
+import net.minecraft.server.level.EntityPlayer;
+// CraftBukkit end
+
public class DataWatcher {
private static final Logger LOGGER = LogUtils.getLogger();
@@ -51,7 +56,7 @@
}
private <T> DataWatcher.Item<T> getItem(DataWatcherObject<T> datawatcherobject) {
- return this.itemsById[datawatcherobject.id()];
+ return (DataWatcher.Item<T>) this.itemsById[datawatcherobject.id()]; // CraftBukkit - decompile error
}
public <T> T get(DataWatcherObject<T> datawatcherobject) {
@@ -74,6 +79,13 @@
}
+ // CraftBukkit start - add method from above
+ public <T> void markDirty(DataWatcherObject<T> datawatcherobject) {
+ this.getItem(datawatcherobject).setDirty(true);
+ this.isDirty = true;
+ }
+ // CraftBukkit end
+
public boolean isDirty() {
return this.isDirty;
}
@@ -140,7 +152,7 @@
if (!Objects.equals(datawatcher_c.serializer(), datawatcher_item.accessor.serializer())) {
throw new IllegalStateException(String.format(Locale.ROOT, "Invalid entity data item type for field %d on entity %s: old=%s(%s), new=%s(%s)", datawatcher_item.accessor.id(), this.entity, datawatcher_item.value, datawatcher_item.value.getClass(), datawatcher_c.value, datawatcher_c.value.getClass()));
} else {
- datawatcher_item.setValue(datawatcher_c.value);
+ datawatcher_item.setValue((T) datawatcher_c.value); // CraftBukkit - decompile error
}
}