mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2025-01-05 16:08:06 +01:00
Update to minecraft 1.18 (#1446)
This commit is contained in:
parent
723fc2c7ec
commit
40b6c66491
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@ -13,7 +13,7 @@ jobs:
|
||||
uses: actions/setup-java@v2
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: '16'
|
||||
java-version: '17'
|
||||
|
||||
- name: Run maven build lifecycle
|
||||
run: mvn --batch-mode clean test package
|
||||
|
@ -1,5 +1,5 @@
|
||||
before_install:
|
||||
- source "$HOME/.sdkman/bin/sdkman-init.sh"
|
||||
- sdk update
|
||||
- sdk install java 16.0.1.hs-adpt
|
||||
- sdk use java 16.0.1.hs-adpt
|
||||
- sdk install java 17.0.1-tem
|
||||
- sdk use java 17.0.1-tem
|
||||
|
31
pom.xml
31
pom.xml
@ -4,7 +4,7 @@
|
||||
<groupId>com.comphenix.protocol</groupId>
|
||||
<artifactId>ProtocolLib</artifactId>
|
||||
<name>ProtocolLib</name>
|
||||
<version>4.7.1-SNAPSHOT</version>
|
||||
<version>4.7.2-SNAPSHOT</version>
|
||||
|
||||
<description>Provides read/write access to the Minecraft protocol.</description>
|
||||
<url>https://github.com/dmulloy2/ProtocolLib</url>
|
||||
@ -16,8 +16,8 @@
|
||||
<project.build.number></project.build.number>
|
||||
<project.fullVersion>${project.version}</project.fullVersion>
|
||||
|
||||
<powermock.version>2.0.7</powermock.version>
|
||||
<spigot.version>1.17.1-R0.1-SNAPSHOT</spigot.version>
|
||||
<powermock.version>2.0.9</powermock.version>
|
||||
<spigot.version>1.18-R0.1-SNAPSHOT</spigot.version>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
@ -110,13 +110,13 @@
|
||||
</systemProperties>
|
||||
<!-- TODO figure out a better way to do this before Java 17 -->
|
||||
<!-- We're currently waiting on powermock, but we may need to switch -->
|
||||
<argLine>--illegal-access=permit</argLine>
|
||||
<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>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<version>3.3.1</version>
|
||||
<configuration>
|
||||
<failOnError>false</failOnError>
|
||||
<encoding>ISO-8859-1</encoding>
|
||||
@ -284,6 +284,19 @@
|
||||
<version>4.0.23.Final</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- since 1.18 minecraft uses new features of netty but netty is no longer bundled - make sure the new classes are available -->
|
||||
<dependency>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-common</artifactId>
|
||||
<version>4.1.70.Final</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-transport</artifactId>
|
||||
<version>4.1.70.Final</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
@ -299,27 +312,27 @@
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-text-serializer-gson</artifactId>
|
||||
<version>4.5.1</version>
|
||||
<version>4.9.3</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/net.bytebuddy/byte-buddy -->
|
||||
<dependency>
|
||||
<groupId>net.bytebuddy</groupId>
|
||||
<artifactId>byte-buddy</artifactId>
|
||||
<version>1.11.0</version>
|
||||
<version>1.12.1</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Testing dependencies -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.13.1</version>
|
||||
<version>4.13.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<version>3.5.10</version>
|
||||
<version>3.12.4</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -19,6 +19,7 @@ package com.comphenix.protocol;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.text.MessageFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
@ -31,13 +32,16 @@ import com.comphenix.protocol.events.ListeningWhitelist;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.events.PacketListener;
|
||||
import com.comphenix.protocol.injector.netty.WirePacket;
|
||||
import com.comphenix.protocol.reflect.FuzzyReflection;
|
||||
import com.comphenix.protocol.reflect.accessors.Accessors;
|
||||
import com.comphenix.protocol.reflect.accessors.MethodAccessor;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
import com.google.common.base.Charsets;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.craftbukkit.libs.org.apache.commons.io.HexDump;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
/**
|
||||
@ -47,6 +51,8 @@ import org.bukkit.plugin.Plugin;
|
||||
public class PacketLogging implements CommandExecutor, PacketListener {
|
||||
public static final String NAME = "packetlog";
|
||||
|
||||
private static MethodAccessor HEX_DUMP;
|
||||
|
||||
private List<PacketType> sendingTypes = new ArrayList<>();
|
||||
private List<PacketType> receivingTypes = new ArrayList<>();
|
||||
|
||||
@ -199,7 +205,13 @@ public class PacketLogging implements CommandExecutor, PacketListener {
|
||||
|
||||
private static String hexDump(byte[] bytes) throws IOException {
|
||||
try (ByteArrayOutputStream output = new ByteArrayOutputStream()) {
|
||||
HexDump.dump(bytes, 0, output, 0);
|
||||
if (HEX_DUMP == null) {
|
||||
Class<?> hexDumpClass = MinecraftReflection.getLibraryClass("org.apache.commons.io.HexDump");
|
||||
HEX_DUMP = Accessors.getMethodAccessor(FuzzyReflection.fromClass(hexDumpClass)
|
||||
.getMethodByParameters("dump", byte[].class, long.class, OutputStream.class, int.class));
|
||||
}
|
||||
|
||||
HEX_DUMP.invoke(null, bytes, 0, output, 0);
|
||||
return new String(output.toByteArray(), Charsets.UTF_8);
|
||||
}
|
||||
}
|
||||
|
@ -137,7 +137,7 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
||||
public static final PacketType OPEN_WINDOW_HORSE = new PacketType(PROTOCOL, SENDER, 0x1F, "OpenWindowHorse");
|
||||
public static final PacketType INITIALIZE_BORDER = new PacketType(PROTOCOL, SENDER, 0x20, "InitializeBorder");
|
||||
public static final PacketType KEEP_ALIVE = new PacketType(PROTOCOL, SENDER, 0x21, "KeepAlive", "SPacketKeepAlive");
|
||||
public static final PacketType MAP_CHUNK = new PacketType(PROTOCOL, SENDER, 0x22, "MapChunk", "SPacketChunkData");
|
||||
public static final PacketType MAP_CHUNK = new PacketType(PROTOCOL, SENDER, 0x22, "MapChunk", "SPacketChunkData", "LevelChunkWithLight");
|
||||
public static final PacketType WORLD_EVENT = new PacketType(PROTOCOL, SENDER, 0x23, "WorldEvent", "SPacketEffect");
|
||||
public static final PacketType WORLD_PARTICLES = new PacketType(PROTOCOL, SENDER, 0x24, "WorldParticles", "SPacketParticles");
|
||||
public static final PacketType LIGHT_UPDATE = new PacketType(PROTOCOL, SENDER, 0x25, "LightUpdate");
|
||||
@ -190,22 +190,23 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
||||
public static final PacketType MOUNT = new PacketType(PROTOCOL, SENDER, 0x54, "Mount", "SPacketSetPassengers");
|
||||
public static final PacketType SCOREBOARD_TEAM = new PacketType(PROTOCOL, SENDER, 0x55, "ScoreboardTeam", "SPacketTeams");
|
||||
public static final PacketType SCOREBOARD_SCORE = new PacketType(PROTOCOL, SENDER, 0x56, "ScoreboardScore", "SPacketUpdateScore");
|
||||
public static final PacketType SET_SUBTITLE_TEXT = new PacketType(PROTOCOL, SENDER, 0x57, "SetSubtitleText");
|
||||
public static final PacketType UPDATE_TIME = new PacketType(PROTOCOL, SENDER, 0x58, "UpdateTime", "SPacketTimeUpdate");
|
||||
public static final PacketType SET_TITLE_TEXT = new PacketType(PROTOCOL, SENDER, 0x59, "SetTitleText");
|
||||
public static final PacketType SET_TITLES_ANIMATION = new PacketType(PROTOCOL, SENDER, 0x5A, "SetTitlesAnimation");
|
||||
public static final PacketType ENTITY_SOUND = new PacketType(PROTOCOL, SENDER, 0x5B, "EntitySound", "SPacketSoundEffect");
|
||||
public static final PacketType NAMED_SOUND_EFFECT = new PacketType(PROTOCOL, SENDER, 0x5C, "NamedSoundEffect");
|
||||
public static final PacketType STOP_SOUND = new PacketType(PROTOCOL, SENDER, 0x5D, "StopSound");
|
||||
public static final PacketType PLAYER_LIST_HEADER_FOOTER = new PacketType(PROTOCOL, SENDER, 0x5E, "PlayerListHeaderFooter", "SPacketPlayerListHeaderFooter");
|
||||
public static final PacketType NBT_QUERY = new PacketType(PROTOCOL, SENDER, 0x5F, "NBTQuery");
|
||||
public static final PacketType COLLECT = new PacketType(PROTOCOL, SENDER, 0x60, "Collect", "SPacketCollectItem");
|
||||
public static final PacketType ENTITY_TELEPORT = new PacketType(PROTOCOL, SENDER, 0x61, "EntityTeleport", "SPacketEntityTeleport");
|
||||
public static final PacketType ADVANCEMENTS = new PacketType(PROTOCOL, SENDER, 0x62, "Advancements", "SPacketAdvancementInfo");
|
||||
public static final PacketType UPDATE_ATTRIBUTES = new PacketType(PROTOCOL, SENDER, 0x63, "UpdateAttributes", "SPacketEntityProperties");
|
||||
public static final PacketType ENTITY_EFFECT = new PacketType(PROTOCOL, SENDER, 0x64, "EntityEffect", "SPacketEntityEffect");
|
||||
public static final PacketType RECIPE_UPDATE = new PacketType(PROTOCOL, SENDER, 0x65, "RecipeUpdate");
|
||||
public static final PacketType TAGS = new PacketType(PROTOCOL, SENDER, 0x66, "Tags");
|
||||
public static final PacketType UPDATE_SIMULATION_DISTANCE = new PacketType(PROTOCOL, SENDER, 0x57, "SetSimulationDistance");
|
||||
public static final PacketType SET_SUBTITLE_TEXT = new PacketType(PROTOCOL, SENDER, 0x58, "SetSubtitleText");
|
||||
public static final PacketType UPDATE_TIME = new PacketType(PROTOCOL, SENDER, 0x59, "UpdateTime", "SPacketTimeUpdate");
|
||||
public static final PacketType SET_TITLE_TEXT = new PacketType(PROTOCOL, SENDER, 0x5A, "SetTitleText");
|
||||
public static final PacketType SET_TITLES_ANIMATION = new PacketType(PROTOCOL, SENDER, 0x5B, "SetTitlesAnimation");
|
||||
public static final PacketType ENTITY_SOUND = new PacketType(PROTOCOL, SENDER, 0x5C, "EntitySound", "SPacketSoundEffect");
|
||||
public static final PacketType NAMED_SOUND_EFFECT = new PacketType(PROTOCOL, SENDER, 0x5D, "NamedSoundEffect");
|
||||
public static final PacketType STOP_SOUND = new PacketType(PROTOCOL, SENDER, 0x5E, "StopSound");
|
||||
public static final PacketType PLAYER_LIST_HEADER_FOOTER = new PacketType(PROTOCOL, SENDER, 0x5F, "PlayerListHeaderFooter", "SPacketPlayerListHeaderFooter");
|
||||
public static final PacketType NBT_QUERY = new PacketType(PROTOCOL, SENDER, 0x60, "NBTQuery");
|
||||
public static final PacketType COLLECT = new PacketType(PROTOCOL, SENDER, 0x61, "Collect", "SPacketCollectItem");
|
||||
public static final PacketType ENTITY_TELEPORT = new PacketType(PROTOCOL, SENDER, 0x62, "EntityTeleport", "SPacketEntityTeleport");
|
||||
public static final PacketType ADVANCEMENTS = new PacketType(PROTOCOL, SENDER, 0x63, "Advancements", "SPacketAdvancementInfo");
|
||||
public static final PacketType UPDATE_ATTRIBUTES = new PacketType(PROTOCOL, SENDER, 0x64, "UpdateAttributes", "SPacketEntityProperties");
|
||||
public static final PacketType ENTITY_EFFECT = new PacketType(PROTOCOL, SENDER, 0x65, "EntityEffect", "SPacketEntityEffect");
|
||||
public static final PacketType RECIPE_UPDATE = new PacketType(PROTOCOL, SENDER, 0x66, "RecipeUpdate");
|
||||
public static final PacketType TAGS = new PacketType(PROTOCOL, SENDER, 0x67, "Tags");
|
||||
|
||||
// ---- Removed in 1.9
|
||||
|
||||
|
@ -38,12 +38,12 @@ public class ProtocolLibrary {
|
||||
/**
|
||||
* The maximum version ProtocolLib has been tested with.
|
||||
*/
|
||||
public static final String MAXIMUM_MINECRAFT_VERSION = "1.17.1";
|
||||
public static final String MAXIMUM_MINECRAFT_VERSION = "1.18";
|
||||
|
||||
/**
|
||||
* The date (with ISO 8601 or YYYY-MM-DD) when the most recent version (1.17.1) was released.
|
||||
* The date (with ISO 8601 or YYYY-MM-DD) when the most recent version (1.18) was released.
|
||||
*/
|
||||
public static final String MINECRAFT_LAST_RELEASE_DATE = "2021-07-06";
|
||||
public static final String MINECRAFT_LAST_RELEASE_DATE = "2021-11-30";
|
||||
|
||||
/**
|
||||
* Plugins that are currently incompatible with ProtocolLib.
|
||||
|
@ -54,7 +54,7 @@ public class NettyByteBufAdapter extends AbstractByteBuf {
|
||||
private static FieldAccessor READER_INDEX;
|
||||
private static FieldAccessor WRITER_INDEX;
|
||||
|
||||
private static final int CAPACITY = Short.MAX_VALUE;
|
||||
private static final int CAPACITY = Integer.MAX_VALUE;
|
||||
|
||||
private NettyByteBufAdapter(DataInputStream input, DataOutputStream output) {
|
||||
// Just pick a figure
|
||||
|
@ -385,4 +385,4 @@ public class PipelineProxy implements ChannelPipeline {
|
||||
return pipeline.voidPromise();
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
@ -17,6 +17,7 @@ package com.comphenix.protocol.reflect;
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import com.comphenix.protocol.reflect.accessors.Accessors;
|
||||
import java.lang.reflect.AccessibleObject;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Member;
|
||||
@ -442,12 +443,8 @@ public class FieldUtils {
|
||||
if (field == null) {
|
||||
throw new IllegalArgumentException("The field must not be null");
|
||||
}
|
||||
if (forceAccess && !field.isAccessible()) {
|
||||
field.setAccessible(true);
|
||||
} else {
|
||||
MemberUtils.setAccessibleWorkaround(field);
|
||||
}
|
||||
field.set(target, value);
|
||||
|
||||
Accessors.getFieldAccessor(field, forceAccess).set(target, value);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,14 +1,28 @@
|
||||
package com.comphenix.protocol.reflect.accessors;
|
||||
|
||||
import com.comphenix.protocol.ProtocolLogger;
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.WrongMethodTypeException;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
final class DefaultFieldAccessor implements FieldAccessor {
|
||||
|
||||
private final Field field;
|
||||
|
||||
|
||||
private MethodHandle setter;
|
||||
|
||||
public DefaultFieldAccessor(Field field) {
|
||||
this.field = field;
|
||||
// try to get a getter and setter handle for the field
|
||||
if (UnsafeFieldAccess.hasTrustedLookup()) {
|
||||
try {
|
||||
setter = UnsafeFieldAccess.findSetter(field);
|
||||
} catch (ReflectiveOperationException exception) {
|
||||
ProtocolLogger.debug("Unable to get setter for field " + field, exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object get(Object instance) {
|
||||
try {
|
||||
@ -19,18 +33,25 @@ final class DefaultFieldAccessor implements FieldAccessor {
|
||||
throw new IllegalStateException("Cannot use reflection.", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void set(Object instance, Object value) {
|
||||
try {
|
||||
field.set(instance, value);
|
||||
} catch (IllegalArgumentException e) {
|
||||
if (setter == null) {
|
||||
field.set(instance, value);
|
||||
} else {
|
||||
setter.invoke(instance, value);
|
||||
}
|
||||
} catch (IllegalArgumentException | ClassCastException e) {
|
||||
throw new RuntimeException("Cannot set field " + field + " to value " + value, e);
|
||||
} catch (IllegalAccessException e) {
|
||||
} catch (IllegalAccessException | WrongMethodTypeException e) {
|
||||
throw new IllegalStateException("Cannot use reflection.", e);
|
||||
} catch (Throwable ignored) {
|
||||
// cannot happen - this might only occur when the handle targets a method
|
||||
throw new RuntimeException("Cannot happen");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Field getField() {
|
||||
return field;
|
||||
@ -43,16 +64,17 @@ final class DefaultFieldAccessor implements FieldAccessor {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
if (this == obj) {
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
if (obj instanceof DefaultFieldAccessor) {
|
||||
DefaultFieldAccessor other = (DefaultFieldAccessor) obj;
|
||||
return other.field == field;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DefaultFieldAccessor [field=" + field + "]";
|
||||
|
@ -0,0 +1,48 @@
|
||||
package com.comphenix.protocol.reflect.accessors;
|
||||
|
||||
import com.comphenix.protocol.ProtocolLogger;
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles.Lookup;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.logging.Level;
|
||||
|
||||
final class UnsafeFieldAccess {
|
||||
|
||||
private static final Lookup TRUSTED_LOOKUP;
|
||||
|
||||
static {
|
||||
Lookup trusted = null;
|
||||
try {
|
||||
// get the unsafe class
|
||||
Class<?> unsafeClass = Class.forName("sun.misc.Unsafe");
|
||||
// get the unsafe instance
|
||||
Field theUnsafe = unsafeClass.getDeclaredField("theUnsafe");
|
||||
theUnsafe.setAccessible(true);
|
||||
sun.misc.Unsafe unsafe = (sun.misc.Unsafe) theUnsafe.get(null);
|
||||
// get the trusted lookup field
|
||||
Field trustedLookup = Lookup.class.getDeclaredField("IMPL_LOOKUP");
|
||||
// get access to the base and offset value of it
|
||||
long offset = unsafe.staticFieldOffset(trustedLookup);
|
||||
Object baseValue = unsafe.staticFieldBase(trustedLookup);
|
||||
// get the trusted lookup instance
|
||||
trusted = (Lookup) unsafe.getObject(baseValue, offset);
|
||||
} catch (Exception exception) {
|
||||
ProtocolLogger.log(Level.SEVERE, "Unable to retrieve trusted lookup", exception);
|
||||
}
|
||||
|
||||
TRUSTED_LOOKUP = trusted;
|
||||
}
|
||||
|
||||
public static boolean hasTrustedLookup() {
|
||||
return TRUSTED_LOOKUP != null;
|
||||
}
|
||||
|
||||
public static MethodHandle findSetter(Field field) throws ReflectiveOperationException {
|
||||
if (Modifier.isStatic(field.getModifiers())) {
|
||||
return TRUSTED_LOOKUP.findStaticSetter(field.getDeclaringClass(), field.getName(), field.getType());
|
||||
} else {
|
||||
return TRUSTED_LOOKUP.findSetter(field.getDeclaringClass(), field.getName(), field.getType());
|
||||
}
|
||||
}
|
||||
}
|
@ -21,10 +21,10 @@ package com.comphenix.protocol.utility;
|
||||
*/
|
||||
|
||||
public final class Constants {
|
||||
public static final String PACKAGE_VERSION = "v1_17_R1";
|
||||
public static final String PACKAGE_VERSION = "v1_18_R1";
|
||||
public static final String NMS = "net.minecraft";
|
||||
public static final String OBC = "org.bukkit.craftbukkit." + PACKAGE_VERSION;
|
||||
public static final MinecraftVersion CURRENT_VERSION = MinecraftVersion.CAVES_CLIFFS_1;
|
||||
public static final MinecraftVersion CURRENT_VERSION = MinecraftVersion.CAVES_CLIFFS_2;
|
||||
|
||||
public static void init() {
|
||||
MinecraftReflection.setMinecraftPackage(NMS, OBC);
|
||||
|
@ -76,6 +76,8 @@ public class MinecraftProtocolVersion {
|
||||
|
||||
map.put(new MinecraftVersion(1, 17, 0), 755);
|
||||
map.put(new MinecraftVersion(1, 17, 1), 756);
|
||||
|
||||
map.put(new MinecraftVersion(1, 18, 0), 757);
|
||||
return map;
|
||||
}
|
||||
|
||||
|
@ -2267,13 +2267,7 @@ public class MinecraftReflection {
|
||||
}
|
||||
|
||||
public static Class<?> getFastUtilClass(String className) {
|
||||
try {
|
||||
return getMinecraftLibraryClass("it.unimi.dsi.fastutil." + className);
|
||||
} catch (RuntimeException ex) {
|
||||
Class<?> clazz = getMinecraftLibraryClass("org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil." + className);
|
||||
setMinecraftLibraryClass("it.unimi.dsi.fastutil." + className, clazz);
|
||||
return clazz;
|
||||
}
|
||||
return getLibraryClass("it.unimi.dsi.fastutil." + className);
|
||||
}
|
||||
|
||||
public static Class<?> getInt2ObjectMapClass() {
|
||||
@ -2283,4 +2277,14 @@ public class MinecraftReflection {
|
||||
public static Class<?> getIntArrayListClass() {
|
||||
return getFastUtilClass("ints.IntArrayList");
|
||||
}
|
||||
|
||||
public static Class<?> getLibraryClass(String classname) {
|
||||
try {
|
||||
return getMinecraftLibraryClass(classname);
|
||||
} catch (RuntimeException ex) {
|
||||
Class<?> clazz = getMinecraftLibraryClass("org.bukkit.craftbukkit.libs." + classname);
|
||||
setMinecraftLibraryClass(classname, clazz);
|
||||
return clazz;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -44,6 +44,11 @@ public class MinecraftVersion implements Comparable<MinecraftVersion>, Serializa
|
||||
*/
|
||||
private static final Pattern VERSION_PATTERN = Pattern.compile(".*\\(.*MC.\\s*([a-zA-z0-9\\-.]+).*");
|
||||
|
||||
/**
|
||||
* Version 1.18 - caves and cliffs part 2
|
||||
*/
|
||||
public static final MinecraftVersion CAVES_CLIFFS_2 = new MinecraftVersion("1.18");
|
||||
|
||||
/**
|
||||
* Version 1.17 - caves and cliffs part 1
|
||||
*/
|
||||
|
@ -738,4 +738,4 @@ public class ZeroBuffer extends ByteBuf {
|
||||
public ByteBuf retain() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -495,7 +495,7 @@ public class WrappedDataWatcher extends AbstractWrapper implements Iterable<Wrap
|
||||
.build();
|
||||
List<Method> methods = fuzzy.getMethodList(contract);
|
||||
for (Method method : methods) {
|
||||
if (method.getName().equals("set") || method.getName().equals("watch")) {
|
||||
if (method.getName().equals("set") || method.getName().equals("watch") || method.getName().equals("b")) {
|
||||
SETTER = Accessors.getMethodAccessor(method);
|
||||
} else {
|
||||
REGISTER = Accessors.getMethodAccessor(method);
|
||||
|
@ -5,10 +5,10 @@ import com.comphenix.protocol.reflect.accessors.Accessors;
|
||||
import com.comphenix.protocol.reflect.accessors.MethodAccessor;
|
||||
import com.comphenix.protocol.reflect.fuzzy.FuzzyMethodContract;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
import com.comphenix.protocol.utility.MinecraftVersion;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.HashMap;
|
||||
@ -46,9 +46,14 @@ public class WrappedRegistry {
|
||||
|
||||
REGISTRY = ImmutableMap.copyOf(regMap);
|
||||
|
||||
GET = Accessors.getMethodAccessor(regClass, "get", MinecraftReflection.getMinecraftKeyClass());
|
||||
|
||||
FuzzyReflection fuzzy = FuzzyReflection.fromClass(regClass, false);
|
||||
GET = Accessors.getMethodAccessor(fuzzy.getMethod(FuzzyMethodContract
|
||||
.newBuilder()
|
||||
.parameterCount(1)
|
||||
.returnDerivedOf(Object.class)
|
||||
.requireModifier(Modifier.ABSTRACT)
|
||||
.parameterExactType(MinecraftReflection.getMinecraftKeyClass())
|
||||
.build()));
|
||||
GET_KEY = Accessors.getMethodAccessor(fuzzy.getMethod(FuzzyMethodContract
|
||||
.newBuilder()
|
||||
.parameterCount(1)
|
||||
|
@ -33,7 +33,7 @@ import com.google.common.io.Files;
|
||||
// TODO Migrate this to Gradle if necessary
|
||||
// Damn final classes ...
|
||||
@RunWith(org.powermock.modules.junit4.PowerMockRunner.class)
|
||||
@PowerMockIgnore({ "org.apache.log4j.*", "org.apache.logging.*", "org.bukkit.craftbukkit.libs.jline.*" })
|
||||
@PowerMockIgnore({ "org.apache.logging.log4j.core.config.xml.*", "javax.management.*" })
|
||||
@PrepareForTest(PluginDescriptionFile.class)
|
||||
public class SimpleCraftBukkitITCase {
|
||||
// The fake plugin
|
||||
|
@ -5,7 +5,6 @@ import java.util.List;
|
||||
|
||||
import com.comphenix.protocol.reflect.FieldUtils;
|
||||
import com.comphenix.protocol.utility.Constants;
|
||||
import com.mojang.bridge.game.GameVersion;
|
||||
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.core.IRegistry;
|
||||
@ -16,10 +15,10 @@ import org.apache.logging.log4j.LogManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemFactory;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.util.Versioning;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemFactory;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.util.Versioning;
|
||||
import org.spigotmc.SpigotWorldConfig;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
@ -81,7 +80,7 @@ public class BukkitInitialization {
|
||||
instance.setPackage();
|
||||
|
||||
SharedConstants.a();
|
||||
DispenserRegistry.init();
|
||||
DispenserRegistry.a();
|
||||
|
||||
try {
|
||||
IRegistry.class.getName();
|
||||
@ -89,12 +88,15 @@ public class BukkitInitialization {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
String releaseTarget = SharedConstants.b().getReleaseTarget();
|
||||
String serverVersion = CraftServer.class.getPackage().getImplementationVersion();
|
||||
|
||||
// Mock the server object
|
||||
Server mockedServer = mock(Server.class);
|
||||
|
||||
when(mockedServer.getLogger()).thenReturn(java.util.logging.Logger.getLogger("Minecraft"));
|
||||
when(mockedServer.getName()).thenReturn("Mock Server");
|
||||
when(mockedServer.getVersion()).thenReturn(CraftServer.class.getPackage().getImplementationVersion());
|
||||
when(mockedServer.getVersion()).thenReturn(serverVersion + " (MC: " + releaseTarget + ")");
|
||||
when(mockedServer.getBukkitVersion()).thenReturn(Versioning.getBukkitVersion());
|
||||
|
||||
when(mockedServer.getItemFactory()).thenReturn(CraftItemFactory.instance());
|
||||
|
@ -76,7 +76,7 @@ import static org.junit.Assert.*;
|
||||
|
||||
// Ensure that the CraftItemFactory is mockable
|
||||
@RunWith(org.powermock.modules.junit4.PowerMockRunner.class)
|
||||
@PowerMockIgnore({ "org.apache.log4j.*", "org.apache.logging.*", "org.bukkit.craftbukkit.libs.jline.*", "javax.management.*", "javax.xml.parsers.*", "com.sun.org.apache.xerces.internal.jaxp.*" })
|
||||
@PowerMockIgnore({ "org.apache.logging.log4j.core.config.xml.*", "javax.management.*" })
|
||||
//@PrepareForTest(CraftItemFactory.class)
|
||||
public class PacketContainerTest {
|
||||
// Helper converters
|
||||
@ -191,7 +191,7 @@ public class PacketContainerTest {
|
||||
@Test
|
||||
public void testGetIntegerArrays() {
|
||||
// Contains a byte array we will test
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.MAP_CHUNK);
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.MOUNT);
|
||||
StructureModifier<int[]> integers = packet.getIntegerArrays();
|
||||
int[] testArray = new int[] { 1, 2, 3 };
|
||||
|
||||
@ -411,7 +411,7 @@ public class PacketContainerTest {
|
||||
// are inner classes (which is ultimately pointless because AttributeSnapshots don't access any
|
||||
// members of the packet itself)
|
||||
PacketPlayOutUpdateAttributes packet = (PacketPlayOutUpdateAttributes) attribute.getHandle();
|
||||
AttributeBase base = IRegistry.al.get(MinecraftKey.a("generic.max_health"));
|
||||
AttributeBase base = IRegistry.am.a(MinecraftKey.a("generic.max_health"));
|
||||
AttributeSnapshot snapshot = new AttributeSnapshot(base, 20.0D, modifiers);
|
||||
attribute.getSpecificModifier(List.class).write(0, Lists.newArrayList(snapshot));
|
||||
|
||||
@ -461,7 +461,7 @@ public class PacketContainerTest {
|
||||
@SuppressWarnings("deprecation")
|
||||
public void testPotionEffect() {
|
||||
PotionEffect effect = new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 20 * 60, 1);
|
||||
MobEffect mobEffect = new MobEffect(MobEffectList.fromId(effect.getType().getId()), effect.getDuration(), effect.getAmplifier(), effect.isAmbient(),
|
||||
MobEffect mobEffect = new MobEffect(MobEffectList.a(effect.getType().getId()), effect.getDuration(), effect.getAmplifier(), effect.isAmbient(),
|
||||
effect.hasParticles());
|
||||
int entityId = 42;
|
||||
|
||||
@ -663,12 +663,20 @@ public class PacketContainerTest {
|
||||
assertEquals(position, clone.getPosition());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetSimulationDistance() {
|
||||
// first packet which is a record - set will fail if we missed something during patching
|
||||
PacketContainer container = new PacketContainer(PacketType.Play.Server.UPDATE_SIMULATION_DISTANCE);
|
||||
container.getIntegers().write(0, 1234);
|
||||
assertEquals(1234, (int) container.getIntegers().read(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapChunk() {
|
||||
// this is a special case as we are generating a data serializer class (we only need to construct the packet)
|
||||
PacketContainer container = new PacketContainer(PacketType.Play.Server.MAP_CHUNK);
|
||||
// check if we can read an nbt compound from the class
|
||||
assertTrue(container.getNbtModifier().optionRead(0).isPresent());
|
||||
assertTrue(container.getStructures().read(0).getNbtModifier().optionRead(0).isPresent());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -9,6 +9,8 @@ import com.comphenix.protocol.reflect.accessors.Accessors;
|
||||
|
||||
import com.comphenix.protocol.reflect.accessors.FieldAccessor;
|
||||
import com.comphenix.protocol.reflect.fuzzy.FuzzyFieldContract;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import net.minecraft.server.level.ChunkProviderServer;
|
||||
import net.minecraft.server.level.EntityTrackerEntry;
|
||||
import net.minecraft.server.level.PlayerChunkMap;
|
||||
@ -16,10 +18,8 @@ import net.minecraft.server.level.PlayerChunkMap.EntityTracker;
|
||||
import net.minecraft.server.level.WorldServer;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
|
||||
import org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.entity.CraftEntity;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -45,7 +45,7 @@ public class EntityUtilitiesTest {
|
||||
when(bukkit.getHandle()).thenReturn(world);
|
||||
|
||||
ChunkProviderServer provider = mock(ChunkProviderServer.class);
|
||||
when(world.getChunkProvider()).thenReturn(provider);
|
||||
when(world.k()).thenReturn(provider);
|
||||
|
||||
PlayerChunkMap chunkMap = mock(PlayerChunkMap.class);
|
||||
Field chunkMapField = FuzzyReflection.fromClass(ChunkProviderServer.class, true)
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.comphenix.protocol.injector;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ -26,7 +26,7 @@ import com.google.common.collect.Lists;
|
||||
|
||||
// Damn final classes
|
||||
@RunWith(org.powermock.modules.junit4.PowerMockRunner.class)
|
||||
@PowerMockIgnore({ "org.apache.log4j.*", "org.apache.logging.*", "org.bukkit.craftbukkit.libs.jline.*" })
|
||||
@PowerMockIgnore({ "org.apache.logging.log4j.core.config.xml.*", "javax.management.*" })
|
||||
@PrepareForTest(PluginDescriptionFile.class)
|
||||
public class PluginVerifierTest {
|
||||
@Test
|
||||
|
@ -8,7 +8,7 @@ import static org.mockito.Mockito.verify;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.junit.AfterClass;
|
||||
@ -31,7 +31,7 @@ import net.minecraft.world.level.ChunkCoordIntPair;
|
||||
import net.minecraft.world.level.block.state.IBlockData;
|
||||
|
||||
@RunWith(org.powermock.modules.junit4.PowerMockRunner.class)
|
||||
@PowerMockIgnore({ "org.apache.log4j.*", "org.apache.logging.*", "org.bukkit.craftbukkit.libs.jline.*" })
|
||||
@PowerMockIgnore({ "org.apache.logging.log4j.core.config.xml.*", "javax.management.*" })
|
||||
public class MinecraftReflectionTest {
|
||||
|
||||
@BeforeClass
|
||||
|
@ -19,7 +19,7 @@ import static com.comphenix.protocol.utility.TestUtils.assertItemsEqual;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@RunWith(org.powermock.modules.junit4.PowerMockRunner.class)
|
||||
@PowerMockIgnore({ "org.apache.log4j.*", "org.apache.logging.*", "org.bukkit.craftbukkit.libs.jline.*" })
|
||||
@PowerMockIgnore({ "org.apache.logging.log4j.core.config.xml.*", "org.bukkit.craftbukkit.libs.jline.*" })
|
||||
//@PrepareForTest(CraftItemFactory.class)
|
||||
public class StreamSerializerTest {
|
||||
|
||||
|
@ -26,7 +26,7 @@ public class ChunkCoordIntPairTest {
|
||||
(net.minecraft.world.level.ChunkCoordIntPair) ChunkCoordIntPair.getConverter().
|
||||
getGeneric(specific);
|
||||
|
||||
assertEquals(1, roundtrip.b);
|
||||
assertEquals(2, roundtrip.c);
|
||||
assertEquals(1, roundtrip.c);
|
||||
assertEquals(2, roundtrip.d);
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
* @author dmulloy2
|
||||
*/
|
||||
@RunWith(org.powermock.modules.junit4.PowerMockRunner.class)
|
||||
@PowerMockIgnore({ "org.apache.log4j.*", "org.apache.logging.*", "org.bukkit.craftbukkit.libs.jline.*" })
|
||||
@PowerMockIgnore({ "org.apache.logging.log4j.core.config.xml.*", "javax.management.*" })
|
||||
public class MultiBlockChangeTest {
|
||||
|
||||
// @BeforeClass
|
||||
|
@ -92,7 +92,7 @@ public class WrappedAttributeTest {
|
||||
modifiers.add((AttributeModifier) wrapper.getHandle());
|
||||
}
|
||||
|
||||
AttributeBase base = IRegistry.al.get(MinecraftKey.a(attribute.getAttributeKey()));
|
||||
AttributeBase base = IRegistry.am.a(MinecraftKey.a(attribute.getAttributeKey()));
|
||||
return new AttributeSnapshot(base, attribute.getBaseValue(), modifiers);
|
||||
}
|
||||
|
||||
|
@ -23,9 +23,9 @@ import net.minecraft.world.level.block.state.IBlockData;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.data.type.GlassPane;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.block.data.CraftBlockData;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.block.impl.CraftStainedGlassPane;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.util.CraftMagicNumbers;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.block.data.CraftBlockData;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.block.impl.CraftStainedGlassPane;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.util.CraftMagicNumbers;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -60,7 +60,7 @@ public class WrappedBlockDataTest {
|
||||
|
||||
@Test
|
||||
public void testDataCreation() {
|
||||
IBlockData nmsData = CraftMagicNumbers.getBlock(Material.CYAN_STAINED_GLASS_PANE).getBlockData();
|
||||
IBlockData nmsData = CraftMagicNumbers.getBlock(Material.CYAN_STAINED_GLASS_PANE).n();
|
||||
GlassPane data = (GlassPane) CraftBlockData.fromData(nmsData);
|
||||
data.setFace(BlockFace.EAST, true);
|
||||
|
||||
|
@ -25,8 +25,8 @@ import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObje
|
||||
|
||||
import net.minecraft.world.entity.projectile.EntityEgg;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftEgg;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.entity.CraftEgg;
|
||||
import org.bukkit.craftbukkit.v1_18_R1.entity.CraftEntity;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -48,7 +48,7 @@ import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
|
||||
@RunWith(org.powermock.modules.junit4.PowerMockRunner.class)
|
||||
@PowerMockIgnore({ "org.apache.log4j.*", "org.apache.logging.*", "org.bukkit.craftbukkit.libs.jline.*" })
|
||||
@PowerMockIgnore({ "org.apache.logging.log4j.core.config.xml.*", "javax.management.*" })
|
||||
//@PrepareForTest(CraftItemFactory.class)
|
||||
public class NbtFactoryTest {
|
||||
@BeforeClass
|
||||
|
Loading…
Reference in New Issue
Block a user