Eradicate all reference of offline world

This commit is contained in:
Ben Woo 2023-09-08 23:41:26 +08:00
parent f0d2499dd2
commit b4617c1c1f
No known key found for this signature in database
GPG Key ID: FB2A3645536E12C8
10 changed files with 103 additions and 94 deletions

View File

@ -34,6 +34,7 @@ public class MVWorldListener implements InjectableListener {
/** /**
* This method is called when Bukkit fires off a WorldUnloadEvent. * This method is called when Bukkit fires off a WorldUnloadEvent.
*
* @param event The Event that was fired. * @param event The Event that was fired.
*/ */
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
@ -50,14 +51,15 @@ public class MVWorldListener implements InjectableListener {
/** /**
* This method is called when Bukkit fires off a WorldLoadEvent. * This method is called when Bukkit fires off a WorldLoadEvent.
*
* @param event The Event that was fired. * @param event The Event that was fired.
*/ */
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void loadWorld(WorldLoadEvent event) { public void loadWorld(WorldLoadEvent event) {
worldManager.getUnloadedWorld(event.getWorld().getName()) worldManager.getUnloadedWorld(event.getWorld().getName())
.peek(offlineWorld -> { .peek(world -> {
Logging.fine("Loading world: " + offlineWorld.getName()); Logging.fine("Loading world: " + world.getName());
worldManager.loadWorld(offlineWorld).onFailure(failure -> { worldManager.loadWorld(world).onFailure(failure -> {
if (failure.getFailureReason() != LoadWorldResult.Failure.WORLD_ALREADY_LOADING) { if (failure.getFailureReason() != LoadWorldResult.Failure.WORLD_ALREADY_LOADING) {
Logging.severe("Failed to load world: " + failure); Logging.severe("Failed to load world: " + failure);
} }

View File

@ -91,14 +91,14 @@ public enum MVCorei18n implements MessageKeyProvider {
CLONEWORLD_CLONED, CLONEWORLD_CLONED,
CLONEWORLD_INVALIDWORLDNAME, CLONEWORLD_INVALIDWORLDNAME,
CLONEWORLD_WORLDEXISTFOLDER, CLONEWORLD_WORLDEXISTFOLDER,
CLONEWORLD_WORLDEXISTOFFLINE, CLONEWORLD_WORLDEXISTUNLOADED,
CLONEWORLD_WORLDEXISTLOADED, CLONEWORLD_WORLDEXISTLOADED,
CLONEWORLD_COPYFAILED, CLONEWORLD_COPYFAILED,
CREATEWORLD_CREATED, CREATEWORLD_CREATED,
CREATEWORLD_INVALIDWORLDNAME, CREATEWORLD_INVALIDWORLDNAME,
CREATEWORLD_WORLDEXISTFOLDER, CREATEWORLD_WORLDEXISTFOLDER,
CREATEWORLD_WORLDEXISTOFFLINE, CREATEWORLD_WORLDEXISTUNLOADED,
CREATEWORLD_WORLDEXISTLOADED, CREATEWORLD_WORLDEXISTLOADED,
CREATEWORLD_BUKKITCREATIONFAILED, CREATEWORLD_BUKKITCREATIONFAILED,
@ -111,7 +111,7 @@ public enum MVCorei18n implements MessageKeyProvider {
IMPORTWORLD_IMPORTED, IMPORTWORLD_IMPORTED,
IMPORTWORLD_INVALIDWORLDNAME, IMPORTWORLD_INVALIDWORLDNAME,
IMPORTWORLD_WORLDFOLDERINVALID, IMPORTWORLD_WORLDFOLDERINVALID,
IMPORTWORLD_WORLDEXISTOFFLINE, IMPORTWORLD_WORLDEXISTUNLOADED,
IMPORTWORLD_WORLDEXISTLOADED, IMPORTWORLD_WORLDEXISTLOADED,
IMPORTWORLD_BUKKITCREATIONFAILED, IMPORTWORLD_BUKKITCREATIONFAILED,
@ -130,7 +130,7 @@ public enum MVCorei18n implements MessageKeyProvider {
UNLOADWORLD_UNLOADED, UNLOADWORLD_UNLOADED,
UNLOADWORLD_WORLDALREADYUNLOADING, UNLOADWORLD_WORLDALREADYUNLOADING,
UNLOADWORLD_WORLDNONEXISTENT, UNLOADWORLD_WORLDNONEXISTENT,
UNLOADWORLD_WORLDOFFLINE, UNLOADWORLD_WORLDUNLOADED,
UNLOADWORLD_BUKKITUNLOADFAILED, UNLOADWORLD_BUKKITUNLOADFAILED,
// generic // generic

View File

@ -117,7 +117,7 @@ public class LoadedMultiverseWorld extends MultiverseWorld {
@Override @Override
public String toString() { public String toString() {
return "MVWorld{" return "LoadedMultiverseWorld{"
+ "name='" + worldName + "', " + "name='" + worldName + "', "
+ "env='" + getEnvironment() + "', " + "env='" + getEnvironment() + "', "
+ "type='" + getWorldType().getOrNull() + "', " + "type='" + getWorldType().getOrNull() + "', "

View File

@ -300,7 +300,7 @@ public class MultiverseWorld {
@Override @Override
public String toString() { public String toString() {
return "OfflineWorld{" return "MultiverseWorld{"
+ "name='" + worldName + "', " + "name='" + worldName + "', "
+ "env='" + getEnvironment() + "', " + "env='" + getEnvironment() + "', "
+ "gen='" + getGenerator() + "'" + "gen='" + getGenerator() + "'"

View File

@ -55,8 +55,8 @@ import static com.onarandombox.MultiverseCore.worldnew.helpers.DataStore.WorldCo
public class WorldManager { public class WorldManager {
private static final List<String> CLONE_IGNORE_FILES = Arrays.asList("uid.dat", "session.lock"); private static final List<String> CLONE_IGNORE_FILES = Arrays.asList("uid.dat", "session.lock");
private final Map<String, MultiverseWorld> offlineWorldsMap; private final Map<String, MultiverseWorld> worldsMap;
private final Map<String, LoadedMultiverseWorld> worldsMap; private final Map<String, LoadedMultiverseWorld> loadedWorldsMap;
private final List<String> unloadTracker; private final List<String> unloadTracker;
private final List<String> loadTracker; private final List<String> loadTracker;
private final WorldsConfigManager worldsConfigManager; private final WorldsConfigManager worldsConfigManager;
@ -77,8 +77,8 @@ public class WorldManager {
@NotNull SafeTTeleporter safeTTeleporter, @NotNull SafeTTeleporter safeTTeleporter,
@NotNull LocationManipulation locationManipulation @NotNull LocationManipulation locationManipulation
) { ) {
this.offlineWorldsMap = new HashMap<>();
this.worldsMap = new HashMap<>(); this.worldsMap = new HashMap<>();
this.loadedWorldsMap = new HashMap<>();
this.unloadTracker = new ArrayList<>(); this.unloadTracker = new ArrayList<>();
this.loadTracker = new ArrayList<>(); this.loadTracker = new ArrayList<>();
@ -99,12 +99,12 @@ public class WorldManager {
return; return;
} }
loadDefaultWorlds(); loadDefaultWorlds();
autoLoadOfflineWorlds(); autoLoadWorlds();
saveWorldsConfig(); saveWorldsConfig();
} }
/** /**
* Generate offline worlds from the worlds config. * Generate worlds from the worlds config.
*/ */
private boolean populateWorldFromConfig() { private boolean populateWorldFromConfig() {
Try<Void> load = worldsConfigManager.load(); Try<Void> load = worldsConfigManager.load();
@ -119,8 +119,8 @@ public class WorldManager {
getWorld(worldConfig.getWorldName()) getWorld(worldConfig.getWorldName())
.peek(unloadedWorld -> unloadedWorld.setWorldConfig(worldConfig)) .peek(unloadedWorld -> unloadedWorld.setWorldConfig(worldConfig))
.onEmpty(() -> { .onEmpty(() -> {
MultiverseWorld offlineWorld = new MultiverseWorld(worldConfig.getWorldName(), worldConfig); MultiverseWorld mvWorld = new MultiverseWorld(worldConfig.getWorldName(), worldConfig);
offlineWorldsMap.put(offlineWorld.getName(), offlineWorld); worldsMap.put(mvWorld.getName(), mvWorld);
}); });
}); });
return true; return true;
@ -143,7 +143,7 @@ public class WorldManager {
/** /**
* Loads all worlds that are set to autoload. * Loads all worlds that are set to autoload.
*/ */
private void autoLoadOfflineWorlds() { private void autoLoadWorlds() {
getWorlds().forEach(world -> { getWorlds().forEach(world -> {
if (isLoadedWorld(world) || !world.getAutoLoad()) { if (isLoadedWorld(world) || !world.getAutoLoad()) {
return; return;
@ -168,7 +168,7 @@ public class WorldManager {
replace("{world}").with(options.worldName())); replace("{world}").with(options.worldName()));
} }
if (getWorld(options.worldName()).isDefined()) { if (getWorld(options.worldName()).isDefined()) {
return Result.failure(CreateWorldResult.Failure.WORLD_EXIST_OFFLINE, return Result.failure(CreateWorldResult.Failure.WORLD_EXIST_UNLOADED,
replace("{world}").with(options.worldName())); replace("{world}").with(options.worldName()));
} }
File worldFolder = new File(Bukkit.getWorldContainer(), options.worldName()); File worldFolder = new File(Bukkit.getWorldContainer(), options.worldName());
@ -216,7 +216,7 @@ public class WorldManager {
replace("{world}").with(options.worldName())); replace("{world}").with(options.worldName()));
} }
if (isWorld(options.worldName())) { if (isWorld(options.worldName())) {
return Result.failure(ImportWorldResult.Failure.WORLD_EXIST_OFFLINE, return Result.failure(ImportWorldResult.Failure.WORLD_EXIST_UNLOADED,
replace("{world}").with(options.worldName())); replace("{world}").with(options.worldName()));
} }
@ -246,16 +246,16 @@ public class WorldManager {
worldConfig.setAdjustSpawn(adjustSpawn); worldConfig.setAdjustSpawn(adjustSpawn);
worldConfig.setGenerator(generator == null ? "" : generator); worldConfig.setGenerator(generator == null ? "" : generator);
MultiverseWorld offlineWorld = new MultiverseWorld(world.getName(), worldConfig); MultiverseWorld mvWorld = new MultiverseWorld(world.getName(), worldConfig);
offlineWorldsMap.put(offlineWorld.getName(), offlineWorld);
LoadedMultiverseWorld mvWorld = new LoadedMultiverseWorld(world, worldConfig, blockSafety, safeTTeleporter, locationManipulation);
worldsMap.put(mvWorld.getName(), mvWorld); worldsMap.put(mvWorld.getName(), mvWorld);
LoadedMultiverseWorld loadedWorld = new LoadedMultiverseWorld(world, worldConfig, blockSafety, safeTTeleporter, locationManipulation);
loadedWorldsMap.put(loadedWorld.getName(), loadedWorld);
saveWorldsConfig(); saveWorldsConfig();
} }
/** /**
* Loads an existing offline world. * Loads an existing world in config.
* *
* @param worldName The name of the world to load. * @param worldName The name of the world to load.
* @return The result of the load. * @return The result of the load.
@ -271,45 +271,45 @@ public class WorldManager {
} }
/** /**
* Loads an existing offline world. * Loads an existing world in config.
* *
* @param offlineWorld The offline world to load. * @param mvWorld The world to load.
* @return The result of the load. * @return The result of the load.
*/ */
public Result<LoadWorldResult.Success, LoadWorldResult.Failure> loadWorld(@NotNull MultiverseWorld offlineWorld) { public Result<LoadWorldResult.Success, LoadWorldResult.Failure> loadWorld(@NotNull MultiverseWorld mvWorld) {
// Params validations // Params validations
if (loadTracker.contains(offlineWorld.getName())) { if (loadTracker.contains(mvWorld.getName())) {
// This is to prevent recursive calls by WorldLoadEvent // This is to prevent recursive calls by WorldLoadEvent
Logging.fine("World already loading: " + offlineWorld.getName()); Logging.fine("World already loading: " + mvWorld.getName());
return Result.failure(LoadWorldResult.Failure.WORLD_ALREADY_LOADING, return Result.failure(LoadWorldResult.Failure.WORLD_ALREADY_LOADING,
replace("{world}").with(offlineWorld.getName())); replace("{world}").with(mvWorld.getName()));
} }
if (isLoadedWorld(offlineWorld)) { if (isLoadedWorld(mvWorld)) {
Logging.severe("World already loaded: " + offlineWorld.getName()); Logging.severe("World already loaded: " + mvWorld.getName());
return Result.failure(LoadWorldResult.Failure.WORLD_EXIST_LOADED, return Result.failure(LoadWorldResult.Failure.WORLD_EXIST_LOADED,
replace("{world}").with(offlineWorld.getName())); replace("{world}").with(mvWorld.getName()));
} }
return createBukkitWorld(WorldCreator.name(offlineWorld.getName()) return createBukkitWorld(WorldCreator.name(mvWorld.getName())
.environment(offlineWorld.getEnvironment()) .environment(mvWorld.getEnvironment())
.generator(Strings.isNullOrEmpty(offlineWorld.getGenerator()) ? null : offlineWorld.getGenerator()) .generator(Strings.isNullOrEmpty(mvWorld.getGenerator()) ? null : mvWorld.getGenerator())
.seed(offlineWorld.getSeed())).fold( .seed(mvWorld.getSeed())).fold(
exception -> Result.failure(LoadWorldResult.Failure.BUKKIT_CREATION_FAILED, exception -> Result.failure(LoadWorldResult.Failure.BUKKIT_CREATION_FAILED,
replace("{world}").with(offlineWorld.getName()), replace("{world}").with(mvWorld.getName()),
replace("{error}").with(exception.getMessage())), replace("{error}").with(exception.getMessage())),
world -> { world -> {
WorldConfig worldConfig = worldsConfigManager.getWorldConfig(offlineWorld.getName()); WorldConfig worldConfig = worldsConfigManager.getWorldConfig(mvWorld.getName());
LoadedMultiverseWorld mvWorld = new LoadedMultiverseWorld(world, worldConfig, blockSafety, LoadedMultiverseWorld loadedWorld = new LoadedMultiverseWorld(world, worldConfig, blockSafety,
safeTTeleporter, locationManipulation); safeTTeleporter, locationManipulation);
worldsMap.put(mvWorld.getName(), mvWorld); loadedWorldsMap.put(loadedWorld.getName(), loadedWorld);
saveWorldsConfig(); saveWorldsConfig();
return Result.success(LoadWorldResult.Success.LOADED, return Result.success(LoadWorldResult.Success.LOADED,
replace("{world}").with(mvWorld.getName())); replace("{world}").with(loadedWorld.getName()));
}); });
} }
/** /**
* Unloads an existing multiverse world. It will still remain as an offline world. * Unloads an existing multiverse world. It will still remain as an unloaded world in mv config.
* *
* @param world The bukkit world to unload. * @param world The bukkit world to unload.
* @return The result of the unload action. * @return The result of the unload action.
@ -319,7 +319,7 @@ public class WorldManager {
} }
/** /**
* Unloads an existing multiverse world. It will still remain as an offline world. * Unloads an existing multiverse world. It will still remain as an unloaded world in mv config.
* *
* @param worldName The name of the world to unload. * @param worldName The name of the world to unload.
* @return The result of the unload action. * @return The result of the unload action.
@ -328,14 +328,14 @@ public class WorldManager {
return getLoadedWorld(worldName) return getLoadedWorld(worldName)
.map(this::unloadWorld) .map(this::unloadWorld)
.getOrElse(() -> isUnloadedWorld(worldName) .getOrElse(() -> isUnloadedWorld(worldName)
? Result.failure(UnloadWorldResult.Failure.WORLD_OFFLINE, ? Result.failure(UnloadWorldResult.Failure.WORLD_UNLOADED,
replace("{world}").with(worldName)) replace("{world}").with(worldName))
: Result.failure(UnloadWorldResult.Failure.WORLD_NON_EXISTENT, : Result.failure(UnloadWorldResult.Failure.WORLD_NON_EXISTENT,
replace("{world}").with(worldName))); replace("{world}").with(worldName)));
} }
/** /**
* Unloads an existing multiverse world. It will still remain as an offline world. * Unloads an existing multiverse world. It will still remain as an unloaded world.
* *
* @param world The multiverse world to unload. * @param world The multiverse world to unload.
* @return The result of the unload action. * @return The result of the unload action.
@ -354,7 +354,7 @@ public class WorldManager {
exception -> Result.failure(UnloadWorldResult.Failure.BUKKIT_UNLOAD_FAILED, exception -> Result.failure(UnloadWorldResult.Failure.BUKKIT_UNLOAD_FAILED,
replace("{world}").with(world.getName()), replace("{world}").with(world.getName()),
replace("{error}").with(exception.getMessage())), replace("{error}").with(exception.getMessage())),
success -> Option.of(worldsMap.remove(world.getName())).fold( success -> Option.of(loadedWorldsMap.remove(world.getName())).fold(
() -> { () -> {
Logging.severe("Failed to remove world from map: " + world.getName()); Logging.severe("Failed to remove world from map: " + world.getName());
return Result.failure(UnloadWorldResult.Failure.WORLD_NON_EXISTENT, return Result.failure(UnloadWorldResult.Failure.WORLD_NON_EXISTENT,
@ -369,8 +369,8 @@ public class WorldManager {
} }
/** /**
* Removes an existing multiverse world. It will be deleted from the worlds config and will no longer be an offline world. * Removes an existing multiverse world. It will be deleted from the worlds config and will no longer be an
* World files will not be deleted. * unloaded world. World files will not be deleted.
* *
* @param worldName The name of the world to remove. * @param worldName The name of the world to remove.
* @return The result of the remove. * @return The result of the remove.
@ -382,8 +382,8 @@ public class WorldManager {
} }
/** /**
* Removes an existing multiverse world. It will be deleted from the worlds config and will no longer be an offline world. * Removes an existing multiverse world. It will be deleted from the worlds config and will no longer be an
* World files will not be deleted. * unloaded world. World files will not be deleted.
* *
* @param world The multiverse world to remove. * @param world The multiverse world to remove.
* @return The result of the remove. * @return The result of the remove.
@ -395,22 +395,22 @@ public class WorldManager {
} }
/** /**
* Removes an existing multiverse world. It will be deleted from the worlds config and will no longer be an offline * Removes an existing multiverse world. It will be deleted from the worlds config and will no longer be an
* world. World files will not be deleted. * unloaded world. World files will not be deleted.
* *
* @param world The multiverse world to remove. * @param loadedWorld The multiverse world to remove.
* @return The result of the remove. * @return The result of the remove.
*/ */
public Result<RemoveWorldResult.Success, RemoveWorldResult.Failure> removeWorld(@NotNull LoadedMultiverseWorld world) { public Result<RemoveWorldResult.Success, RemoveWorldResult.Failure> removeWorld(@NotNull LoadedMultiverseWorld loadedWorld) {
var result = unloadWorld(world); var result = unloadWorld(loadedWorld);
if (result.isFailure()) { if (result.isFailure()) {
return Result.failure(RemoveWorldResult.Failure.UNLOAD_FAILED, result.getReasonMessage()); return Result.failure(RemoveWorldResult.Failure.UNLOAD_FAILED, result.getReasonMessage());
} }
return removeWorldFromConfig(world); return removeWorldFromConfig(loadedWorld);
} }
/** /**
* Removes an existing multiverse world from the world's config. It will no longer be an offline world. * Removes an existing multiverse world from the world's config. It will no longer be an world known to Multiverse.
* *
* @param world The multiverse world to remove. * @param world The multiverse world to remove.
* @return The result of the remove. * @return The result of the remove.
@ -418,7 +418,7 @@ public class WorldManager {
private Result<RemoveWorldResult.Success, RemoveWorldResult.Failure> private Result<RemoveWorldResult.Success, RemoveWorldResult.Failure>
removeWorldFromConfig(@NotNull MultiverseWorld world) { removeWorldFromConfig(@NotNull MultiverseWorld world) {
// Remove world from config // Remove world from config
offlineWorldsMap.remove(world.getName()); worldsMap.remove(world.getName());
worldsConfigManager.deleteWorldConfig(world.getName()); worldsConfigManager.deleteWorldConfig(world.getName());
saveWorldsConfig(); saveWorldsConfig();
@ -443,7 +443,7 @@ public class WorldManager {
* Deletes an existing multiverse world entirely. World will be loaded if it is not already loaded. * Deletes an existing multiverse world entirely. World will be loaded if it is not already loaded.
* Warning: This will delete all world files. * Warning: This will delete all world files.
* *
* @param world The offline world to delete. * @param world The world to delete.
* @return The result of the delete action. * @return The result of the delete action.
*/ */
public Result<DeleteWorldResult.Success, DeleteWorldResult.Failure> deleteWorld(@NotNull MultiverseWorld world) { public Result<DeleteWorldResult.Success, DeleteWorldResult.Failure> deleteWorld(@NotNull MultiverseWorld world) {
@ -530,8 +530,8 @@ public class WorldManager {
return Result.failure(CloneWorldResult.Failure.WORLD_EXIST_LOADED, replace("{world}").with(newWorldName)); return Result.failure(CloneWorldResult.Failure.WORLD_EXIST_LOADED, replace("{world}").with(newWorldName));
} }
if (isWorld(newWorldName)) { if (isWorld(newWorldName)) {
Logging.severe("World already exist offline: " + newWorldName); Logging.severe("World already exist unloaded: " + newWorldName);
return Result.failure(CloneWorldResult.Failure.WORLD_EXIST_OFFLINE, replace("{world}").with(newWorldName)); return Result.failure(CloneWorldResult.Failure.WORLD_EXIST_UNLOADED, replace("{world}").with(newWorldName));
} }
return Result.success(); return Result.success();
} }
@ -674,61 +674,68 @@ public class WorldManager {
} }
/** /**
* Get an offline world that is not loaded. * Get a world that is not loaded.
* *
* @param worldName The name of the world to get. * @param worldName The name of the world to get.
* @return The offline world if it exists. * @return The world if it exists.
*/ */
public Option<MultiverseWorld> getUnloadedWorld(@Nullable String worldName) { public Option<MultiverseWorld> getUnloadedWorld(@Nullable String worldName) {
return isLoadedWorld(worldName) ? Option.none() : Option.of(offlineWorldsMap.get(worldName)); return isLoadedWorld(worldName) ? Option.none() : Option.of(worldsMap.get(worldName));
} }
/** /**
* Get a list of all offline worlds that are not loaded. * Get a list of all worlds that are not loaded.
* *
* @return A list of all offline worlds that are not loaded. * @return A list of all worlds that are not loaded.
*/ */
public Collection<MultiverseWorld> getUnloadedWorlds() { public Collection<MultiverseWorld> getUnloadedWorlds() {
return offlineWorldsMap.values().stream().filter(world -> !world.isLoaded()).toList(); return worldsMap.values().stream().filter(world -> !world.isLoaded()).toList();
} }
/** /**
* Check if a world is an offline world that is not loaded. * Check if a world is a world that is not loaded.
* *
* @param worldName The name of the world to check. * @param worldName The name of the world to check.
* @return True if the world is an offline world that is not loaded. * @return True if the world is a world that is not loaded.
*/ */
public boolean isUnloadedWorld(@Nullable String worldName) { public boolean isUnloadedWorld(@Nullable String worldName) {
return !isLoadedWorld(worldName) && isWorld(worldName); return !isLoadedWorld(worldName) && isWorld(worldName);
} }
/** /**
* Get an offline world that may or may not be loaded. * Get a world that may or may not be loaded. It will an {@link LoadedMultiverseWorld} if the world is loaded,
* otherwise returns an {@link MultiverseWorld} instance.
* *
* @param worldName The name of the world to get. * @param worldName The name of the world to get.
* @return The offline world if it exists. * @return The world if it exists.
*/ */
public Option<MultiverseWorld> getWorld(@Nullable String worldName) { public Option<MultiverseWorld> getWorld(@Nullable String worldName) {
return Option.of(offlineWorldsMap.get(worldName)); return getLoadedWorld(worldName).fold(() -> getUnloadedWorld(worldName), Option::of);
} }
/** /**
* Get a list of all offline worlds that may or may not be loaded. * <p>Get a list of all worlds that may or may not be loaded. It will an {@link LoadedMultiverseWorld} if the world
* is loaded, otherwise you will get an {@link MultiverseWorld} instance.</p>
* *
* @return A list of all offline worlds that may or may not be loaded. * <p>If you want only unloaded worlds, use {@link #getUnloadedWorlds()}. If you want only loaded worlds, use
* {@link #getLoadedWorlds()}.</p>
*
* @return A list of all worlds that may or may not be loaded.
*/ */
public Collection<MultiverseWorld> getWorlds() { public Collection<MultiverseWorld> getWorlds() {
return offlineWorldsMap.values(); return worldsMap.values().stream()
.map(world -> getLoadedWorld(world).fold(() -> world, loadedWorld -> loadedWorld))
.toList();
} }
/** /**
* Check if a world is an offline world that may or may not be loaded. * Check if a world is a world is known to multiverse, but may or may not be loaded.
* *
* @param worldName The name of the world to check. * @param worldName The name of the world to check.
* @return True if the world is an offline world that may or may not be loaded. * @return True if the world is a world is known to multiverse, but may or may not be loaded.
*/ */
public boolean isWorld(@Nullable String worldName) { public boolean isWorld(@Nullable String worldName) {
return offlineWorldsMap.containsKey(worldName); return worldsMap.containsKey(worldName);
} }
/** /**
@ -738,17 +745,17 @@ public class WorldManager {
* @return The multiverse world if it exists. * @return The multiverse world if it exists.
*/ */
public Option<LoadedMultiverseWorld> getLoadedWorld(@Nullable World world) { public Option<LoadedMultiverseWorld> getLoadedWorld(@Nullable World world) {
return world == null ? Option.none() : Option.of(worldsMap.get(world.getName())); return world == null ? Option.none() : Option.of(loadedWorldsMap.get(world.getName()));
} }
/** /**
* Get a multiverse world that is loaded. * Get a multiverse world that is loaded.
* *
* @param world The offline world that should be loaded. * @param world The world that should be loaded.
* @return The multiverse world if it exists. * @return The multiverse world if it exists.
*/ */
public Option<LoadedMultiverseWorld> getLoadedWorld(@Nullable MultiverseWorld world) { public Option<LoadedMultiverseWorld> getLoadedWorld(@Nullable MultiverseWorld world) {
return world == null ? Option.none() : Option.of(worldsMap.get(world.getName())); return world == null ? Option.none() : Option.of(loadedWorldsMap.get(world.getName()));
} }
/** /**
@ -758,7 +765,7 @@ public class WorldManager {
* @return The multiverse world if it exists. * @return The multiverse world if it exists.
*/ */
public Option<LoadedMultiverseWorld> getLoadedWorld(@Nullable String worldName) { public Option<LoadedMultiverseWorld> getLoadedWorld(@Nullable String worldName) {
return Option.of(worldsMap.get(worldName)); return Option.of(loadedWorldsMap.get(worldName));
} }
/** /**
@ -767,7 +774,7 @@ public class WorldManager {
* @return A list of all multiverse worlds that are loaded. * @return A list of all multiverse worlds that are loaded.
*/ */
public Collection<LoadedMultiverseWorld> getLoadedWorlds() { public Collection<LoadedMultiverseWorld> getLoadedWorlds() {
return worldsMap.values(); return loadedWorldsMap.values();
} }
/** /**
@ -783,7 +790,7 @@ public class WorldManager {
/** /**
* Check if a world is a multiverse world that is loaded. * Check if a world is a multiverse world that is loaded.
* *
* @param world The offline world to check. * @param world The world to check.
* @return True if the world is a multiverse world that is loaded. * @return True if the world is a multiverse world that is loaded.
*/ */
public boolean isLoadedWorld(@Nullable MultiverseWorld world) { public boolean isLoadedWorld(@Nullable MultiverseWorld world) {
@ -797,7 +804,7 @@ public class WorldManager {
* @return True if the world is a multiverse world that is loaded. * @return True if the world is a multiverse world that is loaded.
*/ */
public boolean isLoadedWorld(@Nullable String worldName) { public boolean isLoadedWorld(@Nullable String worldName) {
return worldsMap.containsKey(worldName); return loadedWorldsMap.containsKey(worldName);
} }
/** /**

View File

@ -26,7 +26,7 @@ public class CloneWorldResult {
public enum Failure implements FailureReason { public enum Failure implements FailureReason {
INVALID_WORLDNAME(MVCorei18n.CLONEWORLD_INVALIDWORLDNAME), INVALID_WORLDNAME(MVCorei18n.CLONEWORLD_INVALIDWORLDNAME),
WORLD_EXIST_FOLDER(MVCorei18n.CLONEWORLD_WORLDEXISTFOLDER), WORLD_EXIST_FOLDER(MVCorei18n.CLONEWORLD_WORLDEXISTFOLDER),
WORLD_EXIST_OFFLINE(MVCorei18n.CLONEWORLD_WORLDEXISTOFFLINE), WORLD_EXIST_UNLOADED(MVCorei18n.CLONEWORLD_WORLDEXISTUNLOADED),
WORLD_EXIST_LOADED(MVCorei18n.CLONEWORLD_WORLDEXISTLOADED), WORLD_EXIST_LOADED(MVCorei18n.CLONEWORLD_WORLDEXISTLOADED),
COPY_FAILED(MVCorei18n.CLONEWORLD_COPYFAILED), COPY_FAILED(MVCorei18n.CLONEWORLD_COPYFAILED),
IMPORT_FAILED(null), IMPORT_FAILED(null),

View File

@ -26,7 +26,7 @@ public class CreateWorldResult {
public enum Failure implements FailureReason { public enum Failure implements FailureReason {
INVALID_WORLDNAME(MVCorei18n.CREATEWORLD_INVALIDWORLDNAME), INVALID_WORLDNAME(MVCorei18n.CREATEWORLD_INVALIDWORLDNAME),
WORLD_EXIST_FOLDER(MVCorei18n.CREATEWORLD_WORLDEXISTFOLDER), WORLD_EXIST_FOLDER(MVCorei18n.CREATEWORLD_WORLDEXISTFOLDER),
WORLD_EXIST_OFFLINE(MVCorei18n.CREATEWORLD_WORLDEXISTOFFLINE), WORLD_EXIST_UNLOADED(MVCorei18n.CREATEWORLD_WORLDEXISTUNLOADED),
WORLD_EXIST_LOADED(MVCorei18n.CREATEWORLD_WORLDEXISTLOADED), WORLD_EXIST_LOADED(MVCorei18n.CREATEWORLD_WORLDEXISTLOADED),
BUKKIT_CREATION_FAILED(MVCorei18n.CREATEWORLD_BUKKITCREATIONFAILED), BUKKIT_CREATION_FAILED(MVCorei18n.CREATEWORLD_BUKKITCREATIONFAILED),
; ;

View File

@ -25,7 +25,7 @@ public class ImportWorldResult {
public enum Failure implements FailureReason { public enum Failure implements FailureReason {
INVALID_WORLDNAME(MVCorei18n.IMPORTWORLD_INVALIDWORLDNAME), INVALID_WORLDNAME(MVCorei18n.IMPORTWORLD_INVALIDWORLDNAME),
WORLD_FOLDER_INVALID(MVCorei18n.IMPORTWORLD_WORLDFOLDERINVALID), WORLD_FOLDER_INVALID(MVCorei18n.IMPORTWORLD_WORLDFOLDERINVALID),
WORLD_EXIST_OFFLINE(MVCorei18n.IMPORTWORLD_WORLDEXISTOFFLINE), WORLD_EXIST_UNLOADED(MVCorei18n.IMPORTWORLD_WORLDEXISTUNLOADED),
WORLD_EXIST_LOADED(MVCorei18n.IMPORTWORLD_WORLDEXISTLOADED), WORLD_EXIST_LOADED(MVCorei18n.IMPORTWORLD_WORLDEXISTLOADED),
BUKKIT_CREATION_FAILED(MVCorei18n.IMPORTWORLD_BUKKITCREATIONFAILED), BUKKIT_CREATION_FAILED(MVCorei18n.IMPORTWORLD_BUKKITCREATIONFAILED),
; ;

View File

@ -26,7 +26,7 @@ public class UnloadWorldResult {
public enum Failure implements FailureReason { public enum Failure implements FailureReason {
WORLD_ALREADY_UNLOADING(MVCorei18n.UNLOADWORLD_WORLDALREADYUNLOADING), WORLD_ALREADY_UNLOADING(MVCorei18n.UNLOADWORLD_WORLDALREADYUNLOADING),
WORLD_NON_EXISTENT(MVCorei18n.UNLOADWORLD_WORLDNONEXISTENT), WORLD_NON_EXISTENT(MVCorei18n.UNLOADWORLD_WORLDNONEXISTENT),
WORLD_OFFLINE(MVCorei18n.UNLOADWORLD_WORLDOFFLINE), WORLD_UNLOADED(MVCorei18n.UNLOADWORLD_WORLDUNLOADED),
BUKKIT_UNLOAD_FAILED(MVCorei18n.UNLOADWORLD_BUKKITUNLOADFAILED), BUKKIT_UNLOAD_FAILED(MVCorei18n.UNLOADWORLD_BUKKITUNLOADFAILED),
; ;

View File

@ -127,14 +127,14 @@ mv-core.entrycheck.noworldaccess=you do not have permissions to access the world
mv-core.cloneworld.cloned=&aWorld '{world}' cloned to '{newworld}'! mv-core.cloneworld.cloned=&aWorld '{world}' cloned to '{newworld}'!
mv-core.cloneworld.invalidworldname=World '{world}' contains invalid characters! mv-core.cloneworld.invalidworldname=World '{world}' contains invalid characters!
mv-core.cloneworld.worldexistfolder=World '{world}' exists in server folders! You need to delete it first before cloning. mv-core.cloneworld.worldexistfolder=World '{world}' exists in server folders! You need to delete it first before cloning.
mv-core.cloneworld.worldexistoffline=World '{world}' already exists and it's unloaded! You need to delete it first before cloning. mv-core.cloneworld.worldexistunloaded=World '{world}' already exists and it's unloaded! You need to delete it first before cloning.
mv-core.cloneworld.worldexistloaded=World '{world}' already exists! You need to delete it first before cloning. mv-core.cloneworld.worldexistloaded=World '{world}' already exists! You need to delete it first before cloning.
mv-core.cloneworld.copyfailed=Failed to copy world '{world}' to '{newworld}': {error}\n&fSee console for more details. mv-core.cloneworld.copyfailed=Failed to copy world '{world}' to '{newworld}': {error}\n&fSee console for more details.
mv-core.createworld.created=&aWorld '{world}' created! mv-core.createworld.created=&aWorld '{world}' created!
mv-core.createworld.invalidworldname=World '{world}' contains invalid characters! mv-core.createworld.invalidworldname=World '{world}' contains invalid characters!
mv-core.createworld.worldexistfolder=World '{world}' already exists in server folders!&f Type '&a/mv import {world} <environment>&f' if you wish to import it. mv-core.createworld.worldexistfolder=World '{world}' already exists in server folders!&f Type '&a/mv import {world} <environment>&f' if you wish to import it.
mv-core.createworld.worldexistoffline=World '{world}' already exists, but it's not loaded!&f Type '&a/mv load {world}&f' if you wish to load it. mv-core.createworld.worldexistunloaded=World '{world}' already exists, but it's not loaded!&f Type '&a/mv load {world}&f' if you wish to load it.
mv-core.createworld.worldexistloaded=World '{world}' already exists! mv-core.createworld.worldexistloaded=World '{world}' already exists!
mv-core.createworld.bukkitcreationfailed=Bukkit failed to create world '{world}': {error}\n&fSee console for more details. mv-core.createworld.bukkitcreationfailed=Bukkit failed to create world '{world}': {error}\n&fSee console for more details.
@ -146,7 +146,7 @@ mv-core.deleteworld.failedtodeletefolder=Failed to delete world folder '{world}'
mv-core.importworld.imported=&aWorld '{world}' imported! mv-core.importworld.imported=&aWorld '{world}' imported!
mv-core.importworld.invalidworldname=World '{world}' contains invalid characters! mv-core.importworld.invalidworldname=World '{world}' contains invalid characters!
mv-core.importworld.worldexistoffline=World '{world}' already exists, but it's not loaded!&f Type '&a/mv load {world}&f' if you wish to load it. mv-core.importworld.worldexistunloaded=World '{world}' already exists, but it's not loaded!&f Type '&a/mv load {world}&f' if you wish to load it.
mv-core.importworld.worldexistloaded=World '{world}' already exists! mv-core.importworld.worldexistloaded=World '{world}' already exists!
mv-core.importworld.worldfolderinvalid=World '{world}' folder contents does not seem to be a valid world! mv-core.importworld.worldfolderinvalid=World '{world}' folder contents does not seem to be a valid world!
mv-core.importworld.bukkitcreationfailed=Bukkit failed to import world '{world}': {error}\n&fSee console for more details. mv-core.importworld.bukkitcreationfailed=Bukkit failed to import world '{world}': {error}\n&fSee console for more details.
@ -166,7 +166,7 @@ mv-core.removeworld.worldnonexistent=World '{world}' not found!
mv-core.unloadworld.unloaded=&aWorld '{world}' unloaded! mv-core.unloadworld.unloaded=&aWorld '{world}' unloaded!
mv-core.unloadworld.worldalreadyunloading=World '{world}' is already unloading! Please wait... mv-core.unloadworld.worldalreadyunloading=World '{world}' is already unloading! Please wait...
mv-core.unloadworld.worldnonexistent=World '{world}' does not exist! mv-core.unloadworld.worldnonexistent=World '{world}' does not exist!
mv-core.unloadworld.worldoffline=World '{world}' is already unloaded! mv-core.unloadworld.worldunloaded=World '{world}' is already unloaded!
mv-core.unloadworld.bukkitunloadfailed=Bukkit failed to unload world '{world}': {error}\n&fSee console for more details. mv-core.unloadworld.bukkitunloadfailed=Bukkit failed to unload world '{world}': {error}\n&fSee console for more details.
# generic # generic