Add modifier for item lists
Dieser Commit ist enthalten in:
Ursprung
7d382279ad
Commit
7a9b9afe2e
@ -402,6 +402,24 @@ public class PacketContainer implements Serializable {
|
|||||||
BukkitConverters.getIgnoreNull(new ItemStackArrayConverter()));
|
BukkitConverters.getIgnoreNull(new ItemStackArrayConverter()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a read/write structure for lists of ItemStacks.
|
||||||
|
* <p>
|
||||||
|
* This modifier will automatically marshal between the Bukkit ItemStack and the
|
||||||
|
* internal Minecraft ItemStack.
|
||||||
|
* @return A modifier for ItemStack list fields.
|
||||||
|
*/
|
||||||
|
public StructureModifier<List<ItemStack>> getItemListModifier() {
|
||||||
|
// Convert to and from the Bukkit wrapper
|
||||||
|
return structureModifier.withType(
|
||||||
|
List.class,
|
||||||
|
BukkitConverters.getListConverter(
|
||||||
|
MinecraftReflection.getItemStackClass(),
|
||||||
|
BukkitConverters.getItemStackConverter()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve a read/write structure for maps of statistics.
|
* Retrieve a read/write structure for maps of statistics.
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -24,6 +24,7 @@ import static org.junit.Assert.fail;
|
|||||||
|
|
||||||
import java.lang.reflect.Array;
|
import java.lang.reflect.Array;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -219,34 +220,24 @@ public class PacketContainerTest {
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: It's a list now
|
@Test
|
||||||
/* @Test
|
public void testGetItemListModifier() {
|
||||||
public void testGetItemArrayModifier() {
|
|
||||||
PacketContainer windowItems = new PacketContainer(PacketType.Play.Server.WINDOW_ITEMS);
|
PacketContainer windowItems = new PacketContainer(PacketType.Play.Server.WINDOW_ITEMS);
|
||||||
StructureModifier<ItemStack[]> itemAccess = windowItems.getItemArrayModifier();
|
StructureModifier<List<ItemStack>> itemAccess = windowItems.getItemListModifier();
|
||||||
|
|
||||||
ItemStack[] itemArray = new ItemStack[] {
|
List<ItemStack> items = new ArrayList<>();
|
||||||
itemWithData(),
|
items.add(itemWithData());
|
||||||
new ItemStack(Material.DIAMOND_AXE)
|
items.add(new ItemStack(Material.DIAMOND_AXE));
|
||||||
};
|
|
||||||
|
|
||||||
assertNull(itemAccess.read(0));
|
assertNull(itemAccess.read(0));
|
||||||
|
|
||||||
// Insert and check that it was succesful
|
// Insert and check that it was succesful
|
||||||
itemAccess.write(0, itemArray);
|
itemAccess.write(0, items);
|
||||||
|
|
||||||
// Read back array
|
// Read back array
|
||||||
ItemStack[] comparison = itemAccess.read(0);
|
List<ItemStack> comparison = itemAccess.read(0);
|
||||||
assertEquals(itemArray.length, comparison.length);
|
assertEquals(items, comparison);
|
||||||
|
}
|
||||||
// Check that it is equivalent
|
|
||||||
for (int i = 0; i < itemArray.length; i++) {
|
|
||||||
ItemStack original = itemArray[i];
|
|
||||||
ItemStack written = comparison[i];
|
|
||||||
|
|
||||||
assertTrue(String.format("Array element %s is not the same: %s != %s", i, original, written), equivalentItem(original, written));
|
|
||||||
}
|
|
||||||
} */
|
|
||||||
|
|
||||||
private boolean equivalentItem(ItemStack first, ItemStack second) {
|
private boolean equivalentItem(ItemStack first, ItemStack second) {
|
||||||
if (first == null) {
|
if (first == null) {
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren