From c0df4b82d380bea4fd66cc887a1476468e2301c4 Mon Sep 17 00:00:00 2001 From: Senmori Date: Sun, 12 Aug 2018 18:39:51 +1000 Subject: SPIGOT-1936: LootTable API --- src/test/java/org/bukkit/LootTablesTest.java | 22 ++++++++++++++++++++++ .../org/bukkit/support/AbstractTestingBase.java | 11 ++++++++--- src/test/java/org/bukkit/support/DummyServer.java | 12 ++++++++++++ 3 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 src/test/java/org/bukkit/LootTablesTest.java (limited to 'src/test/java/org') diff --git a/src/test/java/org/bukkit/LootTablesTest.java b/src/test/java/org/bukkit/LootTablesTest.java new file mode 100644 index 00000000..8d2cbb44 --- /dev/null +++ b/src/test/java/org/bukkit/LootTablesTest.java @@ -0,0 +1,22 @@ +package org.bukkit; + +import org.bukkit.loot.LootTable; +import org.bukkit.loot.LootTables; +import org.bukkit.support.AbstractTestingBase; +import org.junit.Assert; +import org.junit.Test; + +public class LootTablesTest extends AbstractTestingBase { + + @Test + public void testLootTablesEnumExists() { + LootTables[] tables = LootTables.values(); + + for (LootTables table : tables) { + LootTable lootTable = Bukkit.getLootTable(table.getKey()); + + Assert.assertNotNull("Unknown LootTable " + table.getKey(), lootTable); + Assert.assertEquals(lootTable.getKey(), table.getKey()); + } + } +} diff --git a/src/test/java/org/bukkit/support/AbstractTestingBase.java b/src/test/java/org/bukkit/support/AbstractTestingBase.java index b6bc6641..53cbb525 100644 --- a/src/test/java/org/bukkit/support/AbstractTestingBase.java +++ b/src/test/java/org/bukkit/support/AbstractTestingBase.java @@ -5,6 +5,7 @@ import java.util.Collections; import java.util.List; import net.minecraft.server.DispenserRegistry; import net.minecraft.server.EnumResourcePackType; +import net.minecraft.server.LootTableRegistry; import net.minecraft.server.ResourceManager; import net.minecraft.server.ResourcePackVanilla; import net.minecraft.server.TagRegistry; @@ -24,12 +25,16 @@ public abstract class AbstractTestingBase { // Materials that only exist in block form (or are legacy) public static final List INVALIDATED_MATERIALS; + public static final LootTableRegistry LOOT_TABLE_REGISTRY; + public static final TagRegistry TAG_REGISTRY; + static { DispenserRegistry.c(); // Set up resource manager ResourceManager resourceManager = new ResourceManager(EnumResourcePackType.SERVER_DATA); - // add tags for unit tests - resourceManager.a(new TagRegistry()); + // add tags and loot tables for unit tests + resourceManager.a(TAG_REGISTRY = new TagRegistry()); + resourceManager.a(LOOT_TABLE_REGISTRY = new LootTableRegistry()); // Register vanilla pack resourceManager.a(Collections.singletonList(new ResourcePackVanilla("minecraft"))); @@ -43,6 +48,6 @@ public abstract class AbstractTestingBase { } } INVALIDATED_MATERIALS = builder.build(); - Assert.assertTrue("Expected 543 invalidated materials (got " + INVALIDATED_MATERIALS.size() + ")", INVALIDATED_MATERIALS.size() == 543); + Assert.assertEquals("Expected 543 invalidated materials (got " + INVALIDATED_MATERIALS.size() + ")", 543, INVALIDATED_MATERIALS.size()); } } diff --git a/src/test/java/org/bukkit/support/DummyServer.java b/src/test/java/org/bukkit/support/DummyServer.java index a6e7651a..02a31f09 100644 --- a/src/test/java/org/bukkit/support/DummyServer.java +++ b/src/test/java/org/bukkit/support/DummyServer.java @@ -8,10 +8,13 @@ import java.util.logging.Logger; import org.bukkit.Bukkit; import org.bukkit.Material; +import org.bukkit.NamespacedKey; import org.bukkit.Server; +import org.bukkit.craftbukkit.CraftLootTable; import org.bukkit.craftbukkit.block.data.CraftBlockData; import org.bukkit.craftbukkit.inventory.CraftItemFactory; import org.bukkit.craftbukkit.util.CraftMagicNumbers; +import org.bukkit.craftbukkit.util.CraftNamespacedKey; import org.bukkit.craftbukkit.util.Versioning; public class DummyServer implements InvocationHandler { @@ -79,6 +82,15 @@ public class DummyServer implements InvocationHandler { } } ); + methods.put(Server.class.getMethod("getLootTable", NamespacedKey.class), + new MethodHandler() { + @Override + public Object handle(DummyServer server, Object[] args) { + NamespacedKey key = (NamespacedKey) args[0]; + return new CraftLootTable(key, AbstractTestingBase.LOOT_TABLE_REGISTRY.a(CraftNamespacedKey.toMinecraft(key))); + } + } + ); Bukkit.setServer(Proxy.getProxyClass(Server.class.getClassLoader(), Server.class).asSubclass(Server.class).getConstructor(InvocationHandler.class).newInstance(new DummyServer())); } catch (Throwable t) { throw new Error(t); -- cgit v1.2.3