Skip to content

Commit 40b6c66

Browse files
authored
Update to minecraft 1.18 (#1446)
1 parent 723fc2c commit 40b6c66

31 files changed

+219
-100
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
uses: actions/setup-java@v2
1414
with:
1515
distribution: 'temurin'
16-
java-version: '16'
16+
java-version: '17'
1717

1818
- name: Run maven build lifecycle
1919
run: mvn --batch-mode clean test package

jitpack.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
before_install:
22
- source "$HOME/.sdkman/bin/sdkman-init.sh"
33
- sdk update
4-
- sdk install java 16.0.1.hs-adpt
5-
- sdk use java 16.0.1.hs-adpt
4+
- sdk install java 17.0.1-tem
5+
- sdk use java 17.0.1-tem

pom.xml

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<groupId>com.comphenix.protocol</groupId>
55
<artifactId>ProtocolLib</artifactId>
66
<name>ProtocolLib</name>
7-
<version>4.7.1-SNAPSHOT</version>
7+
<version>4.7.2-SNAPSHOT</version>
88

99
<description>Provides read/write access to the Minecraft protocol.</description>
1010
<url>https://github.com/dmulloy2/ProtocolLib</url>
@@ -16,8 +16,8 @@
1616
<project.build.number></project.build.number>
1717
<project.fullVersion>${project.version}</project.fullVersion>
1818

19-
<powermock.version>2.0.7</powermock.version>
20-
<spigot.version>1.17.1-R0.1-SNAPSHOT</spigot.version>
19+
<powermock.version>2.0.9</powermock.version>
20+
<spigot.version>1.18-R0.1-SNAPSHOT</spigot.version>
2121
</properties>
2222

2323
<build>
@@ -110,13 +110,13 @@
110110
</systemProperties>
111111
<!-- TODO figure out a better way to do this before Java 17 -->
112112
<!-- We're currently waiting on powermock, but we may need to switch -->
113-
<argLine>--illegal-access=permit</argLine>
113+
<argLine>--add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.util.regex=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED</argLine>
114114
</configuration>
115115
</plugin>
116116

117117
<plugin>
118118
<artifactId>maven-javadoc-plugin</artifactId>
119-
<version>3.2.0</version>
119+
<version>3.3.1</version>
120120
<configuration>
121121
<failOnError>false</failOnError>
122122
<encoding>ISO-8859-1</encoding>
@@ -284,6 +284,19 @@
284284
<version>4.0.23.Final</version>
285285
<scope>provided</scope>
286286
</dependency>
287+
<!-- since 1.18 minecraft uses new features of netty but netty is no longer bundled - make sure the new classes are available -->
288+
<dependency>
289+
<groupId>io.netty</groupId>
290+
<artifactId>netty-common</artifactId>
291+
<version>4.1.70.Final</version>
292+
<scope>test</scope>
293+
</dependency>
294+
<dependency>
295+
<groupId>io.netty</groupId>
296+
<artifactId>netty-transport</artifactId>
297+
<version>4.1.70.Final</version>
298+
<scope>test</scope>
299+
</dependency>
287300
<dependency>
288301
<groupId>org.spigotmc</groupId>
289302
<artifactId>spigot-api</artifactId>
@@ -299,27 +312,27 @@
299312
<dependency>
300313
<groupId>net.kyori</groupId>
301314
<artifactId>adventure-text-serializer-gson</artifactId>
302-
<version>4.5.1</version>
315+
<version>4.9.3</version>
303316
<scope>provided</scope>
304317
</dependency>
305318
<!-- https://mvnrepository.com/artifact/net.bytebuddy/byte-buddy -->
306319
<dependency>
307320
<groupId>net.bytebuddy</groupId>
308321
<artifactId>byte-buddy</artifactId>
309-
<version>1.11.0</version>
322+
<version>1.12.1</version>
310323
</dependency>
311324

312325
<!-- Testing dependencies -->
313326
<dependency>
314327
<groupId>junit</groupId>
315328
<artifactId>junit</artifactId>
316-
<version>4.13.1</version>
329+
<version>4.13.2</version>
317330
<scope>test</scope>
318331
</dependency>
319332
<dependency>
320333
<groupId>org.mockito</groupId>
321334
<artifactId>mockito-core</artifactId>
322-
<version>3.5.10</version>
335+
<version>3.12.4</version>
323336
<scope>test</scope>
324337
</dependency>
325338
<dependency>

src/main/java/com/comphenix/protocol/PacketLogging.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.io.ByteArrayOutputStream;
2020
import java.io.File;
2121
import java.io.IOException;
22+
import java.io.OutputStream;
2223
import java.text.MessageFormat;
2324
import java.text.SimpleDateFormat;
2425
import java.util.ArrayList;
@@ -31,13 +32,16 @@
3132
import com.comphenix.protocol.events.PacketEvent;
3233
import com.comphenix.protocol.events.PacketListener;
3334
import com.comphenix.protocol.injector.netty.WirePacket;
35+
import com.comphenix.protocol.reflect.FuzzyReflection;
36+
import com.comphenix.protocol.reflect.accessors.Accessors;
37+
import com.comphenix.protocol.reflect.accessors.MethodAccessor;
38+
import com.comphenix.protocol.utility.MinecraftReflection;
3439
import com.google.common.base.Charsets;
3540

3641
import org.bukkit.ChatColor;
3742
import org.bukkit.command.Command;
3843
import org.bukkit.command.CommandExecutor;
3944
import org.bukkit.command.CommandSender;
40-
import org.bukkit.craftbukkit.libs.org.apache.commons.io.HexDump;
4145
import org.bukkit.plugin.Plugin;
4246

4347
/**
@@ -47,6 +51,8 @@
4751
public class PacketLogging implements CommandExecutor, PacketListener {
4852
public static final String NAME = "packetlog";
4953

54+
private static MethodAccessor HEX_DUMP;
55+
5056
private List<PacketType> sendingTypes = new ArrayList<>();
5157
private List<PacketType> receivingTypes = new ArrayList<>();
5258

@@ -199,7 +205,13 @@ public void onPacketReceiving(PacketEvent event) {
199205

200206
private static String hexDump(byte[] bytes) throws IOException {
201207
try (ByteArrayOutputStream output = new ByteArrayOutputStream()) {
202-
HexDump.dump(bytes, 0, output, 0);
208+
if (HEX_DUMP == null) {
209+
Class<?> hexDumpClass = MinecraftReflection.getLibraryClass("org.apache.commons.io.HexDump");
210+
HEX_DUMP = Accessors.getMethodAccessor(FuzzyReflection.fromClass(hexDumpClass)
211+
.getMethodByParameters("dump", byte[].class, long.class, OutputStream.class, int.class));
212+
}
213+
214+
HEX_DUMP.invoke(null, bytes, 0, output, 0);
203215
return new String(output.toByteArray(), Charsets.UTF_8);
204216
}
205217
}

src/main/java/com/comphenix/protocol/PacketType.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public static class Server extends PacketTypeEnum {
137137
public static final PacketType OPEN_WINDOW_HORSE = new PacketType(PROTOCOL, SENDER, 0x1F, "OpenWindowHorse");
138138
public static final PacketType INITIALIZE_BORDER = new PacketType(PROTOCOL, SENDER, 0x20, "InitializeBorder");
139139
public static final PacketType KEEP_ALIVE = new PacketType(PROTOCOL, SENDER, 0x21, "KeepAlive", "SPacketKeepAlive");
140-
public static final PacketType MAP_CHUNK = new PacketType(PROTOCOL, SENDER, 0x22, "MapChunk", "SPacketChunkData");
140+
public static final PacketType MAP_CHUNK = new PacketType(PROTOCOL, SENDER, 0x22, "MapChunk", "SPacketChunkData", "LevelChunkWithLight");
141141
public static final PacketType WORLD_EVENT = new PacketType(PROTOCOL, SENDER, 0x23, "WorldEvent", "SPacketEffect");
142142
public static final PacketType WORLD_PARTICLES = new PacketType(PROTOCOL, SENDER, 0x24, "WorldParticles", "SPacketParticles");
143143
public static final PacketType LIGHT_UPDATE = new PacketType(PROTOCOL, SENDER, 0x25, "LightUpdate");
@@ -190,22 +190,23 @@ public static class Server extends PacketTypeEnum {
190190
public static final PacketType MOUNT = new PacketType(PROTOCOL, SENDER, 0x54, "Mount", "SPacketSetPassengers");
191191
public static final PacketType SCOREBOARD_TEAM = new PacketType(PROTOCOL, SENDER, 0x55, "ScoreboardTeam", "SPacketTeams");
192192
public static final PacketType SCOREBOARD_SCORE = new PacketType(PROTOCOL, SENDER, 0x56, "ScoreboardScore", "SPacketUpdateScore");
193-
public static final PacketType SET_SUBTITLE_TEXT = new PacketType(PROTOCOL, SENDER, 0x57, "SetSubtitleText");
194-
public static final PacketType UPDATE_TIME = new PacketType(PROTOCOL, SENDER, 0x58, "UpdateTime", "SPacketTimeUpdate");
195-
public static final PacketType SET_TITLE_TEXT = new PacketType(PROTOCOL, SENDER, 0x59, "SetTitleText");
196-
public static final PacketType SET_TITLES_ANIMATION = new PacketType(PROTOCOL, SENDER, 0x5A, "SetTitlesAnimation");
197-
public static final PacketType ENTITY_SOUND = new PacketType(PROTOCOL, SENDER, 0x5B, "EntitySound", "SPacketSoundEffect");
198-
public static final PacketType NAMED_SOUND_EFFECT = new PacketType(PROTOCOL, SENDER, 0x5C, "NamedSoundEffect");
199-
public static final PacketType STOP_SOUND = new PacketType(PROTOCOL, SENDER, 0x5D, "StopSound");
200-
public static final PacketType PLAYER_LIST_HEADER_FOOTER = new PacketType(PROTOCOL, SENDER, 0x5E, "PlayerListHeaderFooter", "SPacketPlayerListHeaderFooter");
201-
public static final PacketType NBT_QUERY = new PacketType(PROTOCOL, SENDER, 0x5F, "NBTQuery");
202-
public static final PacketType COLLECT = new PacketType(PROTOCOL, SENDER, 0x60, "Collect", "SPacketCollectItem");
203-
public static final PacketType ENTITY_TELEPORT = new PacketType(PROTOCOL, SENDER, 0x61, "EntityTeleport", "SPacketEntityTeleport");
204-
public static final PacketType ADVANCEMENTS = new PacketType(PROTOCOL, SENDER, 0x62, "Advancements", "SPacketAdvancementInfo");
205-
public static final PacketType UPDATE_ATTRIBUTES = new PacketType(PROTOCOL, SENDER, 0x63, "UpdateAttributes", "SPacketEntityProperties");
206-
public static final PacketType ENTITY_EFFECT = new PacketType(PROTOCOL, SENDER, 0x64, "EntityEffect", "SPacketEntityEffect");
207-
public static final PacketType RECIPE_UPDATE = new PacketType(PROTOCOL, SENDER, 0x65, "RecipeUpdate");
208-
public static final PacketType TAGS = new PacketType(PROTOCOL, SENDER, 0x66, "Tags");
193+
public static final PacketType UPDATE_SIMULATION_DISTANCE = new PacketType(PROTOCOL, SENDER, 0x57, "SetSimulationDistance");
194+
public static final PacketType SET_SUBTITLE_TEXT = new PacketType(PROTOCOL, SENDER, 0x58, "SetSubtitleText");
195+
public static final PacketType UPDATE_TIME = new PacketType(PROTOCOL, SENDER, 0x59, "UpdateTime", "SPacketTimeUpdate");
196+
public static final PacketType SET_TITLE_TEXT = new PacketType(PROTOCOL, SENDER, 0x5A, "SetTitleText");
197+
public static final PacketType SET_TITLES_ANIMATION = new PacketType(PROTOCOL, SENDER, 0x5B, "SetTitlesAnimation");
198+
public static final PacketType ENTITY_SOUND = new PacketType(PROTOCOL, SENDER, 0x5C, "EntitySound", "SPacketSoundEffect");
199+
public static final PacketType NAMED_SOUND_EFFECT = new PacketType(PROTOCOL, SENDER, 0x5D, "NamedSoundEffect");
200+
public static final PacketType STOP_SOUND = new PacketType(PROTOCOL, SENDER, 0x5E, "StopSound");
201+
public static final PacketType PLAYER_LIST_HEADER_FOOTER = new PacketType(PROTOCOL, SENDER, 0x5F, "PlayerListHeaderFooter", "SPacketPlayerListHeaderFooter");
202+
public static final PacketType NBT_QUERY = new PacketType(PROTOCOL, SENDER, 0x60, "NBTQuery");
203+
public static final PacketType COLLECT = new PacketType(PROTOCOL, SENDER, 0x61, "Collect", "SPacketCollectItem");
204+
public static final PacketType ENTITY_TELEPORT = new PacketType(PROTOCOL, SENDER, 0x62, "EntityTeleport", "SPacketEntityTeleport");
205+
public static final PacketType ADVANCEMENTS = new PacketType(PROTOCOL, SENDER, 0x63, "Advancements", "SPacketAdvancementInfo");
206+
public static final PacketType UPDATE_ATTRIBUTES = new PacketType(PROTOCOL, SENDER, 0x64, "UpdateAttributes", "SPacketEntityProperties");
207+
public static final PacketType ENTITY_EFFECT = new PacketType(PROTOCOL, SENDER, 0x65, "EntityEffect", "SPacketEntityEffect");
208+
public static final PacketType RECIPE_UPDATE = new PacketType(PROTOCOL, SENDER, 0x66, "RecipeUpdate");
209+
public static final PacketType TAGS = new PacketType(PROTOCOL, SENDER, 0x67, "Tags");
209210

210211
// ---- Removed in 1.9
211212

src/main/java/com/comphenix/protocol/ProtocolLibrary.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ public class ProtocolLibrary {
3838
/**
3939
* The maximum version ProtocolLib has been tested with.
4040
*/
41-
public static final String MAXIMUM_MINECRAFT_VERSION = "1.17.1";
41+
public static final String MAXIMUM_MINECRAFT_VERSION = "1.18";
4242

4343
/**
44-
* The date (with ISO 8601 or YYYY-MM-DD) when the most recent version (1.17.1) was released.
44+
* The date (with ISO 8601 or YYYY-MM-DD) when the most recent version (1.18) was released.
4545
*/
46-
public static final String MINECRAFT_LAST_RELEASE_DATE = "2021-07-06";
46+
public static final String MINECRAFT_LAST_RELEASE_DATE = "2021-11-30";
4747

4848
/**
4949
* Plugins that are currently incompatible with ProtocolLib.

src/main/java/com/comphenix/protocol/injector/netty/NettyByteBufAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public class NettyByteBufAdapter extends AbstractByteBuf {
5454
private static FieldAccessor READER_INDEX;
5555
private static FieldAccessor WRITER_INDEX;
5656

57-
private static final int CAPACITY = Short.MAX_VALUE;
57+
private static final int CAPACITY = Integer.MAX_VALUE;
5858

5959
private NettyByteBufAdapter(DataInputStream input, DataOutputStream output) {
6060
// Just pick a figure

src/main/java/com/comphenix/protocol/injector/netty/PipelineProxy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,4 +385,4 @@ public ChannelPromise voidPromise() {
385385
return pipeline.voidPromise();
386386
}
387387
*/
388-
}
388+
}

