Skip to content

Commit 2ffb933

Browse files
authored
Merge pull request #1174 from booky10/feat/1.21.5-support
1.21.5 support
2 parents d9ddf4e + eb3b959 commit 2ffb933

File tree

251 files changed

+208721
-856
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

251 files changed

+208721
-856
lines changed

.github/workflows/gradle-publish.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
uses: actions/setup-java@v4
2020
with:
2121
java-version: '21'
22-
distribution: 'adopt'
22+
distribution: 'temurin'
2323
cache: 'gradle'
2424
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
2525
settings-path: ${{ github.workspace }} # location for the settings.xml file

api/src/main/java/com/github/retrooper/packetevents/manager/server/ServerVersion.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public enum ServerVersion {
5050
//1.20 and 1.20.1 have the same protocol version. 1.20.3 and 1.20.4 have the same protocol version. 1.20.5 and 1.20.6 have the same protocol version
5151
V_1_20(763), V_1_20_1(763), V_1_20_2(764), V_1_20_3(765), V_1_20_4(765), V_1_20_5(766), V_1_20_6(766),
5252
//1.21 and 1.21.1 have the same protocol version. 1.21.2 and 1.21.3 have the same protocol version
53-
V_1_21(767), V_1_21_1(767), V_1_21_2(768), V_1_21_3(768), V_1_21_4(769),
53+
V_1_21(767), V_1_21_1(767), V_1_21_2(768), V_1_21_3(768), V_1_21_4(769), V_1_21_5(770),
5454
//TODO UPDATE Add server version constant
5555
ERROR(-1, true);
5656

api/src/main/java/com/github/retrooper/packetevents/netty/buffer/ByteBufHelper.java

+13
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,19 @@ public static Object resetWriterIndex(Object buffer) {
239239
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().resetWriterIndex(buffer);
240240
}
241241

242+
public static Object allocateNewBuffer(Object buffer) {
243+
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().allocateNewBuffer(buffer);
244+
}
245+
246+
public static int getByteSize(int value) {
247+
for (int i = 1; i < 5; ++i) {
248+
if ((value & -1 << i * 7) == 0) {
249+
return i;
250+
}
251+
}
252+
return 5;
253+
}
254+
242255
public static int readVarInt(Object buffer) {
243256
int value = 0;
244257
int length = 0;

api/src/main/java/com/github/retrooper/packetevents/netty/buffer/ByteBufOperator.java

+2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ public interface ByteBufOperator {
7474
Object markWriterIndex(Object buffer);
7575
Object resetWriterIndex(Object buffer);
7676

77+
Object allocateNewBuffer(Object buffer);
78+
7779
default float readFloat(Object buffer) {
7880
return Float.intBitsToFloat(readInt(buffer));
7981
}

api/src/main/java/com/github/retrooper/packetevents/protocol/attribute/Attributes.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static Attribute getByName(String name) {
4949
if (normedName.startsWith(ResourceLocation.VANILLA_NAMESPACE + ":generic.")
5050
|| normedName.startsWith(ResourceLocation.VANILLA_NAMESPACE + ":player.")
5151
|| normedName.startsWith(ResourceLocation.VANILLA_NAMESPACE + ":zombie.")) {
52-
normedName = normedName.substring(name.indexOf('.') + 1);
52+
normedName = normedName.substring(normedName.indexOf('.') + 1);
5353
}
5454
return REGISTRY.getByName(normedName);
5555
}

api/src/main/java/com/github/retrooper/packetevents/protocol/chat/ChatTypeDecoration.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public static ChatTypeDecoration decode(NBT nbt, ClientVersion version) {
9090
}
9191
NBTCompound styleTag = compound.getCompoundTagOrNull("style");
9292
Style style = styleTag == null ? empty() :
93-
AdventureSerializer.getNBTSerializer().deserializeStyle(styleTag);
93+
AdventureSerializer.serializer(version).nbt().deserializeStyle(styleTag);
9494
return new ChatTypeDecoration(translationKey, params, style);
9595
}
9696

@@ -104,8 +104,8 @@ public static NBT encode(ChatTypeDecoration decoration, ClientVersion version) {
104104
compound.setTag("translation_key", new NBTString(decoration.translationKey));
105105
compound.setTag("parameters", paramsTag);
106106
if (!decoration.style.isEmpty()) {
107-
compound.setTag("style", AdventureSerializer.getNBTSerializer()
108-
.serializeStyle(decoration.style));
107+
compound.setTag("style", AdventureSerializer.serializer(version)
108+
.nbt().serializeStyle(decoration.style));
109109
}
110110
return compound;
111111
}

api/src/main/java/com/github/retrooper/packetevents/protocol/chat/LastSeenMessages.java

+19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.retrooper.packetevents.protocol.chat;
22

3+
import org.jetbrains.annotations.ApiStatus;
34
import org.jetbrains.annotations.Nullable;
45

56
import java.io.DataOutput;
@@ -86,12 +87,23 @@ public LastSeenMessages getLastSeenMessages() {
8687
}
8788

8889
public static class Update {
90+
8991
private final int offset;
9092
private final BitSet acknowledged;
93+
private final byte checksum;
9194

95+
/**
96+
* Checksum has been added with 1.21.5
97+
*/
98+
@ApiStatus.Obsolete
9299
public Update(int offset, BitSet acknowledged) {
100+
this(offset, acknowledged, (byte) 0);
101+
}
102+
103+
public Update(int offset, BitSet acknowledged, byte checksum) {
93104
this.offset = offset;
94105
this.acknowledged = acknowledged;
106+
this.checksum = checksum;
95107
}
96108

97109
public int getOffset() {
@@ -101,5 +113,12 @@ public int getOffset() {
101113
public BitSet getAcknowledged() {
102114
return acknowledged;
103115
}
116+
117+
/**
118+
* Added with 1.21.5
119+
*/
120+
public byte getChecksum() {
121+
return this.checksum;
122+
}
104123
}
105124
}

api/src/main/java/com/github/retrooper/packetevents/protocol/chat/Parsers.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ public static VersionedRegistry<Parser> getRegistry() {
148148
public static final Parser STYLE = define("style", null, null);
149149
public static final Parser MESSAGE = define("message", null, null);
150150
public static final Parser NBT_COMPOUND_TAG = define("nbt_compound_tag", null, null);
151-
@Deprecated
152-
public static final Parser NBT = NBT_COMPOUND_TAG;
151+
@ApiStatus.Obsolete
152+
public static final Parser NBT = define("nbt", null, null);
153153
public static final Parser NBT_TAG = define("nbt_tag", null, null);
154154
public static final Parser NBT_PATH = define("nbt_path", null, null);
155155
public static final Parser OBJECTIVE = define("objective", null, null);
@@ -210,6 +210,14 @@ public static VersionedRegistry<Parser> getRegistry() {
210210
public static final Parser LOOT_MODIFIER = define("loot_modifier", null, null);
211211
public static final Parser UUID = define("uuid", null, null);
212212

213+
/**
214+
* Added with 1.21.5
215+
*/
216+
public static final Parser RESOURCE_SELECTOR = define("resource_selector",
217+
wrapper -> Collections.singletonList(wrapper.readIdentifier()),
218+
(wrapper, value) -> wrapper.writeIdentifier((ResourceLocation) value.get(0))
219+
);
220+
213221
static {
214222
REGISTRY.unloadMappings();
215223
}

api/src/main/java/com/github/retrooper/packetevents/protocol/chat/message/ChatMessage_v1_19_3.java

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import java.time.Instant;
1111
import java.util.Optional;
1212
import java.util.UUID;
13-
//We'll extend ChatMessage_v1_16 for now, hopefully no breaking changes in the future
1413
public class ChatMessage_v1_19_3 extends ChatMessage_v1_16 {
1514
int index;
1615
byte[] signature;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* This file is part of packetevents - https://github.com/retrooper/packetevents
3+
* Copyright (C) 2025 retrooper and contributors
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
package com.github.retrooper.packetevents.protocol.chat.message;
20+
21+
import com.github.retrooper.packetevents.protocol.chat.ChatType;
22+
import com.github.retrooper.packetevents.protocol.chat.LastSeenMessages;
23+
import com.github.retrooper.packetevents.protocol.chat.filter.FilterMask;
24+
import net.kyori.adventure.text.Component;
25+
import org.jetbrains.annotations.Nullable;
26+
27+
import java.time.Instant;
28+
import java.util.UUID;
29+
30+
//We'll extend ChatMessage_v1_19_3 for now, hopefully no breaking changes in the future
31+
public class ChatMessage_v1_21_5 extends ChatMessage_v1_19_3 {
32+
33+
int globalIndex;
34+
35+
public ChatMessage_v1_21_5(int globalIndex, UUID senderUUID, int index, byte[] signature, String plainContent,
36+
Instant timestamp, long salt, LastSeenMessages.Packed lastSeenMessagesPacked, @Nullable Component unsignedChatContent,
37+
FilterMask filterMask, ChatType.Bound chatFormatting) {
38+
super(senderUUID, index, signature, plainContent, timestamp, salt, lastSeenMessagesPacked, unsignedChatContent, filterMask, chatFormatting);
39+
this.globalIndex = globalIndex;
40+
}
41+
42+
public int getGlobalIndex() {
43+
return this.globalIndex;
44+
}
45+
46+
public void setGlobalIndex(int globalIndex) {
47+
this.globalIndex = globalIndex;
48+
}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* This file is part of packetevents - https://github.com/retrooper/packetevents
3+
* Copyright (C) 2025 retrooper and contributors
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
package com.github.retrooper.packetevents.protocol.chat.message.reader.impl;
20+
21+
import com.github.retrooper.packetevents.protocol.chat.ChatType;
22+
import com.github.retrooper.packetevents.protocol.chat.LastSeenMessages;
23+
import com.github.retrooper.packetevents.protocol.chat.filter.FilterMask;
24+
import com.github.retrooper.packetevents.protocol.chat.message.ChatMessage;
25+
import com.github.retrooper.packetevents.protocol.chat.message.ChatMessage_v1_21_5;
26+
import com.github.retrooper.packetevents.protocol.chat.message.reader.ChatMessageProcessor;
27+
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
28+
import net.kyori.adventure.text.Component;
29+
import org.jetbrains.annotations.NotNull;
30+
31+
import java.time.Instant;
32+
import java.util.UUID;
33+
34+
public class ChatMessageProcessor_v1_21_5 implements ChatMessageProcessor {
35+
36+
@Override
37+
public ChatMessage readChatMessage(@NotNull PacketWrapper<?> wrapper) {
38+
int globalIndex = wrapper.readVarInt();
39+
UUID senderUUID = wrapper.readUUID();
40+
int index = wrapper.readVarInt();
41+
byte[] signature = wrapper.readOptional((w) -> w.readBytes(256));
42+
String plainContent = wrapper.readString(256);
43+
Instant timestamp = wrapper.readTimestamp();
44+
long salt = wrapper.readLong();
45+
LastSeenMessages.Packed lastSeenMessagesPacked = wrapper.readLastSeenMessagesPacked();
46+
Component unsignedChatContent = wrapper.readOptional(PacketWrapper::readComponent);
47+
FilterMask filterMask = wrapper.readFilterMask();
48+
ChatType.Bound chatType = wrapper.readChatTypeBoundNetwork();
49+
50+
return new ChatMessage_v1_21_5(globalIndex, senderUUID, index, signature, plainContent, timestamp, salt, lastSeenMessagesPacked, unsignedChatContent, filterMask, chatType);
51+
}
52+
53+
@Override
54+
public void writeChatMessage(@NotNull PacketWrapper<?> wrapper, @NotNull ChatMessage data) {
55+
ChatMessage_v1_21_5 newData = (ChatMessage_v1_21_5) data;
56+
wrapper.writeInt(newData.getGlobalIndex());
57+
wrapper.writeUUID(newData.getSenderUUID());
58+
wrapper.writeVarInt(newData.getIndex());
59+
wrapper.writeOptional(newData.getSignature(), PacketWrapper::writeBytes);
60+
wrapper.writeString(newData.getPlainContent());
61+
wrapper.writeTimestamp(newData.getTimestamp());
62+
wrapper.writeLong(newData.getSalt());
63+
wrapper.writeLastSeenMessagesPacked(newData.getLastSeenMessagesPacked());
64+
wrapper.writeOptional(newData.getUnsignedChatContent().orElse(null), PacketWrapper::writeComponent);
65+
wrapper.writeFilterMask(newData.getFilterMask());
66+
wrapper.writeChatTypeBoundNetwork(newData.getChatFormatting());
67+
}
68+
}

api/src/main/java/com/github/retrooper/packetevents/protocol/color/DyeColor.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
package com.github.retrooper.packetevents.protocol.color;
2020

21+
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
2122
import net.kyori.adventure.util.RGBLike;
2223
import org.jetbrains.annotations.NotNull;
2324

@@ -54,6 +55,8 @@ public enum DyeColor implements RGBLike {
5455

5556
BLACK(new Color(0x1d1d21), new Color(0x0), new Color(0x1e1b1b), 29);
5657

58+
private static final DyeColor[] COLORS = values();
59+
5760
private final Color textureDiffuseColor;
5861

5962
private final Color textColor;
@@ -70,6 +73,14 @@ public enum DyeColor implements RGBLike {
7073
this.mapColorId = mapColorId;
7174
}
7275

76+
public static DyeColor read(PacketWrapper<?> wrapper) {
77+
return wrapper.readEnum(COLORS);
78+
}
79+
80+
public static void write(PacketWrapper<?> wrapper, DyeColor color) {
81+
wrapper.writeEnum(color);
82+
}
83+
7384
public @NotNull Color color() {
7485
return this.textureDiffuseColor;
7586
}
@@ -100,4 +111,4 @@ public int blue() {
100111
public int mapColorId() {
101112
return this.mapColorId;
102113
}
103-
}
114+
}

api/src/main/java/com/github/retrooper/packetevents/protocol/component/ComponentPredicate.java

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ public class ComponentPredicate implements Predicate<IComponentMap> {
3131

3232
private List<ComponentValue<?>> requiredComponents;
3333

34+
public ComponentPredicate() {
35+
this(new ArrayList<>());
36+
}
37+
3438
public ComponentPredicate(List<ComponentValue<?>> requiredComponents) {
3539
this.requiredComponents = requiredComponents;
3640
}

0 commit comments

Comments
 (0)