Skip to content

Commit 153dd61

Browse files
committed
Update to 1.17.1
Fixes #1315
1 parent 263ec8a commit 153dd61

File tree

9 files changed

+129
-68
lines changed

9 files changed

+129
-68
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<project.fullVersion>${project.version}</project.fullVersion>
1818

1919
<powermock.version>2.0.7</powermock.version>
20-
<spigot.version>1.17-R0.1-SNAPSHOT</spigot.version>
20+
<spigot.version>1.17.1-R0.1-SNAPSHOT</spigot.version>
2121
</properties>
2222

2323
<build>

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.comphenix.protocol.PacketTypeLookup.ClassLookup;
1212
import com.comphenix.protocol.events.ConnectionSide;
1313
import com.comphenix.protocol.injector.packet.PacketRegistry;
14+
import com.comphenix.protocol.utility.Constants;
1415
import com.comphenix.protocol.utility.MinecraftReflection;
1516
import com.comphenix.protocol.utility.MinecraftVersion;
1617
import com.google.common.base.Preconditions;
@@ -653,7 +654,7 @@ public String getMojangName() {
653654
/**
654655
* Protocol version of all the current IDs.
655656
*/
656-
private static final MinecraftVersion PROTOCOL_VERSION = MinecraftVersion.CAVES_CLIFFS_1;
657+
private static final MinecraftVersion PROTOCOL_VERSION = Constants.CURRENT_VERSION;
657658

658659
private final Protocol protocol;
659660
private final Sender sender;

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";
41+
public static final String MAXIMUM_MINECRAFT_VERSION = "1.17.1";
4242

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

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

src/main/java/com/comphenix/protocol/events/AbstractStructure.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,16 @@ public StructureModifier<Integer> getGameStateIDs() {
914914
);
915915
}
916916

