summaryrefslogtreecommitdiffstats
path: root/src/test/java
diff options
context:
space:
mode:
authorSenmori <thesenmori@gmail.com>2018-08-12 18:39:51 +1000
committermd_5 <git@md-5.net>2018-08-12 18:40:03 +1000
commitc0df4b82d380bea4fd66cc887a1476468e2301c4 (patch)
tree0fa0d8db07d29c0f1c53bb9a70568eb42e9a9c7d /src/test/java
parent15da7067067a0786d221f2ad3cd060acd4dd3431 (diff)
downloadcraftbukkit-c0df4b82d380bea4fd66cc887a1476468e2301c4.tar
craftbukkit-c0df4b82d380bea4fd66cc887a1476468e2301c4.tar.gz
craftbukkit-c0df4b82d380bea4fd66cc887a1476468e2301c4.tar.lz
craftbukkit-c0df4b82d380bea4fd66cc887a1476468e2301c4.tar.xz
craftbukkit-c0df4b82d380bea4fd66cc887a1476468e2301c4.zip
SPIGOT-1936: LootTable API
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/bukkit/LootTablesTest.java22
-rw-r--r--src/test/java/org/bukkit/support/AbstractTestingBase.java11
-rw-r--r--src/test/java/org/bukkit/support/DummyServer.java12
3 files changed, 42 insertions, 3 deletions
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<Material> 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);