World Changes

This commit is contained in:
Brian Neumann-Fopiano
2026-07-12 17:06:30 -04:00
parent e42ab6fae6
commit cd05fd1bca
58 changed files with 668 additions and 313 deletions
+3 -3
View File
@@ -62,7 +62,7 @@ dependencies {
api(project(':spi'))
// Provided or Classpath
compileOnly(libs.spigot)
compileOnly(libs.paper.api)
compileOnly(libs.log4j.api)
compileOnly(libs.log4j.core)
@@ -120,8 +120,8 @@ dependencies {
testImplementation('junit:junit:4.13.2')
testImplementation('org.mockito:mockito-core:5.16.1')
testImplementation(libs.spigot)
testRuntimeOnly(libs.spigot)
testImplementation(libs.paper.api)
testRuntimeOnly(libs.paper.api)
}
java {
@@ -254,7 +254,6 @@ public class IrisSettings {
public boolean adjustVanillaHeight = false;
public boolean autoIngestDatapacks = true;
public boolean autoImportDatapackStructures = true;
public String forceMainWorld = "";
public int spinh = -20;
public int spins = 7;
public int spinb = 8;
@@ -0,0 +1,129 @@
package art.arcane.iris.core;
import art.arcane.volmlib.util.bukkit.WorldIdentity;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.World;
import org.bukkit.generator.WorldInfo;
import java.io.File;
import java.nio.file.Path;
import java.util.Locale;
import java.util.Objects;
import java.util.Optional;
public final class IrisWorldStorage {
private IrisWorldStorage() {
}
public static File levelRoot() {
return Bukkit.getServer().getLevelDirectory().toAbsolutePath().normalize().toFile();
}
public static File levelRoot(File dimensionRoot) {
Path current = Objects.requireNonNull(dimensionRoot, "dimensionRoot").toPath().toAbsolutePath().normalize();
while (current != null) {
Path fileName = current.getFileName();
if (fileName != null && "dimensions".equals(fileName.toString())) {
Path parent = current.getParent();
if (parent != null) {
return parent.toFile();
}
break;
}
current = current.getParent();
}
return dimensionRoot.getAbsoluteFile();
}
public static NamespacedKey keyFromLegacyName(String worldName) {
return keyFromLegacyName(worldName, levelRoot().getName());
}
static NamespacedKey keyFromLegacyName(String worldName, String levelName) {
String name = Objects.requireNonNull(worldName, "worldName").trim();
String mainLevelName = Objects.requireNonNull(levelName, "levelName").trim();
if (name.isEmpty()) {
throw new IllegalArgumentException("World name cannot be empty.");
}
if (name.equals(mainLevelName)) {
return NamespacedKey.minecraft("overworld");
}
if (name.equals(mainLevelName + "_nether")) {
return NamespacedKey.minecraft("the_nether");
}
if (name.equals(mainLevelName + "_the_end")) {
return NamespacedKey.minecraft("the_end");
}
String key = name.toLowerCase(Locale.ENGLISH).replace(' ', '_');
return NamespacedKey.minecraft(key);
}
public static File dimensionRoot(String worldName) {
return dimensionRoot(keyFromLegacyName(worldName));
}
public static File dimensionRoot(WorldInfo world) {
NamespacedKey key = WorldIdentity.key(world);
Optional<World> loadedWorld = WorldIdentity.resolve(key);
if (loadedWorld.isPresent()) {
return loadedWorld.get().getWorldFolder().getAbsoluteFile();
}
return dimensionRoot(key);
}
public static File dimensionRoot(NamespacedKey key) {
return dimensionRoot(levelRoot(), key);
}
public static File dimensionRoot(File levelRoot, NamespacedKey key) {
Path dimensionsRoot = Objects.requireNonNull(levelRoot, "levelRoot")
.toPath()
.toAbsolutePath()
.normalize()
.resolve("dimensions");
NamespacedKey worldKey = Objects.requireNonNull(key, "key");
Path namespaceRoot = dimensionsRoot.resolve(worldKey.getNamespace()).normalize();
Path dimensionRoot = namespaceRoot.resolve(worldKey.getKey()).normalize();
if (!dimensionRoot.startsWith(namespaceRoot)) {
throw new IllegalArgumentException("World key escapes its namespace storage root: " + worldKey);
}
return dimensionRoot.toFile();
}
public static Optional<NamespacedKey> keyFromDimensionRoot(File levelRoot, File dimensionRoot) {
Path dimensionsPath = Objects.requireNonNull(levelRoot, "levelRoot")
.toPath()
.toAbsolutePath()
.normalize()
.resolve("dimensions");
Path worldPath = Objects.requireNonNull(dimensionRoot, "dimensionRoot")
.toPath()
.toAbsolutePath()
.normalize();
if (!worldPath.startsWith(dimensionsPath)) {
return Optional.empty();
}
Path relative = dimensionsPath.relativize(worldPath);
if (relative.getNameCount() < 2) {
return Optional.empty();
}
String namespace = relative.getName(0).toString();
StringBuilder key = new StringBuilder();
for (int i = 1; i < relative.getNameCount(); i++) {
if (!key.isEmpty()) {
key.append('/');
}
key.append(relative.getName(i));
}
return Optional.ofNullable(NamespacedKey.fromString(namespace + ":" + key));
}
public static File packRoot(NamespacedKey key) {
return new File(dimensionRoot(key), "iris/pack");
}
}
@@ -1,16 +1,20 @@
package art.arcane.iris.core;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.core.service.StudioSVC;
import art.arcane.iris.engine.data.cache.AtomicCache;
import art.arcane.iris.engine.object.IrisDimension;
import art.arcane.iris.spi.IrisLogging;
import art.arcane.iris.spi.IrisPlatforms;
import art.arcane.iris.spi.IrisServices;
import art.arcane.iris.util.common.misc.ServerProperties;
import art.arcane.iris.util.common.plugin.VolmitSender;
import art.arcane.volmlib.util.bukkit.WorldIdentity;
import art.arcane.volmlib.util.collection.KMap;
import art.arcane.volmlib.util.io.IO;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import art.arcane.iris.spi.IrisLogging;
import art.arcane.iris.spi.IrisPlatforms;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.engine.data.cache.AtomicCache;
import art.arcane.iris.engine.object.IrisDimension;
import art.arcane.volmlib.util.collection.KMap;
import art.arcane.volmlib.util.io.IO;
import art.arcane.iris.util.common.misc.ServerProperties;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
@@ -30,8 +34,15 @@ public class IrisWorlds {
private volatile boolean dirty = false;
private IrisWorlds(KMap<String, String> worlds) {
this.worlds = worlds;
readBukkitWorlds().forEach(this::put0);
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));
save();
}
@@ -56,20 +67,23 @@ public class IrisWorlds {
});
}
public void put(String name, String type) {
put0(name, type);
public void put(String identity, String type) {
put0(identity, type);
save();
}
private void put0(String name, String type) {
String old = worlds.put(name, type);
private void put0(String identity, String type) {
String canonicalIdentity = WorldIdentity.parse(identity).toString();
String old = worlds.put(canonicalIdentity, type);
if (!type.equals(old))
dirty = true;
}
public KMap<String, String> getWorlds() {
clean();
return readBukkitWorlds().put(worlds);
KMap<String, String> result = new KMap<>();
readBukkitWorlds().forEach((name, type) -> result.put(IrisWorldStorage.keyFromLegacyName(name).toString(), type));
return result.put(worlds);
}
public Stream<IrisData> getPacks() {
@@ -87,7 +101,15 @@ public class IrisWorlds {
}
public void clean() {
dirty = worlds.entrySet().removeIf(entry -> !new File(Bukkit.getWorldContainer(), entry.getKey() + "/iris/pack/dimensions/" + entry.getValue() + ".json").exists());
boolean removed = worlds.entrySet().removeIf(entry -> {
try {
File packRoot = IrisWorldStorage.packRoot(WorldIdentity.parse(entry.getKey()));
return !new File(packRoot, "dimensions/" + entry.getValue() + ".json").exists();
} catch (IllegalArgumentException e) {
return true;
}
});
dirty = dirty || removed;
}
public synchronized void save() {
@@ -114,13 +136,13 @@ public class IrisWorlds {
}
public static KMap<String, String> readBukkitWorlds() {
var bukkit = YamlConfiguration.loadConfiguration(ServerProperties.BUKKIT_YML);
var worlds = bukkit.getConfigurationSection("worlds");
YamlConfiguration bukkit = YamlConfiguration.loadConfiguration(ServerProperties.BUKKIT_YML);
ConfigurationSection worlds = bukkit.getConfigurationSection("worlds");
if (worlds == null) return new KMap<>();
var result = new KMap<String, String>();
KMap<String, String> result = new KMap<>();
for (String world : worlds.getKeys(false)) {
var gen = worlds.getString(world + ".generator");
String gen = worlds.getString(world + ".generator");
if (gen == null) continue;
String loadKey;
@@ -136,20 +158,28 @@ public class IrisWorlds {
return result;
}
private static art.arcane.iris.engine.object.IrisDimension loadDimension(String worldName, String id) {
java.io.File pack = new java.io.File(org.bukkit.Bukkit.getWorldContainer(), String.join(java.io.File.separator, worldName, "iris", "pack"));
art.arcane.iris.engine.object.IrisDimension dimension = pack.isDirectory() ? art.arcane.iris.core.loader.IrisData.get(pack).getDimensionLoader().load(id) : null;
private static IrisDimension loadDimension(String worldIdentity, String id) {
File pack = IrisWorldStorage.packRoot(WorldIdentity.parse(worldIdentity));
IrisDimension dimension = pack.isDirectory() ? IrisData.get(pack).getDimensionLoader().load(id) : null;
if (dimension == null) {
dimension = art.arcane.iris.core.loader.IrisData.loadAnyDimension(id, null);
dimension = IrisData.loadAnyDimension(id, null);
}
if (dimension == null) {
IrisLogging.warn("Unable to find dimension type " + id + " Looking for online packs...");
art.arcane.iris.spi.IrisServices.get(art.arcane.iris.core.service.StudioSVC.class).downloadSearch(new art.arcane.iris.util.common.plugin.VolmitSender(org.bukkit.Bukkit.getConsoleSender()), id, false);
dimension = art.arcane.iris.core.loader.IrisData.loadAnyDimension(id, null);
IrisServices.get(StudioSVC.class).downloadSearch(new VolmitSender(Bukkit.getConsoleSender()), id, false);
dimension = IrisData.loadAnyDimension(id, null);
if (dimension != null) {
IrisLogging.info("Resolved missing dimension, proceeding.");
}
}
return dimension;
}
private static String migrateLoadedIdentity(String identity) {
try {
return WorldIdentity.parse(identity).toString();
} catch (IllegalArgumentException e) {
return IrisWorldStorage.keyFromLegacyName(identity).toString();
}
}
}
@@ -36,6 +36,7 @@ import art.arcane.iris.util.common.plugin.VolmitSender;
import art.arcane.iris.util.common.scheduling.J;
import lombok.NonNull;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
@@ -46,6 +47,7 @@ import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
@@ -58,8 +60,6 @@ import java.util.concurrent.atomic.AtomicIntegerArray;
import java.util.stream.Stream;
public class ServerConfigurator {
private static volatile boolean deferredInstallPending = false;
public static void configure() {
IrisSettings.IrisSettingsAutoconfiguration s = IrisSettings.get().getAutoConfiguration();
if (s.isConfigureSpigotTimeoutTime()) {
@@ -70,26 +70,9 @@ public class ServerConfigurator {
J.attempt(ServerConfigurator::increasePaperWatchdog);
}
if (shouldDeferInstallUntilWorldsReady()) {
deferredInstallPending = true;
return;
}
deferredInstallPending = false;
installDataPacks(true);
}
public static void configureIfDeferred() {
if (!deferredInstallPending) {
return;
}
configure();
if (deferredInstallPending) {
J.a(ServerConfigurator::configureIfDeferred, 20);
}
}
private static void increaseKeepAliveSpigot() throws IOException, InvalidConfigurationException {
File spigotConfig = new File("spigot.yml");
FileConfiguration f = new YamlConfiguration();
@@ -122,20 +105,7 @@ public class ServerConfigurator {
}
public static KList<File> getDatapacksFolder() {
if (!IrisSettings.get().getGeneral().forceMainWorld.isEmpty()) {
return new KList<File>().qadd(new File(Bukkit.getWorldContainer(), IrisSettings.get().getGeneral().forceMainWorld + "/datapacks"));
}
KList<File> worlds = new KList<>();
Bukkit.getServer().getWorlds().forEach(w -> {
File folder = resolveDatapacksFolder(w.getWorldFolder());
if (!worlds.contains(folder)) {
worlds.add(folder);
}
});
if (worlds.isEmpty()) {
worlds.add(new File(Bukkit.getWorldContainer(), ServerProperties.LEVEL_NAME + "/datapacks"));
}
return worlds;
return new KList<File>().qadd(new File(IrisWorldStorage.levelRoot(), "datapacks"));
}
public static boolean installDataPacks(boolean fullInstall) {
@@ -250,15 +220,6 @@ public class ServerConfigurator {
}
}
private static boolean shouldDeferInstallUntilWorldsReady() {
String forcedMainWorld = IrisSettings.get().getGeneral().forceMainWorld;
if (forcedMainWorld != null && !forcedMainWorld.isBlank()) {
return false;
}
return Bukkit.getServer().getWorlds().isEmpty();
}
public static File resolveDatapacksFolder(File worldFolder) {
File rootFolder = resolveWorldRootFolder(worldFolder);
return new File(rootFolder, "datapacks");
@@ -266,22 +227,9 @@ public class ServerConfigurator {
static File resolveWorldRootFolder(File worldFolder) {
if (worldFolder == null) {
return new File(Bukkit.getWorldContainer(), ServerProperties.LEVEL_NAME);
return IrisWorldStorage.levelRoot();
}
File current = worldFolder.getAbsoluteFile();
while (current != null) {
if ("dimensions".equals(current.getName())) {
File parent = current.getParentFile();
if (parent != null) {
return parent;
}
break;
}
current = current.getParentFile();
}
return worldFolder.getAbsoluteFile();
return IrisWorldStorage.levelRoot(worldFolder);
}
private static boolean verifyDataPacksPost(boolean allowRestarting) {
@@ -401,13 +349,19 @@ public class ServerConfigurator {
@Nullable
public static String getWorld(@NonNull IrisData data) {
String worldContainer = Bukkit.getWorldContainer().getAbsolutePath();
if (!worldContainer.endsWith(File.separator)) worldContainer += File.separator;
Path packPath = data.getDataFolder().toPath().toAbsolutePath().normalize();
Path irisPath = packPath.getParent();
if (irisPath == null || !"pack".equals(packPath.getFileName().toString()) || !"iris".equals(irisPath.getFileName().toString())) {
return null;
}
String path = data.getDataFolder().getAbsolutePath();
if (!path.startsWith(worldContainer)) return null;
int l = path.endsWith(File.separator) ? 11 : 10;
return path.substring(worldContainer.length(), path.length() - l);
Path dimensionPath = irisPath.getParent();
if (dimensionPath == null) {
return null;
}
File dimensionRoot = dimensionPath.toFile();
NamespacedKey key = IrisWorldStorage.keyFromDimensionRoot(IrisWorldStorage.levelRoot(), dimensionRoot).orElse(null);
return key == null ? null : key.toString();
}
public static class DimensionHeight {
@@ -36,6 +36,8 @@ import art.arcane.volmlib.util.mantle.runtime.Mantle;
import art.arcane.volmlib.util.math.Position2;
import art.arcane.volmlib.util.scheduling.ChronoLatch;
import art.arcane.iris.util.common.scheduling.J;
import art.arcane.volmlib.util.bukkit.WorldIdentity;
import org.bukkit.generator.WorldInfo;
import java.awt.Color;
import java.util.concurrent.ExecutorService;
@@ -216,13 +218,20 @@ public class PregeneratorJob implements PregenListener, PregenRenderSource {
return engine.getWorld().name();
}
public boolean targetsWorldName(String worldName) {
if (worldName == null || engine == null || engine.getWorld() == null) {
public boolean targetsWorld(WorldInfo world) {
if (world == null || engine == null || engine.getWorld() == null) {
return false;
}
String targetName = engine.getWorld().name();
return targetName != null && targetName.equalsIgnoreCase(worldName);
return WorldIdentity.key(world).equals(engine.getWorld().key());
}
public boolean targetsWorldIdentity(String worldIdentity) {
if (worldIdentity == null || engine == null || engine.getWorld() == null) {
return false;
}
return worldIdentity.equals(engine.getWorld().identity());
}
private static Color parseColor(String c) {
@@ -1,7 +1,7 @@
package art.arcane.iris.core.lifecycle;
import art.arcane.iris.core.nms.INMS;
import org.bukkit.Bukkit;
import art.arcane.volmlib.util.bukkit.WorldIdentity;
import org.bukkit.World;
import org.bukkit.WorldCreator;
@@ -21,7 +21,7 @@ final class BukkitPublicBackend implements WorldLifecycleBackend {
@Override
public CompletableFuture<World> create(WorldLifecycleRequest request) {
World existing = Bukkit.getWorld(request.worldName());
World existing = WorldIdentity.resolve(request.worldKey()).orElse(null);
if (existing != null) {
return CompletableFuture.completedFuture(existing);
}
@@ -1,7 +1,7 @@
package art.arcane.iris.core.lifecycle;
import art.arcane.iris.spi.IrisLogging;
import org.bukkit.Bukkit;
import art.arcane.volmlib.util.bukkit.WorldIdentity;
import org.bukkit.World;
import java.util.Locale;
@@ -31,7 +31,7 @@ final class PaperLikeRuntimeBackend implements WorldLifecycleBackend {
public CompletableFuture<World> create(WorldLifecycleRequest request) {
Object legacyStorageAccess = null;
try {
World existing = Bukkit.getWorld(request.worldName());
World existing = WorldIdentity.resolve(request.worldKey()).orElse(null);
if (existing != null) {
return CompletableFuture.completedFuture(existing);
}
@@ -47,7 +47,7 @@ final class PaperLikeRuntimeBackend implements WorldLifecycleBackend {
+ ", backend=paper_like_runtime, flavor=" + capabilities.paperLikeFlavor().name().toLowerCase(Locale.ROOT)
+ ", registrySource=" + WorldLifecycleSupport.runtimeLevelStemRegistrySource(request));
Object levelStem = WorldLifecycleSupport.resolveRuntimeLevelStem(capabilities, request);
Object stemKey = WorldLifecycleSupport.createRuntimeLevelStemKey(request.worldName());
Object stemKey = WorldLifecycleSupport.createRuntimeLevelStemKey(request.worldKey());
if (capabilities.paperLikeFlavor() == CapabilitySnapshot.PaperLikeFlavor.CURRENT_INFO_AND_DATA) {
Object dimensionKey = WorldLifecycleSupport.createDimensionKey(stemKey);
@@ -55,18 +55,18 @@ final class PaperLikeRuntimeBackend implements WorldLifecycleBackend {
Object worldLoadingInfo = capabilities.worldLoadingInfoConstructor().newInstance(request.environment(), stemKey, dimensionKey, !request.studio());
Object worldLoadingInfoAndData = capabilities.worldLoadingInfoAndDataConstructor().newInstance(worldLoadingInfo, loadedWorldData);
Object worldDataAndGenSettings = WorldLifecycleSupport.createCurrentWorldDataAndSettings(capabilities, request.worldName());
if (!WorldLifecycleSupport.hasExistingWorldData(request.worldName())) {
if (!WorldLifecycleSupport.hasExistingWorldData(request.worldKey())) {
worldDataAndGenSettings = WorldLifecycleSupport.applySeedToWorldDataAndGenSettings(worldDataAndGenSettings, request.seed());
}
capabilities.createLevelMethod().invoke(capabilities.minecraftServer(), levelStem, worldLoadingInfoAndData, worldDataAndGenSettings);
} else {
legacyStorageAccess = WorldLifecycleSupport.createLegacyStorageAccess(capabilities, request.worldName());
legacyStorageAccess = WorldLifecycleSupport.createLegacyStorageAccess(capabilities);
Object primaryLevelData = WorldLifecycleSupport.createLegacyPrimaryLevelData(capabilities, legacyStorageAccess, request.worldName());
Object worldLoadingInfo = capabilities.worldLoadingInfoConstructor().newInstance(0, request.worldName(), request.environment().name().toLowerCase(Locale.ROOT), stemKey, !request.studio());
capabilities.createLevelMethod().invoke(capabilities.minecraftServer(), levelStem, worldLoadingInfo, legacyStorageAccess, primaryLevelData);
}
World loadedWorld = Bukkit.getWorld(request.worldName());
World loadedWorld = WorldIdentity.resolve(request.worldKey()).orElse(null);
if (loadedWorld == null) {
return CompletableFuture.failedFuture(new IllegalStateException("Paper-like runtime backend did not load world \"" + request.worldName() + "\"."));
}
@@ -1,5 +1,6 @@
package art.arcane.iris.core.lifecycle;
import org.bukkit.NamespacedKey;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.WorldType;
@@ -8,6 +9,7 @@ import org.bukkit.generator.ChunkGenerator;
public record WorldLifecycleRequest(
String worldName,
NamespacedKey worldKey,
World.Environment environment,
ChunkGenerator generator,
BiomeProvider biomeProvider,
@@ -22,6 +24,7 @@ public record WorldLifecycleRequest(
public static WorldLifecycleRequest fromCreator(WorldCreator creator, boolean studio, boolean benchmark, WorldLifecycleCaller callerKind) {
return new WorldLifecycleRequest(
creator.name(),
creator.key(),
creator.environment(),
creator.generator(),
creator.biomeProvider(),
@@ -36,7 +39,7 @@ public record WorldLifecycleRequest(
}
public WorldCreator toWorldCreator() {
WorldCreator creator = new WorldCreator(worldName)
WorldCreator creator = WorldCreator.ofKey(worldKey)
.environment(environment)
.generateStructures(generateStructures)
.hardcore(hardcore)
@@ -2,6 +2,8 @@ package art.arcane.iris.core.lifecycle;
import art.arcane.iris.spi.IrisLogging;
import art.arcane.iris.util.common.scheduling.J;
import art.arcane.volmlib.util.bukkit.WorldIdentity;
import org.bukkit.NamespacedKey;
import org.bukkit.World;
import java.util.List;
@@ -18,7 +20,7 @@ public final class WorldLifecycleService {
private final PaperLikeRuntimeBackend paperLikeRuntimeBackend;
private final BukkitPublicBackend bukkitPublicBackend;
private final List<WorldLifecycleBackend> backends;
private final Map<String, String> worldBackendByName;
private final Map<String, String> worldBackendByKey;
public WorldLifecycleService(CapabilitySnapshot capabilities) {
this.capabilities = capabilities;
@@ -26,7 +28,7 @@ public final class WorldLifecycleService {
this.paperLikeRuntimeBackend = new PaperLikeRuntimeBackend(capabilities);
this.bukkitPublicBackend = new BukkitPublicBackend(capabilities);
this.backends = List.of(worldsProviderBackend, paperLikeRuntimeBackend, bukkitPublicBackend);
this.worldBackendByName = new ConcurrentHashMap<>();
this.worldBackendByKey = new ConcurrentHashMap<>();
}
public static WorldLifecycleService get() {
@@ -74,7 +76,7 @@ public final class WorldLifecycleService {
return;
}
if (world != null) {
worldBackendByName.put(world.getName(), backend.backendName());
worldBackendByKey.put(WorldIdentity.serialize(world), backend.backendName());
}
});
}
@@ -104,7 +106,8 @@ public final class WorldLifecycleService {
}
private boolean unloadDirect(World world, boolean save) {
WorldLifecycleBackend backend = selectUnloadBackend(world.getName());
String worldIdentity = WorldIdentity.serialize(world);
WorldLifecycleBackend backend = selectUnloadBackend(worldIdentity);
IrisLogging.info("WorldLifecycle unload: world=%s, backend=%s",
world.getName(),
backend.backendName());
@@ -124,13 +127,13 @@ public final class WorldLifecycleService {
throw new IllegalStateException(e);
}
if (unloaded) {
worldBackendByName.remove(world.getName());
worldBackendByKey.remove(worldIdentity);
}
return unloaded;
}
public String backendNameForWorld(String worldName) {
return selectUnloadBackend(worldName).backendName();
public String backendNameForWorld(NamespacedKey worldKey) {
return selectUnloadBackend(worldKey.toString()).backendName();
}
WorldLifecycleBackend selectCreateBackend(WorldLifecycleRequest request) {
@@ -155,8 +158,8 @@ public final class WorldLifecycleService {
throw new IllegalStateException("No world lifecycle backend supports request for \"" + request.worldName() + "\".");
}
WorldLifecycleBackend selectUnloadBackend(String worldName) {
String backendName = worldBackendByName.get(worldName);
WorldLifecycleBackend selectUnloadBackend(String worldIdentity) {
String backendName = worldBackendByKey.get(worldIdentity);
if (backendName == null) {
return bukkitPublicBackend;
}
@@ -170,7 +173,7 @@ public final class WorldLifecycleService {
return bukkitPublicBackend;
}
void rememberBackend(String worldName, String backendName) {
worldBackendByName.put(worldName, backendName);
void rememberBackend(NamespacedKey worldKey, String backendName) {
worldBackendByKey.put(worldKey.toString(), backendName);
}
}
@@ -1,12 +1,15 @@
package art.arcane.iris.core.lifecycle;
import art.arcane.iris.core.IrisWorldStorage;
import art.arcane.iris.core.link.Identifier;
import art.arcane.iris.core.nms.INMS;
import art.arcane.iris.core.nms.INMSBinding;
import art.arcane.iris.engine.platform.PlatformChunkGenerator;
import art.arcane.iris.util.common.scheduling.J;
import art.arcane.volmlib.util.bukkit.WorldIdentity;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.NamespacedKey;
import org.bukkit.World;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
@@ -18,7 +21,6 @@ import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.file.Path;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.OptionalLong;
@@ -119,10 +121,8 @@ final class WorldLifecycleSupport {
return lookupMethod.invoke(datapackDimensions, levelStemRegistryKey);
}
static Object createRuntimeLevelStemKey(String worldName) throws ReflectiveOperationException {
String sanitized = worldName.toLowerCase(Locale.ROOT).replaceAll("[^a-z0-9/_-]", "_");
String path = "runtime/" + sanitized;
Identifier identifier = new Identifier("iris", path);
static Object createRuntimeLevelStemKey(NamespacedKey worldKey) throws ReflectiveOperationException {
Identifier identifier = new Identifier(worldKey.getNamespace(), worldKey.getKey());
Object rawIdentifier = Class.forName("net.minecraft.resources.Identifier")
.getMethod("fromNamespaceAndPath", String.class, String.class)
.invoke(null, identifier.namespace(), identifier.key());
@@ -253,11 +253,13 @@ final class WorldLifecycleSupport {
setModdedInfoMethod.invoke(worldData, modName, modified);
}
static boolean hasExistingWorldData(String worldName) {
File worldFolder = new File(Bukkit.getWorldContainer(), worldName);
return new File(worldFolder, "level.dat").exists()
|| new File(worldFolder, "region").exists()
|| new File(worldFolder, "data").exists();
static boolean hasExistingWorldData(NamespacedKey worldKey) {
File worldFolder = IrisWorldStorage.dimensionRoot(worldKey);
return new File(worldFolder, "region").exists()
|| new File(worldFolder, "entities").exists()
|| new File(worldFolder, "poi").exists()
|| new File(worldFolder, "data/paper/metadata.dat").exists()
|| new File(worldFolder, "paper-world.yml").exists();
}
static Object applySeedToWorldDataAndGenSettings(Object worldDataAndGenSettings, long seed) throws ReflectiveOperationException {
@@ -386,18 +388,19 @@ final class WorldLifecycleSupport {
return primaryLevelData;
}
static Object createLegacyStorageAccess(CapabilitySnapshot capabilities, String worldName) throws ReflectiveOperationException {
static Object createLegacyStorageAccess(CapabilitySnapshot capabilities) throws ReflectiveOperationException {
Class<?> levelStorageSourceClass = Class.forName("net.minecraft.world.level.storage.LevelStorageSource");
Method createDefaultMethod = levelStorageSourceClass.getMethod("createDefault", Path.class);
Object levelStorageSource = createDefaultMethod.invoke(null, Bukkit.getWorldContainer().toPath());
File levelRoot = IrisWorldStorage.levelRoot();
Object levelStorageSource = createDefaultMethod.invoke(null, levelRoot.getParentFile().toPath());
Method storageAccessMethod = capabilities.levelStorageAccessMethod();
if (storageAccessMethod.getParameterCount() == 1) {
return storageAccessMethod.invoke(levelStorageSource, worldName);
return storageAccessMethod.invoke(levelStorageSource, levelRoot.getName());
}
Object overworldStemKey = Class.forName("net.minecraft.world.level.dimension.LevelStem")
.getField("OVERWORLD")
.get(null);
return storageAccessMethod.invoke(levelStorageSource, worldName, overworldStemKey);
return storageAccessMethod.invoke(levelStorageSource, levelRoot.getName(), overworldStemKey);
}
static void closeLevelStorageAccess(Object levelStorageAccess) {
@@ -437,8 +440,8 @@ final class WorldLifecycleSupport {
Method getHandleMethod = world.getClass().getMethod("getHandle");
Object serverLevel = getHandleMethod.invoke(world);
closeServerLevel(world, serverLevel);
detachServerLevel(capabilities, serverLevel, world.getName());
return Bukkit.getWorld(world.getName()) == null;
detachServerLevel(capabilities, serverLevel, world);
return WorldIdentity.resolve(WorldIdentity.key(world)).isEmpty();
} catch (Throwable e) {
throw new IllegalStateException("Failed to unload world \"" + world.getName() + "\" through the selected world lifecycle backend.", unwrap(e));
}
@@ -527,7 +530,7 @@ final class WorldLifecycleSupport {
}
@SuppressWarnings({"rawtypes", "unchecked"})
private static void removeWorldFromCraftServerMap(String worldName) throws ReflectiveOperationException {
private static void removeWorldFromCraftServerMap(World world) throws ReflectiveOperationException {
Object bukkitServer = Bukkit.getServer();
if (bukkitServer == null) {
return;
@@ -536,16 +539,17 @@ final class WorldLifecycleSupport {
Field worldsField = CapabilityResolution.resolveField(bukkitServer.getClass(), "worlds");
Object rawWorlds = worldsField.get(bukkitServer);
if (rawWorlds instanceof Map map) {
map.remove(worldName);
map.remove(worldName.toLowerCase(Locale.ROOT));
map.remove(WorldIdentity.key(world));
map.remove(WorldIdentity.serialize(world));
map.remove(world.getName());
}
}
private static void detachServerLevel(CapabilitySnapshot capabilities, Object serverLevel, String worldName) throws Throwable {
private static void detachServerLevel(CapabilitySnapshot capabilities, Object serverLevel, World world) throws Throwable {
Runnable detachTask = () -> {
try {
capabilities.removeLevelMethod().invoke(capabilities.minecraftServer(), serverLevel);
removeWorldFromCraftServerMap(worldName);
removeWorldFromCraftServerMap(world);
} catch (Throwable e) {
throw new RuntimeException(e);
}
@@ -558,7 +562,7 @@ final class WorldLifecycleSupport {
CompletableFuture<Void> detachFuture = J.sfut(detachTask);
if (detachFuture == null) {
throw new IllegalStateException("Failed to schedule global detach task for world \"" + worldName + "\".");
throw new IllegalStateException("Failed to schedule global detach task for world \"" + world.getName() + "\".");
}
detachFuture.get(15, TimeUnit.SECONDS);
}
@@ -1,10 +1,9 @@
package art.arcane.iris.core.lifecycle;
import org.bukkit.Bukkit;
import art.arcane.iris.core.IrisWorldStorage;
import org.bukkit.World;
import org.bukkit.WorldType;
import java.io.File;
import java.nio.file.Path;
import java.util.Locale;
import java.util.concurrent.CompletableFuture;
@@ -25,7 +24,7 @@ final class WorldsProviderBackend implements WorldLifecycleBackend {
@SuppressWarnings("unchecked")
public CompletableFuture<World> create(WorldLifecycleRequest request) {
try {
Path worldPath = new File(Bukkit.getWorldContainer(), request.worldName()).toPath();
Path worldPath = IrisWorldStorage.dimensionRoot(request.worldKey()).toPath();
Object builder = WorldLifecycleSupport.invokeNamed(capabilities.worldsProvider(), "levelBuilder", new Class[]{Path.class}, worldPath);
builder = WorldLifecycleSupport.invokeNamed(builder, "name", new Class[]{String.class}, request.worldName());
builder = WorldLifecycleSupport.invokeNamed(builder, "seed", new Class[]{long.class}, request.seed());
@@ -1,5 +1,6 @@
package art.arcane.iris.core.runtime;
import art.arcane.iris.core.IrisWorldStorage;
import art.arcane.iris.spi.IrisLogging;
import art.arcane.iris.spi.IrisServices;
import art.arcane.iris.core.lifecycle.WorldLifecycleService;
@@ -10,6 +11,7 @@ import art.arcane.iris.engine.platform.PlatformChunkGenerator;
import art.arcane.iris.util.common.plugin.VolmitSender;
import art.arcane.iris.util.common.scheduling.J;
import art.arcane.volmlib.util.exceptions.IrisException;
import art.arcane.volmlib.util.bukkit.WorldIdentity;
import art.arcane.volmlib.util.io.IO;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@@ -327,7 +329,7 @@ public final class StudioOpenCoordinator {
}
for (String familyWorldName : TransientWorldCleanupSupport.worldFamilyNames(worldName)) {
World familyWorld = Bukkit.getWorld(familyWorldName);
World familyWorld = WorldIdentity.resolve(IrisWorldStorage.keyFromLegacyName(familyWorldName)).orElse(null);
if (familyWorld == null) {
continue;
}
@@ -342,10 +344,9 @@ public final class StudioOpenCoordinator {
return new WorldFamilyDeleteResult(true, false);
}
File container = Bukkit.getWorldContainer();
boolean liveDeleted = true;
for (String familyWorldName : TransientWorldCleanupSupport.worldFamilyNames(worldName)) {
File folder = new File(container, familyWorldName);
File folder = IrisWorldStorage.dimensionRoot(familyWorldName);
if (!folder.exists()) {
continue;
}
@@ -378,15 +379,14 @@ public final class StudioOpenCoordinator {
}
private void cleanupStaleTransientWorlds(String worldName) {
File container = Bukkit.getWorldContainer();
LinkedHashSet<String> staleWorldNames = TransientWorldCleanupSupport.collectTransientStudioWorldNames(container);
LinkedHashSet<String> staleWorldNames = TransientWorldCleanupSupport.collectTransientStudioWorldNames(IrisWorldStorage.levelRoot());
String requestedBaseName = TransientWorldCleanupSupport.transientStudioBaseWorldName(worldName);
if (requestedBaseName != null) {
staleWorldNames.add(requestedBaseName);
}
for (String staleWorldName : staleWorldNames) {
if (Bukkit.getWorld(staleWorldName) != null) {
if (WorldIdentity.resolve(IrisWorldStorage.keyFromLegacyName(staleWorldName)).isPresent()) {
continue;
}
@@ -480,7 +480,7 @@ public final class StudioOpenCoordinator {
}
for (String familyWorldName : TransientWorldCleanupSupport.worldFamilyNames(worldName)) {
if (Bukkit.getWorld(familyWorldName) != null) {
if (WorldIdentity.resolve(IrisWorldStorage.keyFromLegacyName(familyWorldName)).isPresent()) {
return true;
}
}
@@ -49,31 +49,38 @@ public final class TransientWorldCleanupSupport {
return names;
}
public static LinkedHashSet<String> collectTransientStudioWorldNames(File worldContainer) {
public static LinkedHashSet<String> collectTransientStudioWorldNames(File levelRoot) {
LinkedHashSet<String> names = new LinkedHashSet<>();
if (worldContainer == null) {
if (levelRoot == null) {
return names;
}
File[] children = worldContainer.listFiles();
if (children == null) {
File namespacesRoot = new File(levelRoot, "dimensions");
File[] namespaces = namespacesRoot.listFiles(File::isDirectory);
if (namespaces == null) {
return names;
}
for (File namespace : namespaces) {
collectTransientStudioWorldNames(namespace, names);
}
return names;
}
private static void collectTransientStudioWorldNames(File folder, LinkedHashSet<String> names) {
File[] children = folder.listFiles(File::isDirectory);
if (children == null) {
return;
}
for (File child : children) {
if (child == null || !child.isDirectory()) {
continue;
}
String baseName = transientStudioBaseWorldName(child.getName());
if (baseName == null) {
if (baseName != null) {
names.add(baseName);
continue;
}
names.add(baseName);
collectTransientStudioWorldNames(child, names);
}
return names;
}
private static String normalizeWorldName(String worldName) {
@@ -3,6 +3,7 @@ package art.arcane.iris.core.safeguard.task;
import art.arcane.iris.BuildConstants;
import art.arcane.iris.platform.bukkit.BukkitPlatform;
import art.arcane.iris.core.IrisWorlds;
import art.arcane.iris.core.IrisWorldStorage;
import art.arcane.iris.core.nms.INMS;
import art.arcane.iris.core.nms.v1X.NMSBinding1X;
import art.arcane.iris.core.safeguard.Mode;
@@ -137,7 +138,7 @@ public final class Tasks {
});
private static final Task DISK_SPACE = Task.of("diskSpace", () -> {
double freeGiB = server().getWorldContainer().getFreeSpace() / (double) 0x4000_0000;
double freeGiB = IrisWorldStorage.levelRoot().getFreeSpace() / (double) 0x4000_0000;
if (freeGiB > 3.0) {
return withDiagnostics(Mode.STABLE);
}
@@ -1,8 +1,10 @@
package art.arcane.iris.core.service;
import art.arcane.iris.core.IrisSettings;
import art.arcane.iris.core.IrisWorldStorage;
import art.arcane.iris.core.pregenerator.cache.PregenCache;
import art.arcane.iris.core.tools.IrisToolbelt;
import art.arcane.volmlib.util.bukkit.WorldIdentity;
import art.arcane.volmlib.util.collection.KMap;
import art.arcane.iris.util.common.plugin.IrisService;
import art.arcane.volmlib.util.scheduling.Looper;
@@ -64,7 +66,7 @@ public class GlobalCacheSVC implements IrisService {
@Nullable
public PregenCache get(@NonNull World world) {
return globalCache.get(world.getName());
return globalCache.get(WorldIdentity.serialize(world));
}
@Nullable
@@ -80,7 +82,7 @@ public class GlobalCacheSVC implements IrisService {
@EventHandler(priority = EventPriority.MONITOR)
public void on(WorldUnloadEvent event) {
var cache = globalCache.remove(event.getWorld().getName());
PregenCache cache = globalCache.remove(WorldIdentity.serialize(event.getWorld()));
if (cache == null) return;
cache.write();
}
@@ -94,7 +96,8 @@ public class GlobalCacheSVC implements IrisService {
private void createCache(World world) {
if (!IrisToolbelt.isIrisWorld(world)) return;
globalCache.computeIfAbsent(world.getName(), GlobalCacheSVC::createDefault);
String worldIdentity = WorldIdentity.serialize(world);
globalCache.computeIfAbsent(worldIdentity, GlobalCacheSVC::createDefault);
}
private boolean isDisabled() {
@@ -116,25 +119,26 @@ public class GlobalCacheSVC implements IrisService {
@NonNull
public static PregenCache createCache(@NonNull String worldName, @NonNull Function<String, PregenCache> provider) {
public static PregenCache createCache(@NonNull String worldIdentity, @NonNull Function<String, PregenCache> provider) {
PregenCache[] holder = new PregenCache[1];
REFERENCE_CACHE.compute(worldName, (name, ref) -> {
REFERENCE_CACHE.compute(worldIdentity, (identity, ref) -> {
if (ref != null) {
if ((holder[0] = ref.get()) != null)
return ref;
}
return new WeakReference<>(holder[0] = provider.apply(worldName));
return new WeakReference<>(holder[0] = provider.apply(worldIdentity));
});
return holder[0];
}
@NonNull
public static PregenCache createDefault(@NonNull String worldName) {
return createCache(worldName, GlobalCacheSVC::createDefault0);
public static PregenCache createDefault(@NonNull String worldIdentity) {
return createCache(worldIdentity, GlobalCacheSVC::createDefault0);
}
private static PregenCache createDefault0(String worldName) {
private static PregenCache createDefault0(String worldIdentity) {
if (disabled) return PregenCache.EMPTY;
return PregenCache.create(new File(Bukkit.getWorldContainer(), String.join(File.separator, worldName, "iris", "pregen"))).sync();
File dimensionRoot = IrisWorldStorage.dimensionRoot(WorldIdentity.parse(worldIdentity));
return PregenCache.create(new File(dimensionRoot, "iris/pregen")).sync();
}
}
@@ -22,6 +22,7 @@ import com.google.gson.JsonSyntaxException;
import art.arcane.iris.spi.IrisLogging;
import art.arcane.iris.spi.IrisServices;
import art.arcane.iris.core.IrisSettings;
import art.arcane.iris.core.IrisWorldStorage;
import art.arcane.iris.core.ServerConfigurator;
import art.arcane.iris.core.lifecycle.WorldLifecycleService;
import art.arcane.iris.core.loader.IrisData;
@@ -86,7 +87,7 @@ public class StudioSVC implements IrisService {
public void onDisable() {
IrisLogging.debug("Studio Mode Active: Closing Projects");
boolean stopping = IrisToolbelt.isServerStopping();
LinkedHashSet<String> worldNamesToDelete = new LinkedHashSet<>(TransientWorldCleanupSupport.collectTransientStudioWorldNames(Bukkit.getWorldContainer()));
LinkedHashSet<String> worldNamesToDelete = new LinkedHashSet<>(TransientWorldCleanupSupport.collectTransientStudioWorldNames(IrisWorldStorage.levelRoot()));
if (activeProject != null) {
PlatformChunkGenerator activeProvider = activeProject.getActiveProvider();
@@ -425,9 +426,8 @@ public class StudioSVC implements IrisService {
return;
}
File container = Bukkit.getWorldContainer();
for (String familyWorldName : TransientWorldCleanupSupport.worldFamilyNames(worldName)) {
File folder = new File(container, familyWorldName);
File folder = IrisWorldStorage.dimensionRoot(familyWorldName);
if (!folder.exists()) {
continue;
}
@@ -18,6 +18,7 @@
package art.arcane.iris.core.structure;
import art.arcane.iris.core.IrisWorldStorage;
import art.arcane.iris.spi.IrisLogging;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.core.nms.INMS;
@@ -28,6 +29,7 @@ import art.arcane.iris.util.common.format.C;
import art.arcane.iris.util.common.plugin.VolmitSender;
import art.arcane.iris.util.common.scheduling.J;
import art.arcane.volmlib.util.collection.KList;
import art.arcane.volmlib.util.bukkit.WorldIdentity;
import art.arcane.volmlib.util.io.IO;
import org.bukkit.Bukkit;
import org.bukkit.Material;
@@ -293,11 +295,11 @@ public final class FeatureImporter {
static World createScratchWorld(VolmitSender sender) {
try {
World existing = Bukkit.getWorld(SCRATCH_WORLD_NAME);
World existing = WorldIdentity.resolve(IrisWorldStorage.keyFromLegacyName(SCRATCH_WORLD_NAME)).orElse(null);
if (existing != null) {
return existing;
}
WorldCreator creator = new WorldCreator(SCRATCH_WORLD_NAME)
WorldCreator creator = WorldCreator.ofKey(IrisWorldStorage.keyFromLegacyName(SCRATCH_WORLD_NAME))
.environment(World.Environment.NORMAL)
.type(WorldType.FLAT)
.generateStructures(false);
@@ -25,6 +25,7 @@ import art.arcane.iris.spi.IrisServices;
import art.arcane.iris.platform.bukkit.BukkitPlatform;
import art.arcane.iris.core.link.MultiverseCoreLink;
import art.arcane.iris.core.IrisRuntimeSchedulerMode;
import art.arcane.iris.core.IrisWorldStorage;
import art.arcane.iris.core.IrisWorlds;
import art.arcane.iris.core.IrisSettings;
import art.arcane.iris.core.ServerConfigurator;
@@ -50,7 +51,6 @@ import org.bukkit.WorldCreator;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.io.IOException;
import java.util.Locale;
import java.util.concurrent.CompletableFuture;
@@ -166,7 +166,7 @@ public class IrisCreator {
reportStudioProgress(0.16D, "prepare_world_pack");
if (!studio() || benchmark) {
d = IrisServices.get(StudioSVC.class).installIntoWorld(sender, d, new File(Bukkit.getWorldContainer(), name()));
d = IrisServices.get(StudioSVC.class).installIntoWorld(sender, d, IrisWorldStorage.dimensionRoot(name()));
if (d == null) {
throw new IrisException("Failed to install dimension pack for " + dimension());
}
@@ -188,7 +188,7 @@ public class IrisCreator {
.studio(studio)
.create();
if (!studio()) {
IrisWorlds.get().put(name(), dimension());
IrisWorlds.get().put(wc.key().toString(), dimension());
}
ServerConfigurator.installDataPacksIfChanged(!studio());
IrisLogging.debug("[Studio timing] create.packPrep + datapacks = " + (System.currentTimeMillis() - createStart) + "ms (cumulative in create)");
@@ -1,6 +1,7 @@
package art.arcane.iris.core.tools;
import art.arcane.iris.core.IrisWorldStorage;
import art.arcane.iris.spi.IrisLogging;
import art.arcane.iris.spi.IrisPlatforms;
import art.arcane.iris.core.lifecycle.WorldLifecycleService;
@@ -9,12 +10,13 @@ import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.object.IrisDimension;
import art.arcane.volmlib.util.collection.KList;
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.format.Form;
import art.arcane.volmlib.util.io.IO;
import art.arcane.iris.util.common.scheduling.J;
import art.arcane.volmlib.util.scheduling.PrecisionStopwatch;
import org.bukkit.Bukkit;
import org.bukkit.World;
import java.io.File;
import java.io.FileWriter;
@@ -47,9 +49,9 @@ public class IrisPackBenchmarking {
.name("PackBenchmarking")
.start(() -> {
IrisLogging.info("Setting up benchmark environment ");
IO.delete(new File(Bukkit.getWorldContainer(), "benchmark"));
IO.delete(IrisWorldStorage.dimensionRoot("benchmark"));
createBenchmark();
while (!IrisToolbelt.isIrisWorld(Bukkit.getWorld("benchmark"))) {
while (!IrisToolbelt.isIrisWorld(benchmarkWorld())) {
J.sleep(1000);
IrisLogging.debug("Iris PackBenchmark: Waiting...");
}
@@ -63,7 +65,11 @@ public class IrisPackBenchmarking {
public void finishedBenchmark(KList<Integer> cps) {
try {
String time = Form.duration((long) stopwatch.getMilliseconds());
Engine engine = IrisToolbelt.access(Bukkit.getWorld("benchmark")).getEngine();
World benchmarkWorld = benchmarkWorld();
if (benchmarkWorld == null) {
throw new IllegalStateException("Benchmark world is not loaded.");
}
Engine engine = IrisToolbelt.access(benchmarkWorld).getEngine();
IrisLogging.info("-----------------");
IrisLogging.info("Results:");
IrisLogging.info("- Total time: " + time);
@@ -101,7 +107,7 @@ public class IrisPackBenchmarking {
}
J.s(() -> {
org.bukkit.World world = Bukkit.getWorld("benchmark");
World world = benchmarkWorld();
if (world == null) return;
IrisToolbelt.evacuate(world);
WorldLifecycleService.get().unload(world, true);
@@ -136,13 +142,17 @@ public class IrisPackBenchmarking {
.gui(gui)
.radiusX(radius)
.radiusZ(radius)
.build(), Bukkit.getWorld("benchmark")
.build(), benchmarkWorld()
);
} finally {
instance.remove();
}
}
private static World benchmarkWorld() {
return WorldIdentity.resolve(IrisWorldStorage.keyFromLegacyName("benchmark")).orElse(null);
}
private double calculateAverage(KList<Integer> list) {
double sum = 0;
for (int num : list) {
@@ -37,10 +37,12 @@ import art.arcane.iris.core.service.GlobalCacheSVC;
import art.arcane.iris.core.service.StudioSVC;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.object.IrisDimension;
import art.arcane.iris.engine.object.IrisWorld;
import art.arcane.iris.engine.platform.BukkitChunkGenerator;
import art.arcane.iris.engine.platform.PlatformChunkGenerator;
import art.arcane.iris.util.common.scheduling.J;
import art.arcane.iris.util.common.plugin.VolmitSender;
import art.arcane.volmlib.util.bukkit.WorldIdentity;
import io.papermc.lib.PaperLib;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@@ -222,14 +224,14 @@ public class IrisToolbelt {
return ((PlatformChunkGenerator) world.getGenerator());
}
StudioSVC studioService = IrisServices.get(StudioSVC.class);
StudioSVC studioService = IrisServices.getOrNull(StudioSVC.class);
if (studioService != null && studioService.isProjectOpen()) {
IrisProject activeProject = studioService.getActiveProject();
if (activeProject != null) {
PlatformChunkGenerator activeProvider = activeProject.getActiveProvider();
if (activeProvider != null) {
World activeWorld = activeProvider.getTarget().getWorld().realWorld();
if (activeWorld != null && activeWorld.getName().equals(world.getName())) {
if (activeWorld != null && WorldIdentity.key(activeWorld).equals(WorldIdentity.key(world))) {
if (activeProvider instanceof BukkitChunkGenerator bukkit) {
bukkit.touch(world);
}
@@ -267,14 +269,18 @@ public class IrisToolbelt {
IrisRuntimeSchedulerMode runtimeSchedulerMode = IrisRuntimeSchedulerMode.resolve(IrisSettings.get().getPregen());
useCachedWrapper = runtimeSchedulerMode != IrisRuntimeSchedulerMode.FOLIA;
}
return new PregeneratorJob(task, useCachedWrapper ? new CachedPregenMethod(method, resolvePregenCache(engine.getWorld().name()), task) : method, engine);
return new PregeneratorJob(task, useCachedWrapper ? new CachedPregenMethod(method, resolvePregenCache(engine.getWorld()), task) : method, engine);
}
private static PregenCache resolvePregenCache(String worldName) {
PregenCache cache = IrisServices.get(GlobalCacheSVC.class).get(worldName);
private static PregenCache resolvePregenCache(IrisWorld world) {
String worldIdentity = world.key() == null ? null : world.key().toString();
if (worldIdentity == null) {
throw new IllegalStateException("Pregeneration requires a namespaced world identity.");
}
PregenCache cache = IrisServices.get(GlobalCacheSVC.class).get(worldIdentity);
if (cache == null) {
IrisLogging.debug("Could not find existing cache for " + worldName + " creating fallback");
cache = GlobalCacheSVC.createDefault(worldName);
IrisLogging.debug("Could not find existing cache for " + worldIdentity + " creating fallback");
cache = GlobalCacheSVC.createDefault(worldIdentity);
}
return cache;
}
@@ -351,7 +357,7 @@ public class IrisToolbelt {
}
for (World i : Bukkit.getWorlds()) {
if (!i.getName().equals(world.getName())) {
if (!WorldIdentity.key(i).equals(WorldIdentity.key(world))) {
for (Player j : new ArrayList<>(world.getPlayers())) {
new VolmitSender(j, BukkitPlatform.volmitPlugin().getTag()).sendMessage("You have been evacuated from this world.");
Location target = i.getSpawnLocation();
@@ -381,7 +387,7 @@ public class IrisToolbelt {
}
for (World i : Bukkit.getWorlds()) {
if (!i.getName().equals(world.getName())) {
if (!WorldIdentity.key(i).equals(WorldIdentity.key(world))) {
for (Player j : new ArrayList<>(world.getPlayers())) {
new VolmitSender(j, BukkitPlatform.volmitPlugin().getTag()).sendMessage("You have been evacuated from this world. " + m);
Location target = i.getSpawnLocation();
@@ -460,7 +466,7 @@ public class IrisToolbelt {
return;
}
beginWorldMaintenance(world.getName(), reason, bypassMantleStages);
beginWorldMaintenance(WorldIdentity.serialize(world), reason, bypassMantleStages);
}
public static void beginWorldMaintenance(String worldName, String reason) {
@@ -476,7 +482,7 @@ public class IrisToolbelt {
return;
}
endWorldMaintenance(world.getName(), reason);
endWorldMaintenance(WorldIdentity.serialize(world), reason);
}
public static void endWorldMaintenance(String worldName, String reason) {
@@ -484,7 +490,7 @@ public class IrisToolbelt {
}
public static boolean isWorldMaintenanceActive(World world) {
return world != null && isWorldMaintenanceActive(world.getName());
return world != null && isWorldMaintenanceActive(WorldIdentity.serialize(world));
}
public static boolean isWorldMaintenanceActive(String worldName) {
@@ -492,7 +498,7 @@ public class IrisToolbelt {
}
public static boolean isWorldMaintenanceBypassingMantleStages(World world) {
return world != null && isWorldMaintenanceBypassingMantleStages(world.getName());
return world != null && isWorldMaintenanceBypassingMantleStages(WorldIdentity.serialize(world));
}
public static boolean isWorldMaintenanceBypassingMantleStages(String worldName) {
@@ -18,11 +18,12 @@
package art.arcane.iris.core.tools;
import art.arcane.iris.core.IrisWorldStorage;
import art.arcane.iris.core.loader.IrisData;
import art.arcane.iris.engine.object.IrisDimension;
import art.arcane.iris.engine.object.IrisWorld;
import art.arcane.iris.engine.platform.BukkitChunkGenerator;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.generator.ChunkGenerator;
@@ -74,13 +75,15 @@ public class IrisWorldCreator {
public WorldCreator create() {
IrisDimension dim = dimension == null ? IrisData.loadAnyDimension(dimensionName, null) : dimension;
NamespacedKey worldKey = IrisWorldStorage.keyFromLegacyName(name);
IrisWorld w = IrisWorld.builder()
.key(worldKey)
.name(name)
.minHeight(dim.getMinHeight())
.maxHeight(dim.getMaxHeight())
.seed(seed)
.worldFolder(new File(Bukkit.getWorldContainer(), name))
.worldFolder(IrisWorldStorage.dimensionRoot(worldKey))
.environment(findEnvironment())
.build();
ChunkGenerator g = new BukkitChunkGenerator(w, studio, studio
@@ -88,7 +91,7 @@ public class IrisWorldCreator {
new File(w.worldFolder(), "iris/pack"), dimensionName);
return new WorldCreator(name)
return WorldCreator.ofKey(worldKey)
.environment(w.environment())
.generateStructures(true)
.generator(g).seed(seed);
@@ -650,7 +650,7 @@ public class IrisEngine implements Engine {
private boolean isPregeneratorActiveForThisWorld() {
PregeneratorJob pregeneratorJob = PregeneratorJob.getInstance();
return pregeneratorJob != null && pregeneratorJob.targetsWorldName(getWorld().name());
return pregeneratorJob != null && pregeneratorJob.targetsWorldIdentity(getWorld().identity());
}
private void savePrefetchOnce() {
@@ -574,7 +574,7 @@ public class IrisWorldManager extends EngineAssignedWorldManager {
return false;
}
return job.targetsWorldName(world.getName());
return job.targetsWorld(world);
}
private Position2[] getLoadedChunkPositionsSnapshot(World world) {
@@ -691,11 +691,11 @@ public interface Engine extends DataProvider, Fallible, LootProvider, BlockUpdat
if (world == null) {
return false;
}
String worldName = world.name();
if (!WorldMaintenance.isWorldMaintenanceActive(worldName)) {
String worldIdentity = world.identity();
if (!WorldMaintenance.isWorldMaintenanceActive(worldIdentity)) {
return false;
}
PregeneratorJob pregeneratorJob = PregeneratorJob.getInstance();
return pregeneratorJob == null || !pregeneratorJob.targetsWorldName(worldName);
return pregeneratorJob == null || !pregeneratorJob.targetsWorldIdentity(worldIdentity);
}
}
@@ -96,13 +96,13 @@ public interface EngineMode extends Staged {
}
private boolean shouldDisableContextCacheForMaintenance() {
boolean maintenanceActive = WorldMaintenance.isWorldMaintenanceActive(getEngine().getWorld().name());
boolean maintenanceActive = WorldMaintenance.isWorldMaintenanceActive(getEngine().getWorld().identity());
if (!maintenanceActive) {
return false;
}
PregeneratorJob pregeneratorJob = PregeneratorJob.getInstance();
boolean pregeneratorTargetsWorld = pregeneratorJob != null && pregeneratorJob.targetsWorldName(getEngine().getWorld().name());
boolean pregeneratorTargetsWorld = pregeneratorJob != null && pregeneratorJob.targetsWorldIdentity(getEngine().getWorld().identity());
return shouldDisableContextCacheForMaintenance(maintenanceActive, pregeneratorTargetsWorld);
}
}
@@ -77,7 +77,7 @@ public class MantleWriter implements IObjectPlacer, AutoCloseable {
this.z = z;
final boolean foliaMaintenance = J.isFolia()
&& WorldMaintenance.isWorldMaintenanceActive(engineMantle.getEngine().getWorld().name());
&& WorldMaintenance.isWorldMaintenanceActive(engineMantle.getEngine().getWorld().identity());
final int parallelism = foliaMaintenance ? 1 : (multicore ? Runtime.getRuntime().availableProcessors() / 2 : 4);
if (foliaMaintenance && IrisSettings.get().getGeneral().isDebug()) {
IrisLogging.info("MantleWriter using sequential chunk prefetch for maintenance regen at " + x + "," + z + ".");
@@ -18,8 +18,10 @@
package art.arcane.iris.engine.object;
import art.arcane.iris.core.IrisWorldStorage;
import art.arcane.iris.core.tools.IrisToolbelt;
import art.arcane.iris.spi.IrisLogging;
import art.arcane.volmlib.util.bukkit.WorldIdentity;
import art.arcane.volmlib.util.collection.KList;
import lombok.AccessLevel;
import lombok.Builder;
@@ -27,8 +29,8 @@ import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.NamespacedKey;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
@@ -44,6 +46,8 @@ import java.util.List;
public class IrisWorld {
private static final KList<Player> NO_PLAYERS = new KList<>();
private static final KList<? extends Entity> NO_ENTITIES = new KList<>();
private NamespacedKey key;
private String platformIdentity;
private String name;
private File worldFolder;
@@ -60,7 +64,8 @@ public class IrisWorld {
}
private static IrisWorld bindWorld(IrisWorld iw, World world) {
return iw.name(world.getName())
return iw.key(WorldIdentity.key(world))
.name(world.getName())
.worldFolder(world.getWorldFolder())
.minHeight(world.getMinHeight())
.maxHeight(world.getMaxHeight())
@@ -72,6 +77,10 @@ public class IrisWorld {
return seed;
}
public String identity() {
return key == null ? platformIdentity : key.toString();
}
public void setRawWorldSeed(long seed) {
this.seed = seed;
}
@@ -81,7 +90,11 @@ public class IrisWorld {
return true;
}
World w = Bukkit.getWorld(name);
if (key == null) {
return false;
}
World w = WorldIdentity.resolve(key).orElse(null);
if (w != null) {
realWorld = w;
@@ -111,8 +124,8 @@ public class IrisWorld {
}
public void bind(WorldInfo worldInfo) {
name(worldInfo.getName())
.worldFolder(new File(Bukkit.getWorldContainer(), worldInfo.getName()))
key(WorldIdentity.key(worldInfo))
.worldFolder(IrisWorldStorage.dimensionRoot(worldInfo))
.minHeight(worldInfo.getMinHeight())
.maxHeight(worldInfo.getMaxHeight())
.environment(worldInfo.getEnvironment());
@@ -50,6 +50,7 @@ import art.arcane.iris.spi.IrisLogging;
import art.arcane.iris.spi.IrisPlatforms;
import art.arcane.iris.spi.PlatformBiome;
import art.arcane.iris.util.common.format.C;
import art.arcane.volmlib.util.bukkit.WorldIdentity;
import art.arcane.volmlib.util.collection.KList;
import art.arcane.volmlib.util.math.M;
import art.arcane.iris.util.project.hunk.Hunk;
@@ -77,6 +78,7 @@ import java.io.File;
import java.io.PrintWriter;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.Random;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
@@ -136,8 +138,9 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
@EventHandler(priority = EventPriority.LOWEST)
public void onWorldInit(WorldInitEvent event) {
if (!world.name().equals(event.getWorld().getName())) return;
if (!Objects.equals(world.key(), WorldIdentity.key(event.getWorld()))) return;
BukkitPlatform.volmitPlugin().unregisterListener(this);
world.bind(event.getWorld());
world.setRawWorldSeed(event.getWorld().getSeed());
if (initialize(event.getWorld())) return;
@@ -165,7 +168,7 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
}
spawnChunks.complete(INMS.get().getSpawnChunkCount(world));
BukkitPlatform.volmitPlugin().unregisterListener(this);
IrisWorlds.get().put(world.getName(), dimensionKey);
IrisWorlds.get().put(WorldIdentity.serialize(world), dimensionKey);
return true;
}
@@ -524,7 +527,7 @@ public class BukkitChunkGenerator extends ChunkGenerator implements PlatformChun
World realWorld = this.world.realWorld();
PregeneratorJob pregeneratorJob = PregeneratorJob.getInstance();
return realWorld != null && pregeneratorJob != null && pregeneratorJob.targetsWorldName(realWorld.getName());
return realWorld != null && pregeneratorJob != null && pregeneratorJob.targetsWorld(realWorld);
}
@Override
@@ -10,12 +10,13 @@ import io.github.slimjar.logging.ProcessLogger;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.nio.file.Path;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Logger;
public class SlimJar {
private static final boolean DEBUG = Boolean.getBoolean("iris.debug-slimjar");
private static final boolean DISABLE_REMAPPER = Boolean.getBoolean("iris.disable-remapper");
private static final ReentrantLock lock = new ReentrantLock();
private static final AtomicBoolean loaded = new AtomicBoolean();
@@ -26,16 +27,15 @@ public class SlimJar {
try {
if (loaded.getAndSet(true)) return;
final VolmitPlugin plugin = BukkitPlatform.volmitPlugin();
final var downloadPath = plugin.getDataFolder("cache", "libraries").toPath();
final var logger = plugin.getLogger();
VolmitPlugin plugin = BukkitPlatform.volmitPlugin();
Path downloadPath = plugin.getDataFolder("cache", "libraries").toPath();
Logger logger = plugin.getLogger();
logger.info("Loading libraries...");
try {
new SpigotApplicationBuilder(plugin)
.downloadDirectoryPath(downloadPath)
.debug(DEBUG)
.remap(!DISABLE_REMAPPER)
.build();
} catch (Throwable e) {
IrisLogging.warn("Failed to inject the library loader, falling back to application builder");
@@ -138,8 +138,8 @@ public class NBTWorld {
Map<Biome, Integer> biomeIds = new KMap<>();
for (Biome biome : Registry.BIOME) {
NamespacedKey key = biome.getKeyOrNull();
if (key != null && !key.getKey().equals("custom")) {
NamespacedKey key = biome.getKey();
if (!key.getKey().equals("custom")) {
biomeIds.put(biome, INMS.get().getBiomeId(biome));
}
}
@@ -18,6 +18,7 @@
package art.arcane.iris.util.common.plugin;
import net.kyori.adventure.text.Component;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.permissions.Permission;
@@ -63,6 +64,12 @@ public class CommandDummy implements CommandSender {
return null;
}
@NotNull
@Override
public Component name() {
return Component.empty();
}
@NotNull
@Override
public Spigot spigot() {
@@ -46,6 +46,7 @@ import org.bukkit.entity.Player;
import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionAttachment;
import org.bukkit.permissions.PermissionAttachmentInfo;
import org.jetbrains.annotations.NotNull;
import org.bukkit.plugin.Plugin;
import java.util.Set;
@@ -507,6 +508,12 @@ public class VolmitSender implements CommandSender {
return s.getName();
}
@NotNull
@Override
public Component name() {
return s.name();
}
@Override
public Spigot spigot() {
return s.spigot();
@@ -0,0 +1,51 @@
package art.arcane.iris.core;
import org.bukkit.NamespacedKey;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import java.io.File;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
public class IrisWorldStorageTest {
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
@Test
public void derivesPaperDimensionRootFromNamespacedKey() throws Exception {
File levelRoot = temporaryFolder.newFolder("world");
NamespacedKey key = new NamespacedKey("iris", "runtime/studio");
File dimensionRoot = IrisWorldStorage.dimensionRoot(levelRoot, key);
assertEquals(new File(levelRoot, "dimensions/iris/runtime/studio").getAbsoluteFile(), dimensionRoot);
assertEquals(key, IrisWorldStorage.keyFromDimensionRoot(levelRoot, dimensionRoot).orElseThrow());
}
@Test
public void separatesLevelRootFromDimensionRoot() throws Exception {
File levelRoot = temporaryFolder.newFolder("world");
File dimensionRoot = new File(levelRoot, "dimensions/minecraft/overworld");
assertEquals(levelRoot.getAbsoluteFile(), IrisWorldStorage.levelRoot(dimensionRoot));
}
@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"));
}
@Test
public void rejectsKeysThatEscapeNamespaceStorage() throws Exception {
File levelRoot = temporaryFolder.newFolder("world");
NamespacedKey key = NamespacedKey.minecraft("../outside");
assertThrows(IllegalArgumentException.class, () -> IrisWorldStorage.dimensionRoot(levelRoot, key));
}
}
@@ -1,5 +1,6 @@
package art.arcane.iris.core.lifecycle;
import org.bukkit.NamespacedKey;
import org.bukkit.World;
import org.junit.Test;
@@ -15,7 +16,7 @@ public class WorldLifecycleDiagnosticsTest {
@Test
public void studioCreateSelectionFailurePrintsFullStacktrace() {
WorldLifecycleService service = new WorldLifecycleService(CapabilitySnapshot.forTesting(ServerFamily.PAPER, false, false, false));
WorldLifecycleRequest request = new WorldLifecycleRequest("studio", World.Environment.NORMAL, null, null, null, true, false, 1337L, true, false, WorldLifecycleCaller.STUDIO);
WorldLifecycleRequest request = new WorldLifecycleRequest("studio", NamespacedKey.minecraft("studio"), World.Environment.NORMAL, null, null, null, true, false, 1337L, true, false, WorldLifecycleCaller.STUDIO);
ByteArrayOutputStream output = new ByteArrayOutputStream();
PrintStream originalErr = System.err;
@@ -5,6 +5,7 @@ import art.arcane.iris.core.nms.INMSBinding;
import art.arcane.iris.engine.framework.Engine;
import art.arcane.iris.engine.framework.EngineTarget;
import art.arcane.iris.engine.platform.PlatformChunkGenerator;
import org.bukkit.NamespacedKey;
import org.bukkit.World;
import org.bukkit.generator.ChunkGenerator;
import org.junit.Test;
@@ -26,6 +27,7 @@ public class WorldLifecycleRuntimeLevelStemTest {
CapabilitySnapshot capabilities = CapabilitySnapshot.forTestingRuntimeRegistries(ServerFamily.PURPUR, false, datapackDimensions, serverRegistryAccess);
WorldLifecycleRequest request = new WorldLifecycleRequest(
"studio",
NamespacedKey.minecraft("studio"),
World.Environment.NORMAL,
new TestingPlatformChunkGenerator(),
null,
@@ -1,5 +1,6 @@
package art.arcane.iris.core.lifecycle;
import org.bukkit.NamespacedKey;
import org.bukkit.World;
import org.junit.Test;
@@ -9,7 +10,7 @@ public class WorldLifecycleSelectionTest {
@Test
public void studioSelectsPaperLikeBackendOnPaper() {
WorldLifecycleService service = new WorldLifecycleService(CapabilitySnapshot.forTesting(ServerFamily.PAPER, false, false, true));
WorldLifecycleRequest request = new WorldLifecycleRequest("studio", World.Environment.NORMAL, null, null, null, true, false, 1337L, true, false, WorldLifecycleCaller.STUDIO);
WorldLifecycleRequest request = new WorldLifecycleRequest("studio", NamespacedKey.minecraft("studio"), World.Environment.NORMAL, null, null, null, true, false, 1337L, true, false, WorldLifecycleCaller.STUDIO);
assertEquals("paper_like_runtime", service.selectCreateBackend(request).backendName());
}
@@ -17,7 +18,7 @@ public class WorldLifecycleSelectionTest {
@Test
public void studioSelectsPaperLikeBackendOnPurpur() {
WorldLifecycleService service = new WorldLifecycleService(CapabilitySnapshot.forTesting(ServerFamily.PURPUR, false, false, true));
WorldLifecycleRequest request = new WorldLifecycleRequest("studio", World.Environment.NORMAL, null, null, null, true, false, 1337L, true, false, WorldLifecycleCaller.STUDIO);
WorldLifecycleRequest request = new WorldLifecycleRequest("studio", NamespacedKey.minecraft("studio"), World.Environment.NORMAL, null, null, null, true, false, 1337L, true, false, WorldLifecycleCaller.STUDIO);
assertEquals("paper_like_runtime", service.selectCreateBackend(request).backendName());
}
@@ -25,7 +26,7 @@ public class WorldLifecycleSelectionTest {
@Test
public void studioSelectsPaperLikeBackendOnCanvas() {
WorldLifecycleService service = new WorldLifecycleService(CapabilitySnapshot.forTesting(ServerFamily.CANVAS, true, false, true));
WorldLifecycleRequest request = new WorldLifecycleRequest("studio", World.Environment.NORMAL, null, null, null, true, false, 1337L, true, false, WorldLifecycleCaller.STUDIO);
WorldLifecycleRequest request = new WorldLifecycleRequest("studio", NamespacedKey.minecraft("studio"), World.Environment.NORMAL, null, null, null, true, false, 1337L, true, false, WorldLifecycleCaller.STUDIO);
assertEquals("paper_like_runtime", service.selectCreateBackend(request).backendName());
}
@@ -33,7 +34,7 @@ public class WorldLifecycleSelectionTest {
@Test
public void studioSelectsPaperLikeBackendOnFolia() {
WorldLifecycleService service = new WorldLifecycleService(CapabilitySnapshot.forTesting(ServerFamily.FOLIA, true, false, true));
WorldLifecycleRequest request = new WorldLifecycleRequest("studio", World.Environment.NORMAL, null, null, null, true, false, 1337L, true, false, WorldLifecycleCaller.STUDIO);
WorldLifecycleRequest request = new WorldLifecycleRequest("studio", NamespacedKey.minecraft("studio"), World.Environment.NORMAL, null, null, null, true, false, 1337L, true, false, WorldLifecycleCaller.STUDIO);
assertEquals("paper_like_runtime", service.selectCreateBackend(request).backendName());
}
@@ -41,7 +42,7 @@ public class WorldLifecycleSelectionTest {
@Test
public void studioSelectsBukkitBackendOnSpigot() {
WorldLifecycleService service = new WorldLifecycleService(CapabilitySnapshot.forTesting(ServerFamily.SPIGOT, false, false, false));
WorldLifecycleRequest request = new WorldLifecycleRequest("studio", World.Environment.NORMAL, null, null, null, true, false, 1337L, true, false, WorldLifecycleCaller.STUDIO);
WorldLifecycleRequest request = new WorldLifecycleRequest("studio", NamespacedKey.minecraft("studio"), World.Environment.NORMAL, null, null, null, true, false, 1337L, true, false, WorldLifecycleCaller.STUDIO);
assertEquals("bukkit_public", service.selectCreateBackend(request).backendName());
}
@@ -49,7 +50,7 @@ public class WorldLifecycleSelectionTest {
@Test
public void persistentCreatePrefersBukkitBackendOnPaperLikeServers() {
WorldLifecycleService service = new WorldLifecycleService(CapabilitySnapshot.forTesting(ServerFamily.PURPUR, false, false, true));
WorldLifecycleRequest request = new WorldLifecycleRequest("persistent", World.Environment.NORMAL, null, null, null, true, false, 1337L, false, false, WorldLifecycleCaller.CREATE);
WorldLifecycleRequest request = new WorldLifecycleRequest("persistent", NamespacedKey.minecraft("persistent"), World.Environment.NORMAL, null, null, null, true, false, 1337L, false, false, WorldLifecycleCaller.CREATE);
assertEquals("bukkit_public", service.selectCreateBackend(request).backendName());
}
@@ -57,7 +58,7 @@ public class WorldLifecycleSelectionTest {
@Test
public void persistentCreateSelectsPaperLikeBackendOnFolia() {
WorldLifecycleService service = new WorldLifecycleService(CapabilitySnapshot.forTesting(ServerFamily.FOLIA, true, false, true));
WorldLifecycleRequest request = new WorldLifecycleRequest("persistent", World.Environment.NORMAL, null, null, null, true, false, 1337L, false, false, WorldLifecycleCaller.CREATE);
WorldLifecycleRequest request = new WorldLifecycleRequest("persistent", NamespacedKey.minecraft("persistent"), World.Environment.NORMAL, null, null, null, true, false, 1337L, false, false, WorldLifecycleCaller.CREATE);
assertEquals("paper_like_runtime", service.selectCreateBackend(request).backendName());
}
@@ -65,7 +66,7 @@ public class WorldLifecycleSelectionTest {
@Test
public void persistentCreateSelectsPaperLikeBackendOnCanvas() {
WorldLifecycleService service = new WorldLifecycleService(CapabilitySnapshot.forTesting(ServerFamily.CANVAS, true, false, true));
WorldLifecycleRequest request = new WorldLifecycleRequest("persistent", World.Environment.NORMAL, null, null, null, true, false, 1337L, false, false, WorldLifecycleCaller.CREATE);
WorldLifecycleRequest request = new WorldLifecycleRequest("persistent", NamespacedKey.minecraft("persistent"), World.Environment.NORMAL, null, null, null, true, false, 1337L, false, false, WorldLifecycleCaller.CREATE);
assertEquals("paper_like_runtime", service.selectCreateBackend(request).backendName());
}
@@ -73,7 +74,7 @@ public class WorldLifecycleSelectionTest {
@Test
public void persistentCreateFallsBackToBukkitBackendOnFoliaWithoutRuntime() {
WorldLifecycleService service = new WorldLifecycleService(CapabilitySnapshot.forTesting(ServerFamily.FOLIA, true, false, false));
WorldLifecycleRequest request = new WorldLifecycleRequest("persistent", World.Environment.NORMAL, null, null, null, true, false, 1337L, false, false, WorldLifecycleCaller.CREATE);
WorldLifecycleRequest request = new WorldLifecycleRequest("persistent", NamespacedKey.minecraft("persistent"), World.Environment.NORMAL, null, null, null, true, false, 1337L, false, false, WorldLifecycleCaller.CREATE);
assertEquals("bukkit_public", service.selectCreateBackend(request).backendName());
}
@@ -82,7 +83,7 @@ public class WorldLifecycleSelectionTest {
public void unloadUsesRememberedBackendFamily() {
WorldLifecycleService service = new WorldLifecycleService(CapabilitySnapshot.forTesting(ServerFamily.PURPUR, false, false, true));
service.rememberBackend("studio", "paper_like_runtime");
assertEquals("paper_like_runtime", service.selectUnloadBackend("studio").backendName());
service.rememberBackend(NamespacedKey.minecraft("studio"), "paper_like_runtime");
assertEquals("paper_like_runtime", service.selectUnloadBackend("minecraft:studio").backendName());
}
}
@@ -39,10 +39,11 @@ public class TransientWorldCleanupSupportTest {
public void collectsOnlyTransientStudioWorldFamiliesFromContainer() throws IOException {
File container = Files.createTempDirectory("transient-world-cleanup-test").toFile();
String baseName = "iris-123e4567-e89b-12d3-a456-426614174000";
File baseFolder = new File(container, baseName);
File netherFolder = new File(container, baseName + "_nether");
File smokeFolder = new File(container, "iris-smoke-studio-deadbeef");
File regularFolder = new File(container, "overworld");
File namespace = new File(container, "dimensions/minecraft");
File baseFolder = new File(namespace, baseName);
File netherFolder = new File(namespace, baseName + "_nether");
File smokeFolder = new File(namespace, "iris-smoke-studio-deadbeef");
File regularFolder = new File(namespace, "overworld");
baseFolder.mkdirs();
netherFolder.mkdirs();
smokeFolder.mkdirs();
@@ -57,6 +58,8 @@ public class TransientWorldCleanupSupportTest {
Files.deleteIfExists(netherFolder.toPath());
Files.deleteIfExists(smokeFolder.toPath());
Files.deleteIfExists(regularFolder.toPath());
Files.deleteIfExists(namespace.toPath());
Files.deleteIfExists(namespace.getParentFile().toPath());
Files.deleteIfExists(container.toPath());
}
}
@@ -1,13 +1,24 @@
package art.arcane.iris.core.tools;
import art.arcane.iris.core.service.StudioSVC;
import art.arcane.iris.spi.IrisServices;
import org.bukkit.World;
import org.junit.After;
import org.junit.Test;
import java.lang.reflect.Proxy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
public class IrisToolbeltPackReferenceTest {
@After
public void cleanServices() {
IrisServices.remove(StudioSVC.class);
}
@Test
public void plainPackUsesMatchingDimensionKey() {
IrisToolbelt.PackReference reference = IrisToolbelt.parsePackReference("overworld");
@@ -34,4 +45,16 @@ public class IrisToolbeltPackReferenceTest {
assertNull(IrisToolbelt.parsePackReference("pack:"));
assertNull(IrisToolbelt.parsePackReference(":dimension"));
}
@Test
public void accessReturnsNullAfterStudioServiceIsRemoved() {
IrisServices.remove(StudioSVC.class);
World world = (World) Proxy.newProxyInstance(
World.class.getClassLoader(),
new Class<?>[]{World.class},
(proxy, method, args) -> null
);
assertNull(IrisToolbelt.access(world));
}
}
@@ -0,0 +1,27 @@
package art.arcane.iris.engine.object;
import org.bukkit.NamespacedKey;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class IrisWorldIdentityTest {
@Test
public void usesBukkitKeyBeforePlatformIdentity() {
IrisWorld world = IrisWorld.builder()
.key(new NamespacedKey("iris", "bukkit"))
.platformIdentity("iris:modded")
.build();
assertEquals("iris:bukkit", world.identity());
}
@Test
public void usesPlatformIdentityWithoutBukkitKey() {
IrisWorld world = IrisWorld.builder()
.platformIdentity("minecraft:the_nether")
.build();
assertEquals("minecraft:the_nether", world.identity());
}
}