Skip to content

Commit 4bc9e8b

Browse files
committed
Fix a class cast exception with array wrappers
(Kinda surprised there isn't an issue to link here)
1 parent f381f0a commit 4bc9e8b

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -485,31 +485,31 @@ public Class<Iterable<? extends T>> getSpecificType() {
485485
* @return Wrapped game profile converter.
486486
*/
487487
public static EquivalentConverter<WrappedGameProfile> getWrappedGameProfileConverter() {
488-
return ignoreNull(handle(WrappedGameProfile::getHandle, WrappedGameProfile::fromHandle));
488+
return ignoreNull(handle(WrappedGameProfile::getHandle, WrappedGameProfile::fromHandle, WrappedGameProfile.class));
489489
}
490490

491491
/**
492492
* Retrieve a converter for wrapped chat components.
493493
* @return Wrapped chat component.
494494
*/
495495
public static EquivalentConverter<WrappedChatComponent> getWrappedChatComponentConverter() {
496-
return ignoreNull(handle(WrappedChatComponent::getHandle, WrappedChatComponent::fromHandle));
496+
return ignoreNull(handle(WrappedChatComponent::getHandle, WrappedChatComponent::fromHandle, WrappedChatComponent.class));
497497
}
498498

499499
/**
500500
* Retrieve a converter for wrapped block data.
501501
* @return Wrapped block data.
502502
*/
503503
public static EquivalentConverter<WrappedBlockData> getWrappedBlockDataConverter() {
504-
return ignoreNull(handle(WrappedBlockData::getHandle, WrappedBlockData::fromHandle));
504+
return ignoreNull(handle(WrappedBlockData::getHandle, WrappedBlockData::fromHandle, WrappedBlockData.class));
505505
}
506506

507507
/**
508508
* Retrieve a converter for wrapped attribute snapshots.
509509
* @return Wrapped attribute snapshot converter.
510510
*/
511511
public static EquivalentConverter<WrappedAttribute> getWrappedAttributeConverter() {
512-
return ignoreNull(handle(WrappedAttribute::getHandle, WrappedAttribute::fromHandle));
512+
return ignoreNull(handle(WrappedAttribute::getHandle, WrappedAttribute::fromHandle, WrappedAttribute.class));
513513
}
514514

515515
/**
@@ -768,15 +768,15 @@ public Class<ItemStack> getSpecificType() {
768768
* @return Server ping converter.
769769
*/
770770
public static EquivalentConverter<WrappedServerPing> getWrappedServerPingConverter() {
771-
return ignoreNull(handle(WrappedServerPing::getHandle, WrappedServerPing::fromHandle));
771+
return ignoreNull(handle(WrappedServerPing::getHandle, WrappedServerPing::fromHandle, WrappedServerPing.class));
772772
}
773773

774774
/**
775775
* Retrieve the converter for a statistic.
776776
* @return Statistic converter.
777777
*/
778778
public static EquivalentConverter<WrappedStatistic> getWrappedStatisticConverter() {
779-
return ignoreNull(handle(WrappedStatistic::getHandle, WrappedStatistic::fromHandle));
779+
return ignoreNull(handle(WrappedStatistic::getHandle, WrappedStatistic::fromHandle, WrappedStatistic.class));
780780
}
781781

782782
private static MethodAccessor BLOCK_FROM_MATERIAL;
@@ -1016,7 +1016,7 @@ public Sound getSpecific(Object generic) {
10161016
}
10171017

10181018
public static EquivalentConverter<WrappedParticle> getParticleConverter() {
1019-
return ignoreNull(handle(WrappedParticle::getHandle, WrappedParticle::fromHandle));
1019+
return ignoreNull(handle(WrappedParticle::getHandle, WrappedParticle::fromHandle, WrappedParticle.class));
10201020
}
10211021

10221022
public static EquivalentConverter<Advancement> getAdvancementConverter() {

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public Class<T> getSpecificType() {
8888
* @return A handle converter
8989
*/
9090
public static <T> EquivalentConverter<T> handle(final Function<T, Object> toHandle,
91-
final Function<Object, T> fromHandle) {
91+
final Function<Object, T> fromHandle, final Class<T> specificType) {
9292
return new EquivalentConverter<T>() {
9393
@Override
9494
public T getSpecific(Object generic) {
@@ -102,7 +102,7 @@ public Object getGeneric(T specific) {
102102

103103
@Override
104104
public Class<T> getSpecificType() {
105-
return null;
105+
return specificType;
106106
}
107107
};
108108
}
@@ -121,7 +121,8 @@ public static <T> EquivalentConverter<T[]> array(final Class<?> nmsClass, final
121121
@Override
122122
public T[] getSpecific(Object generic) {
123123
Object[] array = (Object[]) generic;
124-
T[] result = (T[]) new Object[array.length];
124+
Class<T[]> clazz = getSpecificType();
125+
T[] result = clazz.cast(Array.newInstance(clazz.getComponentType(), array.length));
125126

126127
// Unwrap every item
127128
for (int i = 0; i < result.length; i++) {

0 commit comments

Comments
 (0)