917+
public StructureModifier<List<Integer>> getIntLists() {
918+
return structureModifier.withType(
919+
List.class,
920+
BukkitConverters.getListConverter(
921+
MinecraftReflection.getIntArrayListClass(),
922+
Converters.passthrough(int.class)
923+
)
924+
);
925+
}
926+
917927
/**
918928
* Retrieve a read/write structure for the Map class.
919929
* @param keyConverter Converter for map keys

src/main/java/com/comphenix/protocol/utility/MinecraftProtocolVersion.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ private static NavigableMap<MinecraftVersion, Integer> createLookup() {
7575
map.put(new MinecraftVersion(1, 16, 5), 754);
7676

7777
map.put(new MinecraftVersion(1, 17, 0), 755);
78+
map.put(new MinecraftVersion(1, 17, 1), 756);
7879
return map;
7980
}
8081

src/main/java/com/comphenix/protocol/utility/MinecraftReflection.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2250,17 +2250,21 @@ public static Class<?> getAttributeBase() {
22502250
return getMinecraftClass("world.entity.ai.attributes.AttributeBase", "AttributeBase");
22512251
}
22522252

2253-
public static Class<?> getInt2ObjectMapClass() {
2253+
public static Class<?> getFastUtilClass(String className) {
22542254
try {
2255-
return getMinecraftLibraryClass("it.unimi.dsi.fastutil.ints.Int2ObjectMap");
2255+
return getMinecraftLibraryClass("it.unimi.dsi.fastutil." + className);
22562256
} catch (RuntimeException ex) {
2257-
try {
2258-
Class<?> clazz = getMinecraftLibraryClass("org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil.ints.Int2ObjectMap");
2259-
setMinecraftLibraryClass("it.unimi.dsi.fastutil.ints.Int2ObjectMap", clazz);
2260-
return clazz;
2261-
} catch (RuntimeException ignored) {
2262-
throw ex;
2263-
}
2257+
Class<?> clazz = getMinecraftLibraryClass("org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil." + className);
2258+
setMinecraftLibraryClass("it.unimi.dsi.fastutil." + className, clazz);
2259+
return clazz;
22642260
}
22652261
}
2262+
2263+
public static Class<?> getInt2ObjectMapClass() {
2264+
return getFastUtilClass("ints.Int2ObjectMap");
2265+
}
2266+
2267+
public static Class<?> getIntArrayListClass() {
2268+
return getFastUtilClass("ints.IntArrayList");
2269+
}
22662270
}

src/main/java/com/comphenix/protocol/wrappers/BukkitConverters.java

Lines changed: 82 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,86 @@ public Class<Map<K, V>> getSpecificType() {
267267
};
268268
}
269269

270-
private static Map<Class<?>, Supplier<List<Object>>> LIST_SUPPLIERS = new ConcurrentHashMap<>();
270+
private static final Map<Class<?>, Supplier<List<Object>>> LIST_SUPPLIERS = new ConcurrentHashMap<>();
271+
272+
private static <T> Object getGenericList(Class<?> listClass, List<T> specific, EquivalentConverter<T> itemConverter) {
273+
List<Object> newList;
274+
Supplier<List<Object>> supplier = LIST_SUPPLIERS.get(listClass);
275+
if (supplier == null) {
276+
try {
277+
Constructor<?> ctor = listClass.getConstructor();
278+
newList = (List<Object>) ctor.newInstance();
279+
supplier = () -> {
280+
try {
281+
return (List<Object>) ctor.newInstance();
282+
} catch (ReflectiveOperationException ex) {
283+
throw new RuntimeException(ex);
284+
}
285+
};
286+
} catch (ReflectiveOperationException ex) {
287+
ex.printStackTrace();
288+
supplier = ArrayList::new;
289+
newList = new ArrayList<>();
290+
}
291+
292+
LIST_SUPPLIERS.put(listClass, supplier);
293+
} else {
294+
newList = supplier.get();
295+
}
296+
297+
// Convert each object
298+
for (T position : specific) {
299+
if (position != null) {
300+
Object converted = itemConverter.getGeneric(position);
301+
if (converted != null) {
302+
newList.add(converted);
303+
}
304+
} else {
305+
newList.add(null);
306+
}
307+
}
308+
309+
return newList;
310+
}
311+
312+
private static <T> List<T> getSpecificList(Object generic, EquivalentConverter<T> itemConverter) {
313+
if (generic instanceof Collection) {
314+
List<T> items = new ArrayList<>();
315+
316+
// Copy everything to a new list
317+
for (Object item : (Collection<Object>) generic) {
318+
T result = itemConverter.getSpecific(item);
319+
320+
if (item != null)
321+
items.add(result);
322+
}
323+
return items;
324+
}
325+
326+
// Not valid
327+
return null;
328+
}
329+
330+
public static <T> EquivalentConverter<List<T>> getListConverter(final Class<?> listClass, final EquivalentConverter<T> itemConverter) {
331+
return ignoreNull(new EquivalentConverter<List<T>>() {
332+
@Override
333+
public List<T> getSpecific(Object generic) {
334+
return getSpecificList(generic, itemConverter);
335+
}
336+
337+
@Override
338+
public Object getGeneric(List<T> specific) {
339+
return getGenericList(listClass, specific, itemConverter);
340+
}
341+
342+
@Override
343+
public Class<List<T>> getSpecificType() {
344+
// Damn you Java
345+
Class<?> dummy = List.class;
346+
return (Class<List<T>>) dummy;
347+
}
348+
});
349+
}
271350

272351
/**
273352
* Retrieve an equivalent converter for a list of generic items.
@@ -280,61 +359,12 @@ public static <T> EquivalentConverter<List<T>> getListConverter(final Equivalent
280359
return ignoreNull(new EquivalentConverter<List<T>>() {
281360
@Override
282361
public List<T> getSpecific(Object generic) {
283-
if (generic instanceof Collection) {
284-
List<T> items = new ArrayList<>();
285-
286-
// Copy everything to a new list
287-
for (Object item : (Collection<Object>) generic) {
288-
T result = itemConverter.getSpecific(item);
289-
290-
if (item != null)
291-
items.add(result);
292-
}
293-
return items;
294-
}
295-
296-
// Not valid
297-
return null;
362+
return getSpecificList(generic, itemConverter);
298363
}
299364

300365
@Override
301366
public Object getGeneric(List<T> specific) {
302-
List<Object> newList;
303-
Supplier<List<Object>> supplier = LIST_SUPPLIERS.get(specific.getClass());
304-
if (supplier == null) {
305-
try {
306-
Constructor<?> ctor = specific.getClass().getConstructor();
307-
newList = (List<Object>) ctor.newInstance();
308-
supplier = () -> {
309-
try {
310-
return (List<Object>) ctor.newInstance();
311-
} catch (ReflectiveOperationException ex) {
312-
throw new RuntimeException(ex);
313-
}
314-
};
315-
} catch (ReflectiveOperationException ex) {
316-
supplier = ArrayList::new;
317-
newList = new ArrayList<>();
318-
}
319-
320-
LIST_SUPPLIERS.put(specific.getClass(), supplier);
321-
} else {
322-
newList = supplier.get();
323-
}
324-
325-
// Convert each object
326-
for (T position : specific) {
327-
if (position != null) {
328-
Object converted = itemConverter.getGeneric(position);
329-
if (converted != null) {
330-
newList.add(converted);
331-
}
332-
} else {
333-
newList.add(null);
334-
}
335-
}
336-
337-
return newList;
367+
return getGenericList(specific.getClass(), specific, itemConverter);
338368
}
339369

340370
@Override

src/test/java/com/comphenix/protocol/events/PacketContainerTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,19 @@ public void testSerialization() {
385385
assertEquals("Test", copy.getStrings().read(0));
386386
}
387387

388+
@Test
389+
public void testIntList() {
390+
PacketContainer destroy = new PacketContainer(PacketType.Play.Server.ENTITY_DESTROY);
391+
destroy.getIntLists().write(0, new ArrayList<Integer>() {{
392+
add(420);
393+
add(69);
394+
}});
395+
List<Integer> back = destroy.getIntLists().read(0);
396+
assertEquals(back.size(), 2);
397+
assertEquals((int) back.get(0), 420);
398+
assertEquals((int) back.get(1), 69);
399+
}
400+
388401
@Test
389402
public void testAttributeList() {
390403
PacketContainer attribute = new PacketContainer(PacketType.Play.Server.UPDATE_ATTRIBUTES);

src/test/java/com/comphenix/protocol/reflect/cloning/AggregateClonerTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static org.junit.Assert.assertArrayEquals;
44
import static org.junit.Assert.assertEquals;
55

6+
import java.lang.reflect.Field;
67
import java.util.Arrays;
78
import java.util.List;
89

@@ -20,7 +21,7 @@ public class AggregateClonerTest {
2021

2122
@BeforeClass
2223
public static void initializeBukkit() {
23-
BukkitInitialization.initializePackage();
24+
BukkitInitialization.initializeItemMeta();
2425
}
2526

2627
@Test
@@ -29,7 +30,8 @@ public void testArrays() {
2930
assertEquals(input, AggregateCloner.DEFAULT.clone(input));
3031
}
3132

32-
@Test
33+
// @Test
34+
// Usages of NonNullList were removed in 1.17.1
3335
public void testNonNullList() {
3436
PacketContainer packet = new PacketContainer(PacketType.Play.Server.WINDOW_ITEMS);
3537

0 commit comments

Comments
 (0)