mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-07-19 21:34:15 +00:00
🔥
This commit is contained in:
@@ -715,7 +715,7 @@ public class Iris extends VolmitPlugin implements Listener, ReloadAware {
|
||||
KList<String> deferredStartupWorlds = new KList<>();
|
||||
IrisWorlds.readBukkitWorlds().forEach((s, generator) -> {
|
||||
try {
|
||||
NamespacedKey worldKey = IrisWorldStorage.keyFromLegacyName(s);
|
||||
NamespacedKey worldKey = IrisWorldStorage.keyFromName(s);
|
||||
if (WorldIdentity.resolve(worldKey).isPresent() || !filter.test(s)) return;
|
||||
|
||||
Iris.info("Loading World: %s | Generator: %s", s, generator);
|
||||
@@ -824,7 +824,7 @@ public class Iris extends VolmitPlugin implements Listener, ReloadAware {
|
||||
continue;
|
||||
}
|
||||
|
||||
NamespacedKey worldKey = IrisWorldStorage.keyFromLegacyName(worldName);
|
||||
NamespacedKey worldKey = IrisWorldStorage.keyFromName(worldName);
|
||||
World loaded = WorldIdentity.resolve(worldKey).orElse(null);
|
||||
if (loaded != null) {
|
||||
if (TransientWorldCleanupSupport.isTransientStudioWorldName(worldName)) {
|
||||
@@ -1227,7 +1227,7 @@ public class Iris extends VolmitPlugin implements Listener, ReloadAware {
|
||||
}
|
||||
|
||||
Iris.debug("Assuming IrisDimension: " + dim.getName());
|
||||
NamespacedKey worldKey = IrisWorldStorage.keyFromLegacyName(worldName);
|
||||
NamespacedKey worldKey = IrisWorldStorage.keyFromName(worldName);
|
||||
|
||||
IrisWorld w = IrisWorld.builder()
|
||||
.platformIdentity(worldKey.toString())
|
||||
@@ -1289,7 +1289,7 @@ public class Iris extends VolmitPlugin implements Listener, ReloadAware {
|
||||
|
||||
@Nullable
|
||||
public static IrisDimension loadDimension(@NonNull String worldName, @NonNull String id) {
|
||||
File pack = IrisWorldStorage.packRoot(IrisWorldStorage.keyFromLegacyName(worldName));
|
||||
File pack = IrisWorldStorage.packRoot(IrisWorldStorage.keyFromName(worldName));
|
||||
IrisDimension dimension = pack.isDirectory() ? IrisData.get(pack).getDimensionLoader().load(id) : null;
|
||||
if (dimension == null) dimension = IrisData.loadAnyDimension(id, null);
|
||||
if (dimension == null) {
|
||||
|
||||
+27
-24
@@ -101,19 +101,20 @@ public class CommandIris implements DirectorExecutor {
|
||||
@Param(aliases = "main-world", description = "Whether or not to automatically use this world as the main world", defaultValue = "false")
|
||||
boolean main
|
||||
) {
|
||||
if (name.equalsIgnoreCase("iris")) {
|
||||
String worldName = IrisWorldStorage.logicalName(IrisWorldStorage.keyFromName(name));
|
||||
if (worldName.equalsIgnoreCase("iris")) {
|
||||
sender().sendMessage(C.RED + "You cannot use the world name \"iris\" for creating worlds as Iris uses this directory for studio worlds.");
|
||||
sender().sendMessage(C.RED + "May we suggest the name \"IrisWorld\" instead?");
|
||||
return;
|
||||
}
|
||||
|
||||
if (name.equalsIgnoreCase("benchmark")) {
|
||||
if (worldName.equalsIgnoreCase("benchmark")) {
|
||||
sender().sendMessage(C.RED + "You cannot use the world name \"benchmark\" for creating worlds as Iris uses this directory for Benchmarking Packs.");
|
||||
sender().sendMessage(C.RED + "May we suggest the name \"IrisWorld\" instead?");
|
||||
return;
|
||||
}
|
||||
|
||||
if (IrisWorldStorage.dimensionRoot(name).exists()) {
|
||||
if (IrisWorldStorage.dimensionRoot(worldName).exists()) {
|
||||
sender().sendMessage(C.RED + "That folder already exists!");
|
||||
return;
|
||||
}
|
||||
@@ -131,8 +132,8 @@ public class CommandIris implements DirectorExecutor {
|
||||
}
|
||||
|
||||
if (J.isFolia()) {
|
||||
if (stageFoliaWorldCreation(name, dimension, seed, main)) {
|
||||
sender().sendMessage(C.GREEN + "World staging completed. Restart the server to generate/load \"" + name + "\".");
|
||||
if (stageFoliaWorldCreation(worldName, dimension, seed, main)) {
|
||||
sender().sendMessage(C.GREEN + "World staging completed. Restart the server to generate/load \"" + worldName + "\".");
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -141,7 +142,7 @@ public class CommandIris implements DirectorExecutor {
|
||||
worldCreation = true;
|
||||
IrisToolbelt.createWorld()
|
||||
.dimension(resolvedType)
|
||||
.name(name)
|
||||
.name(worldName)
|
||||
.seed(seed)
|
||||
.sender(sender())
|
||||
.studio(false)
|
||||
@@ -149,12 +150,12 @@ public class CommandIris implements DirectorExecutor {
|
||||
if (main) {
|
||||
Runtime.getRuntime().addShutdownHook(mainWorld.updateAndGet(old -> {
|
||||
if (old != null) Runtime.getRuntime().removeShutdownHook(old);
|
||||
return new Thread(() -> updateMainWorld(name));
|
||||
return new Thread(() -> updateMainWorld(worldName));
|
||||
}));
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
sender().sendMessage(C.RED + "Exception raised during creation. See the console for more details.");
|
||||
Iris.reportError("Exception raised during world creation for \"" + name + "\".", e);
|
||||
Iris.reportError("Exception raised during world creation for \"" + worldName + "\".", e);
|
||||
worldCreation = false;
|
||||
return;
|
||||
}
|
||||
@@ -173,7 +174,7 @@ public class CommandIris implements DirectorExecutor {
|
||||
data.load(in);
|
||||
}
|
||||
|
||||
File sourceDimensionRoot = IrisWorldStorage.dimensionRoot(IrisWorldStorage.keyFromLegacyName(newName));
|
||||
File sourceDimensionRoot = IrisWorldStorage.dimensionRoot(IrisWorldStorage.keyFromName(newName));
|
||||
if (!sourceDimensionRoot.isDirectory()) {
|
||||
throw new IllegalStateException("Source dimension folder does not exist: " + sourceDimensionRoot.getAbsolutePath());
|
||||
}
|
||||
@@ -195,7 +196,7 @@ public class CommandIris implements DirectorExecutor {
|
||||
File targetDimensionRoot = IrisWorldStorage.dimensionRoot(newLevelRoot, NamespacedKey.minecraft("overworld"));
|
||||
IO.copyDirectory(sourceDimensionRoot.toPath(), targetDimensionRoot.toPath());
|
||||
|
||||
World sourceWorld = WorldIdentity.resolve(IrisWorldStorage.keyFromLegacyName(newName)).orElse(null);
|
||||
World sourceWorld = WorldIdentity.resolve(IrisWorldStorage.keyFromName(newName)).orElse(null);
|
||||
Long stagedSeed = IrisWorlds.readBukkitWorldSeed(newName);
|
||||
if (sourceWorld == null && stagedSeed == null) {
|
||||
throw new IllegalStateException("Cannot determine the promoted world's seed.");
|
||||
@@ -246,14 +247,15 @@ public class CommandIris implements DirectorExecutor {
|
||||
}
|
||||
|
||||
private boolean registerWorldInBukkitYml(String worldName, String dimension, Long seed) {
|
||||
String logicalWorldName = IrisWorldStorage.logicalName(IrisWorldStorage.keyFromName(worldName));
|
||||
YamlConfiguration yml = YamlConfiguration.loadConfiguration(BUKKIT_YML);
|
||||
ConfigurationSection worlds = yml.getConfigurationSection("worlds");
|
||||
if (worlds == null) {
|
||||
worlds = yml.createSection("worlds");
|
||||
}
|
||||
ConfigurationSection worldSection = worlds.getConfigurationSection(worldName);
|
||||
ConfigurationSection worldSection = worlds.getConfigurationSection(logicalWorldName);
|
||||
if (worldSection == null) {
|
||||
worldSection = worlds.createSection(worldName);
|
||||
worldSection = worlds.createSection(logicalWorldName);
|
||||
}
|
||||
|
||||
String generator = "Iris:" + dimension;
|
||||
@@ -264,7 +266,7 @@ public class CommandIris implements DirectorExecutor {
|
||||
|
||||
try {
|
||||
yml.save(BUKKIT_YML);
|
||||
Iris.info("Registered \"" + worldName + "\" in bukkit.yml");
|
||||
Iris.info("Registered \"" + logicalWorldName + "\" in bukkit.yml");
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
sender().sendMessage(C.RED + "Failed to update bukkit.yml: " + e.getMessage());
|
||||
@@ -518,16 +520,17 @@ public class CommandIris implements DirectorExecutor {
|
||||
@Param(description = "The name of the world to load")
|
||||
String world
|
||||
) {
|
||||
worldNameToCheck = world;
|
||||
String logicalWorldName = IrisWorldStorage.logicalName(IrisWorldStorage.keyFromName(world));
|
||||
worldNameToCheck = logicalWorldName;
|
||||
boolean worldExists = doesWorldExist(worldNameToCheck);
|
||||
WorldEngine = world;
|
||||
WorldEngine = logicalWorldName;
|
||||
|
||||
if (!worldExists) {
|
||||
sender().sendMessage(C.YELLOW + world + " Doesnt exist on the server.");
|
||||
sender().sendMessage(C.YELLOW + logicalWorldName + " Doesnt exist on the server.");
|
||||
return;
|
||||
}
|
||||
|
||||
File directory = new File(IrisWorldStorage.packRoot(IrisWorldStorage.keyFromLegacyName(world)), "dimensions");
|
||||
File directory = new File(IrisWorldStorage.packRoot(IrisWorldStorage.keyFromName(logicalWorldName)), "dimensions");
|
||||
|
||||
String dimension = null;
|
||||
if (directory.exists() && directory.isDirectory()) {
|
||||
@@ -544,28 +547,28 @@ public class CommandIris implements DirectorExecutor {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
sender().sendMessage(C.GOLD + world + " is not an iris world.");
|
||||
sender().sendMessage(C.GOLD + logicalWorldName + " is not an iris world.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (dimension == null) {
|
||||
sender().sendMessage(C.RED + "Could not determine Iris dimension for " + world + ".");
|
||||
sender().sendMessage(C.RED + "Could not determine Iris dimension for " + logicalWorldName + ".");
|
||||
return;
|
||||
}
|
||||
|
||||
sender().sendMessage(C.GREEN + "Loading world: " + world);
|
||||
sender().sendMessage(C.GREEN + "Loading world: " + logicalWorldName);
|
||||
|
||||
if (!registerWorldInBukkitYml(world, dimension, null)) {
|
||||
if (!registerWorldInBukkitYml(logicalWorldName, dimension, null)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (J.isFolia()) {
|
||||
sender().sendMessage(C.YELLOW + "Folia cannot load new worlds at runtime. Restart the server to load \"" + world + "\".");
|
||||
sender().sendMessage(C.YELLOW + "Folia cannot load new worlds at runtime. Restart the server to load \"" + logicalWorldName + "\".");
|
||||
return;
|
||||
}
|
||||
|
||||
Iris.instance.checkForBukkitWorlds(world::equals);
|
||||
sender().sendMessage(C.GREEN + world + " loaded successfully.");
|
||||
Iris.instance.checkForBukkitWorlds(logicalWorldName::equals);
|
||||
sender().sendMessage(C.GREEN + logicalWorldName + " loaded successfully.");
|
||||
}
|
||||
@Director(description = "Evacuate an iris world", origin = DirectorOrigin.PLAYER, sync = true)
|
||||
public void evacuate(
|
||||
|
||||
@@ -13,6 +13,8 @@ import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
public final class IrisWorldStorage {
|
||||
private static final String IRIS_NAMESPACE = "iris";
|
||||
|
||||
private IrisWorldStorage() {
|
||||
}
|
||||
|
||||
@@ -36,11 +38,11 @@ public final class IrisWorldStorage {
|
||||
return dimensionRoot.getAbsoluteFile();
|
||||
}
|
||||
|
||||
public static NamespacedKey keyFromLegacyName(String worldName) {
|
||||
return keyFromLegacyName(worldName, levelRoot().getName());
|
||||
public static NamespacedKey keyFromName(String worldName) {
|
||||
return keyFromName(worldName, levelRoot().getName());
|
||||
}
|
||||
|
||||
static NamespacedKey keyFromLegacyName(String worldName, String levelName) {
|
||||
static NamespacedKey keyFromName(String worldName, String levelName) {
|
||||
String name = Objects.requireNonNull(worldName, "worldName").trim();
|
||||
String mainLevelName = Objects.requireNonNull(levelName, "levelName").trim();
|
||||
if (name.isEmpty()) {
|
||||
@@ -57,11 +59,34 @@ public final class IrisWorldStorage {
|
||||
}
|
||||
|
||||
String key = name.toLowerCase(Locale.ENGLISH).replace(' ', '_');
|
||||
return NamespacedKey.minecraft(key);
|
||||
return new NamespacedKey(IRIS_NAMESPACE, key);
|
||||
}
|
||||
|
||||
public static String logicalName(WorldInfo world) {
|
||||
return logicalName(WorldIdentity.key(world));
|
||||
}
|
||||
|
||||
public static String logicalName(NamespacedKey key) {
|
||||
return logicalName(key, levelRoot().getName());
|
||||
}
|
||||
|
||||
static String logicalName(NamespacedKey key, String levelName) {
|
||||
NamespacedKey worldKey = Objects.requireNonNull(key, "key");
|
||||
String mainLevelName = Objects.requireNonNull(levelName, "levelName").trim();
|
||||
if (NamespacedKey.minecraft("overworld").equals(worldKey)) {
|
||||
return mainLevelName;
|
||||
}
|
||||
if (NamespacedKey.minecraft("the_nether").equals(worldKey)) {
|
||||
return mainLevelName + "_nether";
|
||||
}
|
||||
if (NamespacedKey.minecraft("the_end").equals(worldKey)) {
|
||||
return mainLevelName + "_the_end";
|
||||
}
|
||||
return worldKey.getKey();
|
||||
}
|
||||
|
||||
public static File dimensionRoot(String worldName) {
|
||||
return dimensionRoot(keyFromLegacyName(worldName));
|
||||
return dimensionRoot(keyFromName(worldName));
|
||||
}
|
||||
|
||||
public static File dimensionRoot(WorldInfo world) {
|
||||
|
||||
@@ -35,14 +35,8 @@ public class IrisWorlds {
|
||||
|
||||
private IrisWorlds(KMap<String, String> worlds) {
|
||||
this.worlds = new KMap<>();
|
||||
worlds.forEach((identity, type) -> {
|
||||
String normalizedIdentity = migrateLoadedIdentity(identity);
|
||||
this.worlds.put(normalizedIdentity, type);
|
||||
if (!normalizedIdentity.equals(identity)) {
|
||||
dirty = true;
|
||||
}
|
||||
});
|
||||
readBukkitWorlds().forEach((name, type) -> put0(IrisWorldStorage.keyFromLegacyName(name).toString(), type));
|
||||
worlds.forEach((identity, type) -> this.worlds.put(WorldIdentity.parse(identity).toString(), type));
|
||||
readBukkitWorlds().forEach((name, type) -> put0(IrisWorldStorage.keyFromName(name).toString(), type));
|
||||
save();
|
||||
}
|
||||
|
||||
@@ -82,7 +76,7 @@ public class IrisWorlds {
|
||||
public KMap<String, String> getWorlds() {
|
||||
clean();
|
||||
KMap<String, String> result = new KMap<>();
|
||||
readBukkitWorlds().forEach((name, type) -> result.put(IrisWorldStorage.keyFromLegacyName(name).toString(), type));
|
||||
readBukkitWorlds().forEach((name, type) -> result.put(IrisWorldStorage.keyFromName(name).toString(), type));
|
||||
return result.put(worlds);
|
||||
}
|
||||
|
||||
@@ -174,12 +168,4 @@ public class IrisWorlds {
|
||||
}
|
||||
return dimension;
|
||||
}
|
||||
|
||||
private static String migrateLoadedIdentity(String identity) {
|
||||
try {
|
||||
return WorldIdentity.parse(identity).toString();
|
||||
} catch (IllegalArgumentException e) {
|
||||
return IrisWorldStorage.keyFromLegacyName(identity).toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +76,9 @@ public final class StudioOpenCoordinator {
|
||||
}
|
||||
|
||||
World world = BukkitWorldBinding.world(provider.getTarget().getWorld());
|
||||
String worldName = world == null ? provider.getTarget().getWorld().name() : world.getName();
|
||||
String worldName = world == null
|
||||
? IrisWorldStorage.logicalName(WorldIdentity.parse(provider.getTarget().getWorld().identity()))
|
||||
: IrisWorldStorage.logicalName(world);
|
||||
try {
|
||||
return closeWorld(provider, worldName, world, true, project);
|
||||
} catch (Throwable e) {
|
||||
@@ -330,7 +332,7 @@ public final class StudioOpenCoordinator {
|
||||
}
|
||||
|
||||
for (String familyWorldName : TransientWorldCleanupSupport.worldFamilyNames(worldName)) {
|
||||
World familyWorld = WorldIdentity.resolve(IrisWorldStorage.keyFromLegacyName(familyWorldName)).orElse(null);
|
||||
World familyWorld = WorldIdentity.resolve(IrisWorldStorage.keyFromName(familyWorldName)).orElse(null);
|
||||
if (familyWorld == null) {
|
||||
continue;
|
||||
}
|
||||
@@ -387,7 +389,7 @@ public final class StudioOpenCoordinator {
|
||||
}
|
||||
|
||||
for (String staleWorldName : staleWorldNames) {
|
||||
if (WorldIdentity.resolve(IrisWorldStorage.keyFromLegacyName(staleWorldName)).isPresent()) {
|
||||
if (WorldIdentity.resolve(IrisWorldStorage.keyFromName(staleWorldName)).isPresent()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -481,7 +483,7 @@ public final class StudioOpenCoordinator {
|
||||
}
|
||||
|
||||
for (String familyWorldName : TransientWorldCleanupSupport.worldFamilyNames(worldName)) {
|
||||
if (WorldIdentity.resolve(IrisWorldStorage.keyFromLegacyName(familyWorldName)).isPresent()) {
|
||||
if (WorldIdentity.resolve(IrisWorldStorage.keyFromName(familyWorldName)).isPresent()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ import art.arcane.iris.engine.object.IrisDimension;
|
||||
import art.arcane.iris.engine.platform.PlatformChunkGenerator;
|
||||
import art.arcane.iris.platform.bukkit.BukkitPlatform;
|
||||
import art.arcane.volmlib.util.collection.KMap;
|
||||
import art.arcane.volmlib.util.bukkit.WorldIdentity;
|
||||
import art.arcane.volmlib.util.exceptions.IrisException;
|
||||
import art.arcane.volmlib.util.io.IO;
|
||||
import art.arcane.volmlib.util.json.JSONException;
|
||||
@@ -93,7 +94,8 @@ public class StudioSVC implements IrisService {
|
||||
if (activeProject != null) {
|
||||
PlatformChunkGenerator activeProvider = activeProject.getActiveProvider();
|
||||
if (activeProvider != null) {
|
||||
String activeWorldName = activeProvider.getTarget().getWorld().name();
|
||||
String activeWorldName = IrisWorldStorage.logicalName(
|
||||
WorldIdentity.parse(activeProvider.getTarget().getWorld().identity()));
|
||||
if (activeWorldName != null && !activeWorldName.isBlank()) {
|
||||
worldNamesToDelete.add(activeWorldName);
|
||||
}
|
||||
@@ -105,7 +107,7 @@ public class StudioSVC implements IrisService {
|
||||
continue;
|
||||
}
|
||||
|
||||
worldNamesToDelete.add(i.getName());
|
||||
worldNamesToDelete.add(IrisWorldStorage.logicalName(i));
|
||||
PlatformChunkGenerator generator = IrisToolbelt.access(i);
|
||||
if (!stopping) {
|
||||
destroyStudioWorld(i, generator);
|
||||
@@ -422,7 +424,7 @@ public class StudioSVC implements IrisService {
|
||||
IrisLogging.reportError("Failed to unload studio world \"" + world.getName() + "\" during shutdown cleanup.", e);
|
||||
}
|
||||
|
||||
deleteTransientStudioFolders(world.getName());
|
||||
deleteTransientStudioFolders(IrisWorldStorage.logicalName(world));
|
||||
}
|
||||
|
||||
private void deleteTransientStudioFolders(String worldName) {
|
||||
|
||||
@@ -294,11 +294,11 @@ public final class FeatureImporter {
|
||||
|
||||
static World createScratchWorld(VolmitSender sender) {
|
||||
try {
|
||||
World existing = WorldIdentity.resolve(IrisWorldStorage.keyFromLegacyName(SCRATCH_WORLD_NAME)).orElse(null);
|
||||
World existing = WorldIdentity.resolve(IrisWorldStorage.keyFromName(SCRATCH_WORLD_NAME)).orElse(null);
|
||||
if (existing != null) {
|
||||
return existing;
|
||||
}
|
||||
WorldCreator creator = WorldCreator.ofKey(IrisWorldStorage.keyFromLegacyName(SCRATCH_WORLD_NAME))
|
||||
WorldCreator creator = WorldCreator.ofKey(IrisWorldStorage.keyFromName(SCRATCH_WORLD_NAME))
|
||||
.environment(World.Environment.NORMAL)
|
||||
.type(WorldType.FLAT)
|
||||
.generateStructures(false);
|
||||
|
||||
@@ -155,6 +155,7 @@ public class IrisCreator {
|
||||
if (Bukkit.isPrimaryThread()) {
|
||||
throw new IrisException("You cannot invoke create() on the main thread.");
|
||||
}
|
||||
name = IrisWorldStorage.logicalName(IrisWorldStorage.keyFromName(name));
|
||||
|
||||
long createStart = System.currentTimeMillis();
|
||||
reportStudioProgress(0.02D, "resolve_dimension");
|
||||
@@ -323,7 +324,7 @@ public class IrisCreator {
|
||||
IrisLogging.reportError("World \"" + world.getName()
|
||||
+ "\" was created, but automatic teleport failed for player \"" + player.getName() + "\".", throwable);
|
||||
J.runEntity(player, () -> new VolmitSender(player).sendMessage(C.YELLOW
|
||||
+ "The world was created, but automatic teleport failed. Try /iris teleport world=" + world.getName()));
|
||||
+ "The world was created, but automatic teleport failed. Try /iris teleport world=" + IrisWorldStorage.logicalName(world)));
|
||||
}
|
||||
|
||||
private void reportStudioProgress(double progress, String stage) {
|
||||
|
||||
@@ -150,7 +150,7 @@ public class IrisPackBenchmarking {
|
||||
}
|
||||
|
||||
private static World benchmarkWorld() {
|
||||
return WorldIdentity.resolve(IrisWorldStorage.keyFromLegacyName("benchmark")).orElse(null);
|
||||
return WorldIdentity.resolve(IrisWorldStorage.keyFromName("benchmark")).orElse(null);
|
||||
}
|
||||
|
||||
private double calculateAverage(KList<Integer> list) {
|
||||
|
||||
@@ -25,6 +25,7 @@ import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.platform.bukkit.BukkitPlatform;
|
||||
import art.arcane.iris.core.IrisRuntimeSchedulerMode;
|
||||
import art.arcane.iris.core.IrisSettings;
|
||||
import art.arcane.iris.core.IrisWorldStorage;
|
||||
import art.arcane.iris.core.gui.PregeneratorJob;
|
||||
import art.arcane.iris.core.loader.IrisData;
|
||||
import art.arcane.iris.core.pregenerator.PregenPerformanceProfile;
|
||||
@@ -531,7 +532,7 @@ public class IrisToolbelt {
|
||||
}
|
||||
|
||||
public static boolean removeWorld(World world) throws IOException {
|
||||
return IrisCreator.removeFromBukkitYml(world.getName());
|
||||
return IrisCreator.removeFromBukkitYml(IrisWorldStorage.logicalName(world));
|
||||
}
|
||||
|
||||
record PackReference(String pack, String dimension, boolean explicitDimension) {
|
||||
|
||||
@@ -76,7 +76,7 @@ public class IrisWorldCreator {
|
||||
|
||||
public WorldCreator create() {
|
||||
IrisDimension dim = dimension == null ? IrisData.loadAnyDimension(dimensionName, null) : dimension;
|
||||
NamespacedKey worldKey = IrisWorldStorage.keyFromLegacyName(name);
|
||||
NamespacedKey worldKey = IrisWorldStorage.keyFromName(name);
|
||||
World.Environment environment = findEnvironment();
|
||||
|
||||
IrisWorld w = IrisWorld.builder()
|
||||
|
||||
@@ -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