src/main/java/com/comphenix/protocol/reflect/FieldUtils.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* limitations under the License.
1818
*/
1919

20+
import com.comphenix.protocol.reflect.accessors.Accessors;
2021
import java.lang.reflect.AccessibleObject;
2122
import java.lang.reflect.Field;
2223
import java.lang.reflect.Member;
@@ -442,12 +443,8 @@ public static void writeField(Field field, Object target, Object value, boolean
442443
if (field == null) {
443444
throw new IllegalArgumentException("The field must not be null");
444445
}
445-
if (forceAccess && !field.isAccessible()) {
446-
field.setAccessible(true);
447-
} else {
448-
MemberUtils.setAccessibleWorkaround(field);
449-
}
450-
field.set(target, value);
446+
447+
Accessors.getFieldAccessor(field, forceAccess).set(target, value);
451448
}
452449

453450
/**

src/main/java/com/comphenix/protocol/reflect/accessors/DefaultFieldAccessor.java

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
11
package com.comphenix.protocol.reflect.accessors;
22

3+
import com.comphenix.protocol.ProtocolLogger;
4+
import java.lang.invoke.MethodHandle;
5+
import java.lang.invoke.WrongMethodTypeException;
36
import java.lang.reflect.Field;
47

58
final class DefaultFieldAccessor implements FieldAccessor {
9+
610
private final Field field;
7-
11+
12+
private MethodHandle setter;
13+
814
public DefaultFieldAccessor(Field field) {
915
this.field = field;
16+
// try to get a getter and setter handle for the field
17+
if (UnsafeFieldAccess.hasTrustedLookup()) {
18+
try {
19+
setter = UnsafeFieldAccess.findSetter(field);
20+
} catch (ReflectiveOperationException exception) {
21+
ProtocolLogger.debug("Unable to get setter for field " + field, exception);
22+
}
23+
}
1024
}
11-
25+
1226
@Override
1327
public Object get(Object instance) {
1428
try {
@@ -19,18 +33,25 @@ public Object get(Object instance) {
1933
throw new IllegalStateException("Cannot use reflection.", e);
2034
}
2135
}
22-
36+
2337
@Override
2438
public void set(Object instance, Object value) {
2539
try {
26-
field.set(instance, value);
27-
} catch (IllegalArgumentException e) {
40+
if (setter == null) {
41+
field.set(instance, value);
42+
} else {
43+
setter.invoke(instance, value);
44+
}
45+
} catch (IllegalArgumentException | ClassCastException e) {
2846
throw new RuntimeException("Cannot set field " + field + " to value " + value, e);
29-
} catch (IllegalAccessException e) {
47+
} catch (IllegalAccessException | WrongMethodTypeException e) {
3048
throw new IllegalStateException("Cannot use reflection.", e);
49+
} catch (Throwable ignored) {
50+
// cannot happen - this might only occur when the handle targets a method
51+
throw new RuntimeException("Cannot happen");
3152
}
3253
}
33-
54+
3455
@Override
3556
public Field getField() {
3657
return field;
@@ -43,16 +64,17 @@ public int hashCode() {
4364

4465
@Override
4566
public boolean equals(Object obj) {
46-
if (this == obj)
67+
if (this == obj) {
4768
return true;
48-
69+
}
70+
4971
if (obj instanceof DefaultFieldAccessor) {
5072
DefaultFieldAccessor other = (DefaultFieldAccessor) obj;
5173
return other.field == field;
5274
}
5375
return true;
5476
}
55-
77+
5678
@Override
5779
public String toString() {
5880
return "DefaultFieldAccessor [field=" + field + "]";

0 commit comments

Comments
 (0)