SPIGOT-2450: Improve scoreboard criteria API, add missing DisplaySlots

By: Parker Hawke <hawkeboyz2@hotmail.com>
This commit is contained in:
Bukkit/Spigot
2022-08-08 21:48:35 +10:00
parent ee7f1a0800
commit 9802bd131d
9 changed files with 503 additions and 1 deletions

View File

@@ -99,6 +99,16 @@ public final class TestServer implements InvocationHandler {
}
}
);
methodMap.put(
Server.class.getMethod("getScoreboardCriteria", String.class),
new MethodHandler() {
@Override
public Object handle(TestServer server, Object[] args) {
// Does not need to return anything. Exists solely to test CriteriaTest which has static init fields
return null;
}
}
);
methods = methodMap.build();
TestServer server = new TestServer();

View File

@@ -0,0 +1,24 @@
package org.bukkit.scoreboard;
import org.bukkit.Material;
import org.bukkit.Statistic;
import org.bukkit.TestServer;
import org.bukkit.entity.EntityType;
import org.junit.Assert;
import org.junit.Test;
public class CriteriaTest {
@Test
public void testStatistic() {
TestServer.getInstance();
Assert.assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.AVIATE_ONE_CM, Material.STONE)); // Generic statistic with block
Assert.assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.AVIATE_ONE_CM, EntityType.CREEPER)); // Generic statistic with entity type
Assert.assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.ENTITY_KILLED_BY, Material.AMETHYST_SHARD)); // Entity statistic with material
Assert.assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.MINE_BLOCK, Material.DIAMOND_PICKAXE)); // Block statistic with item
Assert.assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.BREAK_ITEM, Material.WATER)); // Item statistic with block
Assert.assertThrows(IllegalArgumentException.class, () -> Criteria.statistic(Statistic.KILL_ENTITY, Material.STONE)); // Entity statistic with Material
}
}