mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-11-24 03:25:29 +01:00
Fix odd ArrayStoreException with MultiBlockChangeInfo
Also adapt test to test with arrays
This commit is contained in:
parent
24d5b1739a
commit
2c5b3a2a5b
@ -35,6 +35,7 @@ import com.comphenix.protocol.utility.MinecraftReflection;
|
|||||||
|
|
||||||
public class MultiBlockChangeInfo {
|
public class MultiBlockChangeInfo {
|
||||||
private static Constructor<?> constructor;
|
private static Constructor<?> constructor;
|
||||||
|
private static Class<?> nmsClass = MinecraftReflection.getMultiBlockChangeInfoClass();
|
||||||
|
|
||||||
private short location;
|
private short location;
|
||||||
private WrappedBlockData data;
|
private WrappedBlockData data;
|
||||||
@ -181,7 +182,7 @@ public class MultiBlockChangeInfo {
|
|||||||
public Object getGeneric(Class<?> genericType, MultiBlockChangeInfo specific) {
|
public Object getGeneric(Class<?> genericType, MultiBlockChangeInfo specific) {
|
||||||
try {
|
try {
|
||||||
if (constructor == null) {
|
if (constructor == null) {
|
||||||
constructor = MinecraftReflection.getMultiBlockChangeInfoClass().getConstructor(
|
constructor = nmsClass.getConstructor(
|
||||||
PacketType.Play.Server.MULTI_BLOCK_CHANGE.getPacketClass(),
|
PacketType.Play.Server.MULTI_BLOCK_CHANGE.getPacketClass(),
|
||||||
short.class,
|
short.class,
|
||||||
MinecraftReflection.getIBlockDataClass()
|
MinecraftReflection.getIBlockDataClass()
|
||||||
@ -224,11 +225,11 @@ public class MultiBlockChangeInfo {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getGeneric(Class<?> genericType, MultiBlockChangeInfo[] specific) {
|
public Object getGeneric(Class<?> genericType, MultiBlockChangeInfo[] specific) {
|
||||||
Object[] result = (Object[]) Array.newInstance(genericType, specific.length);
|
Object[] result = (Object[]) Array.newInstance(nmsClass, specific.length);
|
||||||
|
|
||||||
// Wrap every item
|
// Wrap every item
|
||||||
for (int i = 0; i < result.length; i++) {
|
for (int i = 0; i < result.length; i++) {
|
||||||
result[i] = converter.getGeneric(genericType, specific[i]);
|
result[i] = converter.getGeneric(nmsClass, specific[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -48,12 +48,15 @@ public class MultiBlockChangeTest {
|
|||||||
WrappedBlockData blockData = WrappedBlockData.createData(Material.STONE);
|
WrappedBlockData blockData = WrappedBlockData.createData(Material.STONE);
|
||||||
MultiBlockChangeInfo info = new MultiBlockChangeInfo(location, blockData, chunk);
|
MultiBlockChangeInfo info = new MultiBlockChangeInfo(location, blockData, chunk);
|
||||||
|
|
||||||
Object generic = MultiBlockChangeInfo.getConverter(chunk).getGeneric(MinecraftReflection.getMultiBlockChangeInfoClass(), info);
|
MultiBlockChangeInfo[] array = { info, info };
|
||||||
MultiBlockChangeInfo back = MultiBlockChangeInfo.getConverter(chunk).getSpecific(generic);
|
|
||||||
|
|
||||||
assertEquals(info.getX(), back.getX());
|
Object generic = MultiBlockChangeInfo.getArrayConverter(chunk).getGeneric(MinecraftReflection.getMultiBlockChangeInfoArrayClass(),
|
||||||
assertEquals(info.getY(), back.getY());
|
array);
|
||||||
assertEquals(info.getZ(), back.getZ());
|
MultiBlockChangeInfo[] back = MultiBlockChangeInfo.getArrayConverter(chunk).getSpecific(generic);
|
||||||
assertEquals(info.getData(), back.getData());
|
|
||||||
|
assertEquals(info.getX(), back[0].getX());
|
||||||
|
assertEquals(info.getY(), back[0].getY());
|
||||||
|
assertEquals(info.getZ(), back[0].getZ());
|
||||||
|
assertEquals(info.getData(), back[0].getData());
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user