Archiviert
13
0

Add WrappedBlockData.getData(), improve block data test

Dieser Commit ist enthalten in:
Dan Mulloy 2015-09-23 20:18:04 -04:00
Ursprung 4e16792450
Commit 0d3867c6f1
2 geänderte Dateien mit 29 neuen und 4 gelöschten Zeilen

Datei anzeigen

@ -38,6 +38,7 @@ public class WrappedBlockData extends AbstractWrapper {
private static final Class<?> BLOCK = MinecraftReflection.getBlockClass();
private static MethodAccessor FROM_LEGACY_DATA = null;
private static MethodAccessor TO_LEGACY_DATA = null;
private static MethodAccessor GET_NMS_BLOCK = null;
private static MethodAccessor GET_BLOCK = null;
@ -50,6 +51,13 @@ public class WrappedBlockData extends AbstractWrapper {
.build();
FROM_LEGACY_DATA = Accessors.getMethodAccessor(fuzzy.getMethod(contract));
contract = FuzzyMethodContract.newBuilder()
.banModifier(Modifier.STATIC)
.parameterExactArray(IBLOCK_DATA)
.returnTypeExact(int.class)
.build();
TO_LEGACY_DATA = Accessors.getMethodAccessor(fuzzy.getMethod(contract));
fuzzy = FuzzyReflection.fromClass(MAGIC_NUMBERS);
GET_NMS_BLOCK = Accessors.getMethodAccessor(fuzzy.getMethodByParameters("getBlock", BLOCK,
new Class<?>[] { Material.class }));
@ -73,6 +81,15 @@ public class WrappedBlockData extends AbstractWrapper {
return BukkitConverters.getBlockConverter().getSpecific(block);
}
/**
* Retrieves the data of this BlockData.
* @return The data of this BlockData.
*/
public int getData() {
Object block = GET_BLOCK.invoke(handle);
return (Integer) TO_LEGACY_DATA.invoke(block, handle);
}
/**
* Sets the type of this BlockData.
* @param type New type

Datei anzeigen

@ -18,6 +18,7 @@ package com.comphenix.protocol.wrappers;
import static org.junit.Assert.assertEquals;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.junit.BeforeClass;
import org.junit.Test;
@ -38,11 +39,18 @@ public class WrappedBlockDataTest {
@Test
public void test() {
Material type = Material.STONE;
WrappedBlockData data = WrappedBlockData.createData(type);
Object generic = BukkitConverters.getWrappedBlockDataConverter().getGeneric(MinecraftReflection.getIBlockDataClass(), data);
Material type = Material.WOOL;
int data = DyeColor.BLUE.getWoolData();
WrappedBlockData wrapper = WrappedBlockData.createData(type, data);
assertEquals(wrapper.getType(), type);
assertEquals(wrapper.getData(), data);
Object generic = BukkitConverters.getWrappedBlockDataConverter().getGeneric(MinecraftReflection.getIBlockDataClass(), wrapper);
WrappedBlockData back = BukkitConverters.getWrappedBlockDataConverter().getSpecific(generic);
assertEquals(data.getType(), back.getType());
assertEquals(wrapper.getType(), back.getType());
assertEquals(wrapper.getData(), back.getData());
}
}