mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-11-30 14:43:27 +01:00
parent
263ec8a36e
commit
153dd61994
2
pom.xml
2
pom.xml
@ -17,7 +17,7 @@
|
|||||||
<project.fullVersion>${project.version}</project.fullVersion>
|
<project.fullVersion>${project.version}</project.fullVersion>
|
||||||
|
|
||||||
<powermock.version>2.0.7</powermock.version>
|
<powermock.version>2.0.7</powermock.version>
|
||||||
<spigot.version>1.17-R0.1-SNAPSHOT</spigot.version>
|
<spigot.version>1.17.1-R0.1-SNAPSHOT</spigot.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
@ -11,6 +11,7 @@ import java.util.function.Consumer;
|
|||||||
import com.comphenix.protocol.PacketTypeLookup.ClassLookup;
|
import com.comphenix.protocol.PacketTypeLookup.ClassLookup;
|
||||||
import com.comphenix.protocol.events.ConnectionSide;
|
import com.comphenix.protocol.events.ConnectionSide;
|
||||||
import com.comphenix.protocol.injector.packet.PacketRegistry;
|
import com.comphenix.protocol.injector.packet.PacketRegistry;
|
||||||
|
import com.comphenix.protocol.utility.Constants;
|
||||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||||
import com.comphenix.protocol.utility.MinecraftVersion;
|
import com.comphenix.protocol.utility.MinecraftVersion;
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
@ -653,7 +654,7 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
|||||||
/**
|
/**
|
||||||
* Protocol version of all the current IDs.
|
* Protocol version of all the current IDs.
|
||||||
*/
|
*/
|
||||||
private static final MinecraftVersion PROTOCOL_VERSION = MinecraftVersion.CAVES_CLIFFS_1;
|
private static final MinecraftVersion PROTOCOL_VERSION = Constants.CURRENT_VERSION;
|
||||||
|
|
||||||
private final Protocol protocol;
|
private final Protocol protocol;
|
||||||
private final Sender sender;
|
private final Sender sender;
|
||||||
|
@ -38,12 +38,12 @@ public class ProtocolLibrary {
|
|||||||
/**
|
/**
|
||||||
* The maximum version ProtocolLib has been tested with.
|
* The maximum version ProtocolLib has been tested with.
|
||||||
*/
|
*/
|
||||||
public static final String MAXIMUM_MINECRAFT_VERSION = "1.17";
|
public static final String MAXIMUM_MINECRAFT_VERSION = "1.17.1";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The date (with ISO 8601 or YYYY-MM-DD) when the most recent version (1.17) was released.
|
* The date (with ISO 8601 or YYYY-MM-DD) when the most recent version (1.17.1) was released.
|
||||||
*/
|
*/
|
||||||
public static final String MINECRAFT_LAST_RELEASE_DATE = "2021-06-08";
|
public static final String MINECRAFT_LAST_RELEASE_DATE = "2021-07-06";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Plugins that are currently incompatible with ProtocolLib.
|
* Plugins that are currently incompatible with ProtocolLib.
|
||||||
|
@ -914,6 +914,16 @@ public abstract class AbstractStructure {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public StructureModifier<List<Integer>> getIntLists() {
|
||||||
|
return structureModifier.withType(
|
||||||
|
List.class,
|
||||||
|
BukkitConverters.getListConverter(
|
||||||
|
MinecraftReflection.getIntArrayListClass(),
|
||||||
|
Converters.passthrough(int.class)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve a read/write structure for the Map class.
|
* Retrieve a read/write structure for the Map class.
|
||||||
* @param keyConverter Converter for map keys
|
* @param keyConverter Converter for map keys
|
||||||
|
@ -75,6 +75,7 @@ public class MinecraftProtocolVersion {
|
|||||||
map.put(new MinecraftVersion(1, 16, 5), 754);
|
map.put(new MinecraftVersion(1, 16, 5), 754);
|
||||||
|
|
||||||
map.put(new MinecraftVersion(1, 17, 0), 755);
|
map.put(new MinecraftVersion(1, 17, 0), 755);
|
||||||
|
map.put(new MinecraftVersion(1, 17, 1), 756);
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2250,17 +2250,21 @@ public class MinecraftReflection {
|
|||||||
return getMinecraftClass("world.entity.ai.attributes.AttributeBase", "AttributeBase");
|
return getMinecraftClass("world.entity.ai.attributes.AttributeBase", "AttributeBase");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Class<?> getInt2ObjectMapClass() {
|
public static Class<?> getFastUtilClass(String className) {
|
||||||
try {
|
try {
|
||||||
return getMinecraftLibraryClass("it.unimi.dsi.fastutil.ints.Int2ObjectMap");
|
return getMinecraftLibraryClass("it.unimi.dsi.fastutil." + className);
|
||||||
} catch (RuntimeException ex) {
|
} catch (RuntimeException ex) {
|
||||||
try {
|
Class<?> clazz = getMinecraftLibraryClass("org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil." + className);
|
||||||
Class<?> clazz = getMinecraftLibraryClass("org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil.ints.Int2ObjectMap");
|
setMinecraftLibraryClass("it.unimi.dsi.fastutil." + className, clazz);
|
||||||
setMinecraftLibraryClass("it.unimi.dsi.fastutil.ints.Int2ObjectMap", clazz);
|
|
||||||
return clazz;
|
return clazz;
|
||||||
} catch (RuntimeException ignored) {
|
|
||||||
throw ex;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Class<?> getInt2ObjectMapClass() {
|
||||||
|
return getFastUtilClass("ints.Int2ObjectMap");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Class<?> getIntArrayListClass() {
|
||||||
|
return getFastUtilClass("ints.IntArrayList");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -267,43 +267,14 @@ public class BukkitConverters {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Map<Class<?>, Supplier<List<Object>>> LIST_SUPPLIERS = new ConcurrentHashMap<>();
|
private static final Map<Class<?>, Supplier<List<Object>>> LIST_SUPPLIERS = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
/**
|
private static <T> Object getGenericList(Class<?> listClass, List<T> specific, EquivalentConverter<T> itemConverter) {
|
||||||
* Retrieve an equivalent converter for a list of generic items.
|
|
||||||
* @param <T> Type
|
|
||||||
* @param itemConverter - an equivalent converter for the generic type.
|
|
||||||
* @return An equivalent converter.
|
|
||||||
*/
|
|
||||||
public static <T> EquivalentConverter<List<T>> getListConverter(final EquivalentConverter<T> itemConverter) {
|
|
||||||
// Convert to and from the wrapper
|
|
||||||
return ignoreNull(new EquivalentConverter<List<T>>() {
|
|
||||||
@Override
|
|
||||||
public List<T> getSpecific(Object generic) {
|
|
||||||
if (generic instanceof Collection) {
|
|
||||||
List<T> items = new ArrayList<>();
|
|
||||||
|
|
||||||
// Copy everything to a new list
|
|
||||||
for (Object item : (Collection<Object>) generic) {
|
|
||||||
T result = itemConverter.getSpecific(item);
|
|
||||||
|
|
||||||
if (item != null)
|
|
||||||
items.add(result);
|
|
||||||
}
|
|
||||||
return items;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Not valid
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getGeneric(List<T> specific) {
|
|
||||||
List<Object> newList;
|
List<Object> newList;
|
||||||
Supplier<List<Object>> supplier = LIST_SUPPLIERS.get(specific.getClass());
|
Supplier<List<Object>> supplier = LIST_SUPPLIERS.get(listClass);
|
||||||
if (supplier == null) {
|
if (supplier == null) {
|
||||||
try {
|
try {
|
||||||
Constructor<?> ctor = specific.getClass().getConstructor();
|
Constructor<?> ctor = listClass.getConstructor();
|
||||||
newList = (List<Object>) ctor.newInstance();
|
newList = (List<Object>) ctor.newInstance();
|
||||||
supplier = () -> {
|
supplier = () -> {
|
||||||
try {
|
try {
|
||||||
@ -313,11 +284,12 @@ public class BukkitConverters {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
} catch (ReflectiveOperationException ex) {
|
} catch (ReflectiveOperationException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
supplier = ArrayList::new;
|
supplier = ArrayList::new;
|
||||||
newList = new ArrayList<>();
|
newList = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
LIST_SUPPLIERS.put(specific.getClass(), supplier);
|
LIST_SUPPLIERS.put(listClass, supplier);
|
||||||
} else {
|
} else {
|
||||||
newList = supplier.get();
|
newList = supplier.get();
|
||||||
}
|
}
|
||||||
@ -337,6 +309,64 @@ public class BukkitConverters {
|
|||||||
return newList;
|
return newList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static <T> List<T> getSpecificList(Object generic, EquivalentConverter<T> itemConverter) {
|
||||||
|
if (generic instanceof Collection) {
|
||||||
|
List<T> items = new ArrayList<>();
|
||||||
|
|
||||||
|
// Copy everything to a new list
|
||||||
|
for (Object item : (Collection<Object>) generic) {
|
||||||
|
T result = itemConverter.getSpecific(item);
|
||||||
|
|
||||||
|
if (item != null)
|
||||||
|
items.add(result);
|
||||||
|
}
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not valid
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> EquivalentConverter<List<T>> getListConverter(final Class<?> listClass, final EquivalentConverter<T> itemConverter) {
|
||||||
|
return ignoreNull(new EquivalentConverter<List<T>>() {
|
||||||
|
@Override
|
||||||
|
public List<T> getSpecific(Object generic) {
|
||||||
|
return getSpecificList(generic, itemConverter);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getGeneric(List<T> specific) {
|
||||||
|
return getGenericList(listClass, specific, itemConverter);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<List<T>> getSpecificType() {
|
||||||
|
// Damn you Java
|
||||||
|
Class<?> dummy = List.class;
|
||||||
|
return (Class<List<T>>) dummy;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve an equivalent converter for a list of generic items.
|
||||||
|
* @param <T> Type
|
||||||
|
* @param itemConverter - an equivalent converter for the generic type.
|
||||||
|
* @return An equivalent converter.
|
||||||
|
*/
|
||||||
|
public static <T> EquivalentConverter<List<T>> getListConverter(final EquivalentConverter<T> itemConverter) {
|
||||||
|
// Convert to and from the wrapper
|
||||||
|
return ignoreNull(new EquivalentConverter<List<T>>() {
|
||||||
|
@Override
|
||||||
|
public List<T> getSpecific(Object generic) {
|
||||||
|
return getSpecificList(generic, itemConverter);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getGeneric(List<T> specific) {
|
||||||
|
return getGenericList(specific.getClass(), specific, itemConverter);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<List<T>> getSpecificType() {
|
public Class<List<T>> getSpecificType() {
|
||||||
// Damn you Java
|
// Damn you Java
|
||||||
|
@ -385,6 +385,19 @@ public class PacketContainerTest {
|
|||||||
assertEquals("Test", copy.getStrings().read(0));
|
assertEquals("Test", copy.getStrings().read(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIntList() {
|
||||||
|
PacketContainer destroy = new PacketContainer(PacketType.Play.Server.ENTITY_DESTROY);
|
||||||
|
destroy.getIntLists().write(0, new ArrayList<Integer>() {{
|
||||||
|
add(420);
|
||||||
|
add(69);
|
||||||
|
}});
|
||||||
|
List<Integer> back = destroy.getIntLists().read(0);
|
||||||
|
assertEquals(back.size(), 2);
|
||||||
|
assertEquals((int) back.get(0), 420);
|
||||||
|
assertEquals((int) back.get(1), 69);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAttributeList() {
|
public void testAttributeList() {
|
||||||
PacketContainer attribute = new PacketContainer(PacketType.Play.Server.UPDATE_ATTRIBUTES);
|
PacketContainer attribute = new PacketContainer(PacketType.Play.Server.UPDATE_ATTRIBUTES);
|
||||||
|
@ -3,6 +3,7 @@ package com.comphenix.protocol.reflect.cloning;
|
|||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -20,7 +21,7 @@ public class AggregateClonerTest {
|
|||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void initializeBukkit() {
|
public static void initializeBukkit() {
|
||||||
BukkitInitialization.initializePackage();
|
BukkitInitialization.initializeItemMeta();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -29,7 +30,8 @@ public class AggregateClonerTest {
|
|||||||
assertEquals(input, AggregateCloner.DEFAULT.clone(input));
|
assertEquals(input, AggregateCloner.DEFAULT.clone(input));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
// @Test
|
||||||
|
// Usages of NonNullList were removed in 1.17.1
|
||||||
public void testNonNullList() {
|
public void testNonNullList() {
|
||||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.WINDOW_ITEMS);
|
PacketContainer packet = new PacketContainer(PacketType.Play.Server.WINDOW_ITEMS);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user