mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-10-22 16:17:44 +00:00
🔥
This commit is contained in:
1 parent
1d194e880b
commit
d76dadec30
13 files changed
+160
-68
No files matched your search
@@ -34,11 +34,19 @@ public class IrisWorldStorageTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mapsLegacyBukkitNamesToPaperKeys() {
|
||||
assertEquals(NamespacedKey.minecraft("overworld"), IrisWorldStorage.keyFromLegacyName("world", "world"));
|
||||
assertEquals(NamespacedKey.minecraft("the_nether"), IrisWorldStorage.keyFromLegacyName("world_nether", "world"));
|
||||
assertEquals(NamespacedKey.minecraft("the_end"), IrisWorldStorage.keyFromLegacyName("world_the_end", "world"));
|
||||
assertEquals(NamespacedKey.minecraft("iris_world"), IrisWorldStorage.keyFromLegacyName("Iris World", "world"));
|
||||
public void mapsIrisWorldNamesToOwnedPaperKeys() {
|
||||
assertEquals(NamespacedKey.minecraft("overworld"), IrisWorldStorage.keyFromName("world", "world"));
|
||||
assertEquals(NamespacedKey.minecraft("the_nether"), IrisWorldStorage.keyFromName("world_nether", "world"));
|
||||
assertEquals(NamespacedKey.minecraft("the_end"), IrisWorldStorage.keyFromName("world_the_end", "world"));
|
||||
assertEquals(new NamespacedKey("iris", "iris_world"), IrisWorldStorage.keyFromName("Iris World", "world"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mapsOwnedPaperKeysBackToLogicalWorldNames() {
|
||||
assertEquals("world", IrisWorldStorage.logicalName(NamespacedKey.minecraft("overworld"), "world"));
|
||||
assertEquals("world_nether", IrisWorldStorage.logicalName(NamespacedKey.minecraft("the_nether"), "world"));
|
||||
assertEquals("world_the_end", IrisWorldStorage.logicalName(NamespacedKey.minecraft("the_end"), "world"));
|
||||
assertEquals("iris_world", IrisWorldStorage.logicalName(new NamespacedKey("iris", "iris_world"), "world"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
package art.arcane.iris.util.common.director.handlers;
|
||||
|
||||
import art.arcane.volmlib.util.director.exceptions.DirectorParsingException;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.World;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
|
||||
public class WorldHandlerTest {
|
||||
@Test
|
||||
public void resolvesOwnedIrisWorldByLogicalNameAndCanonicalKey() throws DirectorParsingException {
|
||||
World world = world("iris_irisworld", new NamespacedKey("iris", "irisworld"));
|
||||
WorldHandler handler = new TestWorldHandler(List.of(world));
|
||||
|
||||
assertSame(world, handler.parse("irisworld", false));
|
||||
assertSame(world, handler.parse("iris:irisworld", false));
|
||||
assertThrows(DirectorParsingException.class, () -> handler.parse("minecraft:irisworld", false));
|
||||
}
|
||||
|
||||
private static World world(String name, NamespacedKey key) {
|
||||
return (World) Proxy.newProxyInstance(
|
||||
World.class.getClassLoader(),
|
||||
new Class<?>[]{World.class},
|
||||
(proxy, method, arguments) -> switch (method.getName()) {
|
||||
case "getName" -> name;
|
||||
case "getKey" -> key;
|
||||
case "equals" -> proxy == arguments[0];
|
||||
case "hashCode" -> System.identityHashCode(proxy);
|
||||
default -> defaultValue(method.getReturnType());
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private static Object defaultValue(Class<?> type) {
|
||||
if (!type.isPrimitive()) {
|
||||
return null;
|
||||
}
|
||||
if (type == boolean.class) {
|
||||
return false;
|
||||
}
|
||||
if (type == char.class) {
|
||||
return '\0';
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static final class TestWorldHandler extends WorldHandler {
|
||||
private final List<World> worlds;
|
||||
|
||||
private TestWorldHandler(List<World> worlds) {
|
||||
this.worlds = worlds;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<World> worldOptions() {
|
||||
return worlds;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user