Merge pull request #3001 from Multiverse/dtm/mv5/world-revamp-continue-patch

Apply basic checkstyle fixes.
This commit is contained in:
Ben Woo 2023-09-08 22:43:14 +08:00 committed by GitHub
commit 27ff3b7a7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 156 additions and 139 deletions

View File

@ -31,8 +31,7 @@ public class MVWorld extends OfflineWorld {
@NotNull WorldConfig worldConfig, @NotNull WorldConfig worldConfig,
@NotNull BlockSafety blockSafety, @NotNull BlockSafety blockSafety,
@NotNull SafeTTeleporter safeTTeleporter, @NotNull SafeTTeleporter safeTTeleporter,
@NotNull LocationManipulation locationManipulation @NotNull LocationManipulation locationManipulation) {
) {
super(world.getName(), worldConfig); super(world.getName(), worldConfig);
this.worldUid = world.getUID(); this.worldUid = world.getUID();
this.blockSafety = blockSafety; this.blockSafety = blockSafety;
@ -118,11 +117,11 @@ public class MVWorld extends OfflineWorld {
@Override @Override
public String toString() { public String toString() {
return "MVWorld{" + return "MVWorld{"
"name='" + worldName + "', " + + "name='" + worldName + "', "
"env='" + getEnvironment() + "', " + + "env='" + getEnvironment() + "', "
"type='" + getWorldType().getOrNull() + "', " + + "type='" + getWorldType().getOrNull() + "', "
"gen='" + getGenerator() + "'" + + "gen='" + getGenerator() + "'"
'}'; + '}';
} }
} }

View File

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

View File

@ -130,14 +130,13 @@ public class WorldManager {
* Load worlds that are already loaded by bukkit before Multiverse-Core is loaded. * Load worlds that are already loaded by bukkit before Multiverse-Core is loaded.
*/ */
private void loadDefaultWorlds() { private void loadDefaultWorlds() {
Bukkit.getWorlds().forEach((world) -> { Bukkit.getWorlds().forEach(world -> {
if (isOfflineWorld(world.getName())) { if (isOfflineWorld(world.getName())) {
return; return;
} }
importWorld(ImportWorldOptions.worldName(world.getName()) importWorld(ImportWorldOptions.worldName(world.getName())
.environment(world.getEnvironment()) .environment(world.getEnvironment())
.generator(generatorProvider.getDefaultGeneratorForWorld(world.getName())) .generator(generatorProvider.getDefaultGeneratorForWorld(world.getName())));
);
}); });
} }
@ -149,7 +148,7 @@ public class WorldManager {
if (isMVWorld(world) || !world.getAutoLoad()) { if (isMVWorld(world) || !world.getAutoLoad()) {
return; return;
} }
loadWorld(world).onFailure((failure) -> Logging.severe("Failed to load world %s: %s", world.getName(), failure)); loadWorld(world).onFailure(failure -> Logging.severe("Failed to load world %s: %s", world.getName(), failure));
}); });
} }
@ -161,17 +160,21 @@ public class WorldManager {
public Result<CreateWorldResult.Success, CreateWorldResult.Failure> createWorld(CreateWorldOptions options) { public Result<CreateWorldResult.Success, CreateWorldResult.Failure> createWorld(CreateWorldOptions options) {
// Params validations // Params validations
if (!worldNameChecker.isValidWorldName(options.worldName())) { if (!worldNameChecker.isValidWorldName(options.worldName())) {
return Result.failure(CreateWorldResult.Failure.INVALID_WORLDNAME, replace("{world}").with(options.worldName())); return Result.failure(CreateWorldResult.Failure.INVALID_WORLDNAME,
replace("{world}").with(options.worldName()));
} }
if (getMVWorld(options.worldName()).isDefined()) { if (getMVWorld(options.worldName()).isDefined()) {
return Result.failure(CreateWorldResult.Failure.WORLD_EXIST_LOADED, replace("{world}").with(options.worldName())); return Result.failure(CreateWorldResult.Failure.WORLD_EXIST_LOADED,
replace("{world}").with(options.worldName()));
} }
if (getOfflineWorld(options.worldName()).isDefined()) { if (getOfflineWorld(options.worldName()).isDefined()) {
return Result.failure(CreateWorldResult.Failure.WORLD_EXIST_OFFLINE, replace("{world}").with(options.worldName())); return Result.failure(CreateWorldResult.Failure.WORLD_EXIST_OFFLINE,
replace("{world}").with(options.worldName()));
} }
File worldFolder = new File(Bukkit.getWorldContainer(), options.worldName()); File worldFolder = new File(Bukkit.getWorldContainer(), options.worldName());
if (worldFolder.exists()) { if (worldFolder.exists()) {
return Result.failure(CreateWorldResult.Failure.WORLD_EXIST_FOLDER, replace("{world}").with(options.worldName())); return Result.failure(CreateWorldResult.Failure.WORLD_EXIST_FOLDER,
replace("{world}").with(options.worldName()));
} }
String parsedGenerator = parseGenerator(options.worldName(), options.generator()); String parsedGenerator = parseGenerator(options.worldName(), options.generator());
@ -180,17 +183,16 @@ public class WorldManager {
.generateStructures(options.generateStructures()) .generateStructures(options.generateStructures())
.generator(parsedGenerator) .generator(parsedGenerator)
.seed(options.seed()) .seed(options.seed())
.type(options.worldType()) .type(options.worldType()))
).fold( .fold(
(exception) -> Result.failure(CreateWorldResult.Failure.BUKKIT_CREATION_FAILED, exception -> Result.failure(CreateWorldResult.Failure.BUKKIT_CREATION_FAILED,
replace("{world}").with(options.worldName()), replace("{world}").with(options.worldName()),
replace("{error}").with(exception.getMessage()) replace("{error}").with(exception.getMessage())),
), world -> {
(world) -> {
newMVWorld(world, parsedGenerator, options.useSpawnAdjust()); newMVWorld(world, parsedGenerator, options.useSpawnAdjust());
return Result.success(CreateWorldResult.Success.CREATED, replace("{world}").with(world.getName())); return Result.success(CreateWorldResult.Success.CREATED,
} replace("{world}").with(world.getName()));
); });
} }
/** /**
@ -202,32 +204,35 @@ public class WorldManager {
public Result<ImportWorldResult.Success, ImportWorldResult.Failure> importWorld(ImportWorldOptions options) { public Result<ImportWorldResult.Success, ImportWorldResult.Failure> importWorld(ImportWorldOptions options) {
// Params validations // Params validations
if (!worldNameChecker.isValidWorldName(options.worldName())) { if (!worldNameChecker.isValidWorldName(options.worldName())) {
return Result.failure(ImportWorldResult.Failure.INVALID_WORLDNAME, replace("{world}").with(options.worldName())); return Result.failure(ImportWorldResult.Failure.INVALID_WORLDNAME,
replace("{world}").with(options.worldName()));
} }
if (!worldNameChecker.isValidWorldFolder(options.worldName())) { if (!worldNameChecker.isValidWorldFolder(options.worldName())) {
return Result.failure(ImportWorldResult.Failure.WORLD_FOLDER_INVALID, replace("{world}").with(options.worldName())); return Result.failure(ImportWorldResult.Failure.WORLD_FOLDER_INVALID,
replace("{world}").with(options.worldName()));
} }
if (isMVWorld(options.worldName())) { if (isMVWorld(options.worldName())) {
return Result.failure(ImportWorldResult.Failure.WORLD_EXIST_LOADED, replace("{world}").with(options.worldName())); return Result.failure(ImportWorldResult.Failure.WORLD_EXIST_LOADED,
replace("{world}").with(options.worldName()));
} }
if (isOfflineWorld(options.worldName())) { if (isOfflineWorld(options.worldName())) {
return Result.failure(ImportWorldResult.Failure.WORLD_EXIST_OFFLINE, replace("{world}").with(options.worldName())); return Result.failure(ImportWorldResult.Failure.WORLD_EXIST_OFFLINE,
replace("{world}").with(options.worldName()));
} }
String parsedGenerator = parseGenerator(options.worldName(), options.generator()); String parsedGenerator = parseGenerator(options.worldName(), options.generator());
return createBukkitWorld(WorldCreator.name(options.worldName()) return createBukkitWorld(WorldCreator.name(options.worldName())
.environment(options.environment()) .environment(options.environment())
.generator(parsedGenerator) .generator(parsedGenerator))
).fold( .fold(
(exception) -> Result.failure(ImportWorldResult.Failure.BUKKIT_CREATION_FAILED, exception -> Result.failure(ImportWorldResult.Failure.BUKKIT_CREATION_FAILED,
replace("{world}").with(options.worldName()), replace("{world}").with(options.worldName()),
replace("{error}").with(exception.getMessage()) replace("{error}").with(exception.getMessage())),
), world -> {
(world) -> {
newMVWorld(world, parsedGenerator, options.useSpawnAdjust()); newMVWorld(world, parsedGenerator, options.useSpawnAdjust());
return Result.success(ImportWorldResult.Success.IMPORTED, replace("{world}").with(options.worldName())); return Result.success(ImportWorldResult.Success.IMPORTED,
} replace("{world}").with(options.worldName()));
); });
} }
private @Nullable String parseGenerator(@NotNull String worldName, @Nullable String generator) { private @Nullable String parseGenerator(@NotNull String worldName, @Nullable String generator) {
@ -259,8 +264,10 @@ public class WorldManager {
return getOfflineWorld(worldName) return getOfflineWorld(worldName)
.map(this::loadWorld) .map(this::loadWorld)
.getOrElse(() -> worldNameChecker.isValidWorldFolder(worldName) .getOrElse(() -> worldNameChecker.isValidWorldFolder(worldName)
? Result.failure(LoadWorldResult.Failure.WORLD_EXIST_FOLDER, replace("{world}").with(worldName)) ? Result.failure(LoadWorldResult.Failure.WORLD_EXIST_FOLDER,
: Result.failure(LoadWorldResult.Failure.WORLD_NON_EXISTENT, replace("{world}").with(worldName))); replace("{world}").with(worldName))
: Result.failure(LoadWorldResult.Failure.WORLD_NON_EXISTENT,
replace("{world}").with(worldName)));
} }
/** /**
@ -274,30 +281,31 @@ public class WorldManager {
if (loadTracker.contains(offlineWorld.getName())) { if (loadTracker.contains(offlineWorld.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: " + offlineWorld.getName());
return Result.failure(LoadWorldResult.Failure.WORLD_ALREADY_LOADING, replace("{world}").with(offlineWorld.getName())); return Result.failure(LoadWorldResult.Failure.WORLD_ALREADY_LOADING,
replace("{world}").with(offlineWorld.getName()));
} }
if (isMVWorld(offlineWorld)) { if (isMVWorld(offlineWorld)) {
Logging.severe("World already loaded: " + offlineWorld.getName()); Logging.severe("World already loaded: " + offlineWorld.getName());
return Result.failure(LoadWorldResult.Failure.WORLD_EXIST_LOADED, replace("{world}").with(offlineWorld.getName())); return Result.failure(LoadWorldResult.Failure.WORLD_EXIST_LOADED,
replace("{world}").with(offlineWorld.getName()));
} }
return createBukkitWorld(WorldCreator.name(offlineWorld.getName()) return createBukkitWorld(WorldCreator.name(offlineWorld.getName())
.environment(offlineWorld.getEnvironment()) .environment(offlineWorld.getEnvironment())
.generator(Strings.isNullOrEmpty(offlineWorld.getGenerator()) ? null : offlineWorld.getGenerator()) .generator(Strings.isNullOrEmpty(offlineWorld.getGenerator()) ? null : offlineWorld.getGenerator())
.seed(offlineWorld.getSeed()) .seed(offlineWorld.getSeed())).fold(
).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(offlineWorld.getName()),
replace("{error}").with(exception.getMessage()) replace("{error}").with(exception.getMessage())),
), world -> {
(world) -> {
WorldConfig worldConfig = worldsConfigManager.getWorldConfig(offlineWorld.getName()); WorldConfig worldConfig = worldsConfigManager.getWorldConfig(offlineWorld.getName());
MVWorld mvWorld = new MVWorld(world, worldConfig, blockSafety, safeTTeleporter, locationManipulation); MVWorld mvWorld = new MVWorld(world, worldConfig, blockSafety,
safeTTeleporter, locationManipulation);
worldsMap.put(mvWorld.getName(), mvWorld); worldsMap.put(mvWorld.getName(), mvWorld);
saveWorldsConfig(); saveWorldsConfig();
return Result.success(LoadWorldResult.Success.LOADED, replace("{world}").with(mvWorld.getName())); return Result.success(LoadWorldResult.Success.LOADED,
} replace("{world}").with(mvWorld.getName()));
); });
} }
/** /**
@ -320,8 +328,10 @@ public class WorldManager {
return getMVWorld(worldName) return getMVWorld(worldName)
.map(this::unloadWorld) .map(this::unloadWorld)
.getOrElse(() -> isOfflineOnlyWorld(worldName) .getOrElse(() -> isOfflineOnlyWorld(worldName)
? Result.failure(UnloadWorldResult.Failure.WORLD_OFFLINE, replace("{world}").with(worldName)) ? Result.failure(UnloadWorldResult.Failure.WORLD_OFFLINE,
: Result.failure(UnloadWorldResult.Failure.WORLD_NON_EXISTENT, replace("{world}").with(worldName))); replace("{world}").with(worldName))
: Result.failure(UnloadWorldResult.Failure.WORLD_NON_EXISTENT,
replace("{world}").with(worldName)));
} }
/** /**
@ -334,28 +344,28 @@ public class WorldManager {
if (unloadTracker.contains(world.getName())) { if (unloadTracker.contains(world.getName())) {
// This is to prevent recursive calls by WorldUnloadEvent // This is to prevent recursive calls by WorldUnloadEvent
Logging.fine("World already unloading: " + world.getName()); Logging.fine("World already unloading: " + world.getName());
return Result.failure(UnloadWorldResult.Failure.WORLD_ALREADY_UNLOADING, replace("{world}").with(world.getName())); return Result.failure(UnloadWorldResult.Failure.WORLD_ALREADY_UNLOADING,
replace("{world}").with(world.getName()));
} }
// TODO: removePlayersFromWorld? // TODO: removePlayersFromWorld?
return unloadBukkitWorld(world.getBukkitWorld().getOrNull()).fold( return unloadBukkitWorld(world.getBukkitWorld().getOrNull()).fold(
(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(worldsMap.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, replace("{world}").with(world.getName())); return Result.failure(UnloadWorldResult.Failure.WORLD_NON_EXISTENT,
replace("{world}").with(world.getName()));
}, },
(mvWorld) -> { mvWorld -> {
Logging.fine("Removed MVWorld from map: " + world.getName()); Logging.fine("Removed MVWorld from map: " + world.getName());
mvWorld.getWorldConfig().deferenceMVWorld(); mvWorld.getWorldConfig().deferenceMVWorld();
return Result.success(UnloadWorldResult.Success.UNLOADED, replace("{world}").with(world.getName())); return Result.success(UnloadWorldResult.Success.UNLOADED,
} replace("{world}").with(world.getName()));
) }));
);
} }
/** /**
@ -381,13 +391,12 @@ public class WorldManager {
public Result<RemoveWorldResult.Success, RemoveWorldResult.Failure> removeWorld(@NotNull OfflineWorld world) { public Result<RemoveWorldResult.Success, RemoveWorldResult.Failure> removeWorld(@NotNull OfflineWorld world) {
return getMVWorld(world).fold( return getMVWorld(world).fold(
() -> removeWorldFromConfig(world), () -> removeWorldFromConfig(world),
this::removeWorld this::removeWorld);
);
} }
/** /**
* 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 offline
* World files will not be deleted. * 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.
@ -406,7 +415,8 @@ public class WorldManager {
* @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.
*/ */
private Result<RemoveWorldResult.Success, RemoveWorldResult.Failure> removeWorldFromConfig(@NotNull OfflineWorld world) { private Result<RemoveWorldResult.Success, RemoveWorldResult.Failure>
removeWorldFromConfig(@NotNull OfflineWorld world) {
// Remove world from config // Remove world from config
offlineWorldsMap.remove(world.getName()); offlineWorldsMap.remove(world.getName());
worldsConfigManager.deleteWorldConfig(world.getName()); worldsConfigManager.deleteWorldConfig(world.getName());
@ -425,7 +435,8 @@ public class WorldManager {
public Result<DeleteWorldResult.Success, DeleteWorldResult.Failure> deleteWorld(@NotNull String worldName) { public Result<DeleteWorldResult.Success, DeleteWorldResult.Failure> deleteWorld(@NotNull String worldName) {
return getOfflineWorld(worldName) return getOfflineWorld(worldName)
.map(this::deleteWorld) .map(this::deleteWorld)
.getOrElse(() -> Result.failure(DeleteWorldResult.Failure.WORLD_NON_EXISTENT, replace("{world}").with(worldName))); .getOrElse(() -> Result.failure(DeleteWorldResult.Failure.WORLD_NON_EXISTENT,
replace("{world}").with(worldName)));
} }
/** /**
@ -440,12 +451,12 @@ public class WorldManager {
() -> { () -> {
var result = loadWorld(world); var result = loadWorld(world);
if (result.isFailure()) { if (result.isFailure()) {
return Result.failure(DeleteWorldResult.Failure.LOAD_FAILED, replace("{world}").with(world.getName())); return Result.failure(DeleteWorldResult.Failure.LOAD_FAILED,
replace("{world}").with(world.getName()));
} }
return deleteWorld(world); return deleteWorld(world);
}, },
this::deleteWorld this::deleteWorld);
);
} }
/** /**
@ -458,7 +469,8 @@ public class WorldManager {
File worldFolder = world.getBukkitWorld().map(World::getWorldFolder).getOrNull(); File worldFolder = world.getBukkitWorld().map(World::getWorldFolder).getOrNull();
if (worldFolder == null || !worldNameChecker.isValidWorldFolder(worldFolder)) { if (worldFolder == null || !worldNameChecker.isValidWorldFolder(worldFolder)) {
Logging.severe("Failed to get world folder for world: " + world.getName()); Logging.severe("Failed to get world folder for world: " + world.getName());
return Result.failure(DeleteWorldResult.Failure.WORLD_FOLDER_NOT_FOUND, replace("{world}").with(world.getName())); return Result.failure(DeleteWorldResult.Failure.WORLD_FOLDER_NOT_FOUND,
replace("{world}").with(world.getName()));
} }
var result = removeWorld(world); var result = removeWorld(world);
@ -469,12 +481,11 @@ public class WorldManager {
// Erase world files from disk // Erase world files from disk
// TODO: Possible config options to keep certain files // TODO: Possible config options to keep certain files
return filesManipulator.deleteFolder(worldFolder).fold( return filesManipulator.deleteFolder(worldFolder).fold(
(exception) -> Result.failure(DeleteWorldResult.Failure.FAILED_TO_DELETE_FOLDER, exception -> Result.failure(DeleteWorldResult.Failure.FAILED_TO_DELETE_FOLDER,
replace("{world}").with(world.getName()), replace("{world}").with(world.getName()),
replace("{error}").with(exception.getMessage()) replace("{error}").with(exception.getMessage())),
), success -> Result.success(DeleteWorldResult.Success.DELETED,
(success) -> Result.success(DeleteWorldResult.Success.DELETED, replace("{world}").with(world.getName())) replace("{world}").with(world.getName())));
);
} }
/** /**
@ -488,24 +499,24 @@ public class WorldManager {
.onSuccessThen(s -> importWorld( .onSuccessThen(s -> importWorld(
ImportWorldOptions.worldName(options.newWorldName()) ImportWorldOptions.worldName(options.newWorldName())
.environment(options.world().getEnvironment()) .environment(options.world().getEnvironment())
.generator(options.world().getGenerator()) .generator(options.world().getGenerator()))
).fold( .fold(
failure -> Result.failure(CloneWorldResult.Failure.IMPORT_FAILED, failure.getReasonMessage()), failure -> Result.failure(CloneWorldResult.Failure.IMPORT_FAILED, failure.getReasonMessage()),
success -> Result.success() success -> Result.success()))
))
.onSuccessThen(s -> getMVWorld(options.newWorldName()).fold( .onSuccessThen(s -> getMVWorld(options.newWorldName()).fold(
() -> Result.failure(CloneWorldResult.Failure.MV_WORLD_FAILED, replace("{world}").with(options.newWorldName())), () -> Result.failure(CloneWorldResult.Failure.MV_WORLD_FAILED,
replace("{world}").with(options.newWorldName())),
mvWorld -> { mvWorld -> {
cloneWorldTransferData(options, mvWorld); cloneWorldTransferData(options, mvWorld);
saveWorldsConfig(); saveWorldsConfig();
return Result.success(CloneWorldResult.Success.CLONED, return Result.success(CloneWorldResult.Success.CLONED,
replace("{world}").with(options.world().getName()), replace("{world}").with(options.world().getName()),
replace("{newworld}").with(mvWorld.getName())); replace("{newworld}").with(mvWorld.getName()));
} }));
));
} }
private Result<CloneWorldResult.Success, CloneWorldResult.Failure> cloneWorldValidateWorld(@NotNull CloneWorldOptions options) { private Result<CloneWorldResult.Success, CloneWorldResult.Failure>
cloneWorldValidateWorld(@NotNull CloneWorldOptions options) {
String newWorldName = options.newWorldName(); String newWorldName = options.newWorldName();
if (!worldNameChecker.isValidWorldName(newWorldName)) { if (!worldNameChecker.isValidWorldName(newWorldName)) {
Logging.severe("Invalid world name: " + newWorldName); Logging.severe("Invalid world name: " + newWorldName);
@ -525,14 +536,15 @@ public class WorldManager {
return Result.success(); return Result.success();
} }
private Result<CloneWorldResult.Success, CloneWorldResult.Failure> cloneWorldCopyFolder(@NotNull CloneWorldOptions options) { private Result<CloneWorldResult.Success, CloneWorldResult.Failure>
cloneWorldCopyFolder(@NotNull CloneWorldOptions options) {
File worldFolder = options.world().getBukkitWorld().map(World::getWorldFolder).getOrNull(); // TODO: Check null? File worldFolder = options.world().getBukkitWorld().map(World::getWorldFolder).getOrNull(); // TODO: Check null?
File newWorldFolder = new File(Bukkit.getWorldContainer(), options.newWorldName()); File newWorldFolder = new File(Bukkit.getWorldContainer(), options.newWorldName());
return filesManipulator.copyFolder(worldFolder, newWorldFolder, CLONE_IGNORE_FILES).fold( return filesManipulator.copyFolder(worldFolder, newWorldFolder, CLONE_IGNORE_FILES).fold(
(exception) -> Result.failure(CloneWorldResult.Failure.COPY_FAILED, exception -> Result.failure(CloneWorldResult.Failure.COPY_FAILED,
replace("{world}").with(options.world().getName()), replace("{world}").with(options.world().getName()),
replace("{error}").with(exception.getMessage())), replace("{error}").with(exception.getMessage())),
(success) -> Result.success()); success -> Result.success());
} }
private void cloneWorldTransferData(@NotNull CloneWorldOptions options, @NotNull MVWorld newWorld) { private void cloneWorldTransferData(@NotNull CloneWorldOptions options, @NotNull MVWorld newWorld) {

View File

@ -77,8 +77,7 @@ public class WorldPurger {
List<LivingEntity> livingEntities = new ArrayList<LivingEntity>(worldEntities.size()); List<LivingEntity> livingEntities = new ArrayList<LivingEntity>(worldEntities.size());
List<Projectile> projectiles = new ArrayList<Projectile>(worldEntities.size()); List<Projectile> projectiles = new ArrayList<Projectile>(worldEntities.size());
for (final Entity e : worldEntities) { for (final Entity e : worldEntities) {
if (e instanceof Projectile) { if (e instanceof Projectile p) {
final Projectile p = (Projectile) e;
if (p.getShooter() != null) { if (p.getShooter() != null) {
projectiles.add((Projectile) e); projectiles.add((Projectile) e);
} }
@ -149,7 +148,8 @@ public class WorldPurger {
return false; return false;
} }
public boolean shouldWeKillThisCreature(Entity e, List<String> thingsToKill, boolean negateAnimals, boolean negateMonsters) { public boolean shouldWeKillThisCreature(Entity e, List<String> thingsToKill,
boolean negateAnimals, boolean negateMonsters) {
boolean specifiedAll = thingsToKill.contains("ALL"); boolean specifiedAll = thingsToKill.contains("ALL");
boolean specifiedAnimals = thingsToKill.contains("ANIMALS") || specifiedAll; boolean specifiedAnimals = thingsToKill.contains("ANIMALS") || specifiedAll;
boolean specifiedMonsters = thingsToKill.contains("MONSTERS") || specifiedAll; boolean specifiedMonsters = thingsToKill.contains("MONSTERS") || specifiedAll;

View File

@ -20,7 +20,7 @@ public final class NullLocation extends SpawnLocation {
@Override @Override
public Location clone() { public Location clone() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
}; }
@Override @Override
public Map<String, Object> serialize() { public Map<String, Object> serialize() {
@ -44,10 +44,10 @@ public final class NullLocation extends SpawnLocation {
@Override @Override
public int hashCode() { public int hashCode() {
return -1; return -1;
}; }
@Override @Override
public String toString() { public String toString() {
return "Location{null}"; return "Location{null}";
}; }
} }

View File

@ -2,7 +2,6 @@ package com.onarandombox.MultiverseCore.worldnew.config;
import com.dumptruckman.minecraft.util.Logging; import com.dumptruckman.minecraft.util.Logging;
import com.onarandombox.MultiverseCore.configuration.handle.ConfigurationSectionHandle; import com.onarandombox.MultiverseCore.configuration.handle.ConfigurationSectionHandle;
import com.onarandombox.MultiverseCore.configuration.node.NodeGroup;
import com.onarandombox.MultiverseCore.world.configuration.AllowedPortalType; import com.onarandombox.MultiverseCore.world.configuration.AllowedPortalType;
import com.onarandombox.MultiverseCore.worldnew.MVWorld; import com.onarandombox.MultiverseCore.worldnew.MVWorld;
import io.vavr.control.Try; import io.vavr.control.Try;
@ -18,7 +17,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
public class WorldConfig { public final class WorldConfig {
private final String worldName; private final String worldName;
private final WorldConfigNodes configNodes; private final WorldConfigNodes configNodes;

View File

@ -49,7 +49,7 @@ public class WorldConfigNodes {
.defaultValue(true) .defaultValue(true)
.name("allow-weather") .name("allow-weather")
.onSetValue((oldValue, newValue) -> { .onSetValue((oldValue, newValue) -> {
if (world == null) { return; } if (world == null) return;
world.getBukkitWorld().peek(world -> { world.getBukkitWorld().peek(world -> {
if (!world.isClearWeather() && !newValue) { if (!world.isClearWeather() && !newValue) {
world.setThundering(false); world.setThundering(false);
@ -78,7 +78,7 @@ public class WorldConfigNodes {
.defaultValue(Difficulty.NORMAL) .defaultValue(Difficulty.NORMAL)
.name("difficulty") .name("difficulty")
.onSetValue((oldValue, newValue) -> { .onSetValue((oldValue, newValue) -> {
if (world == null) { return; } if (world == null) return;
world.getBukkitWorld().peek(world -> world.setDifficulty(newValue)); world.getBukkitWorld().peek(world -> world.setDifficulty(newValue));
}) })
.build()); .build());
@ -93,7 +93,8 @@ public class WorldConfigNodes {
.name("entryfee-currency") .name("entryfee-currency")
.build()); .build());
public final ConfigNode<World.Environment> ENVIRONMENT = node(ConfigNode.builder("environment", World.Environment.class) public final ConfigNode<World.Environment> ENVIRONMENT = node(ConfigNode
.builder("environment", World.Environment.class)
.defaultValue(World.Environment.NORMAL) .defaultValue(World.Environment.NORMAL)
.name("environment") .name("environment")
.build()); .build());
@ -118,11 +119,12 @@ public class WorldConfigNodes {
.name("hunger") .name("hunger")
.build()); .build());
public final ConfigNode<Boolean> KEEP_SPAWN_IN_MEMORY = node(ConfigNode.builder("keep-spawn-in-memory", Boolean.class) public final ConfigNode<Boolean> KEEP_SPAWN_IN_MEMORY = node(ConfigNode
.builder("keep-spawn-in-memory", Boolean.class)
.defaultValue(true) .defaultValue(true)
.name("keep-spawn-in-memory") .name("keep-spawn-in-memory")
.onSetValue((oldValue, newValue) -> { .onSetValue((oldValue, newValue) -> {
if (world == null) { return; } if (world == null) return;
world.getBukkitWorld().peek(world -> world.setKeepSpawnInMemory(newValue)); world.getBukkitWorld().peek(world -> world.setKeepSpawnInMemory(newValue));
}) })
.build()); .build());
@ -132,7 +134,8 @@ public class WorldConfigNodes {
.name("player-limit") .name("player-limit")
.build()); .build());
public final ConfigNode<AllowedPortalType> PORTAL_FORM = node(ConfigNode.builder("portal-form", AllowedPortalType.class) public final ConfigNode<AllowedPortalType> PORTAL_FORM = node(ConfigNode
.builder("portal-form", AllowedPortalType.class)
.defaultValue(AllowedPortalType.ALL) .defaultValue(AllowedPortalType.ALL)
.name("portal-form") .name("portal-form")
.build()); .build());
@ -141,7 +144,7 @@ public class WorldConfigNodes {
.defaultValue(true) .defaultValue(true)
.name("pvp") .name("pvp")
.onSetValue((oldValue, newValue) -> { .onSetValue((oldValue, newValue) -> {
if (world == null) { return; } if (world == null) return;
world.getBukkitWorld().peek(world -> world.setPVP(newValue)); world.getBukkitWorld().peek(world -> world.setPVP(newValue));
}) })
.build()); .build());
@ -165,7 +168,7 @@ public class WorldConfigNodes {
.defaultValue(new NullLocation()) .defaultValue(new NullLocation())
.name("spawn-location") .name("spawn-location")
.onSetValue((oldValue, newValue) -> { .onSetValue((oldValue, newValue) -> {
if (world == null) { return; } if (world == null) return;
world.getBukkitWorld().peek(world -> { world.getBukkitWorld().peek(world -> {
world.setSpawnLocation(newValue.getBlockX(), newValue.getBlockY(), newValue.getBlockZ()); world.setSpawnLocation(newValue.getBlockX(), newValue.getBlockY(), newValue.getBlockZ());
newValue.setWorld(world); newValue.setWorld(world);
@ -177,44 +180,49 @@ public class WorldConfigNodes {
.defaultValue(true) .defaultValue(true)
.name("spawning-animals") .name("spawning-animals")
.onSetValue((oldValue, newValue) -> { .onSetValue((oldValue, newValue) -> {
if (world == null) { return; } if (world == null) return;
world.getBukkitWorld().peek(world -> world.setSpawnFlags(world.getAllowMonsters(), newValue)); world.getBukkitWorld().peek(world -> world.setSpawnFlags(world.getAllowMonsters(), newValue));
}) })
.build()); .build());
public final ConfigNode<Integer> SPAWNING_ANIMALS_TICKS = node(ConfigNode.builder("spawning.animals.tick-rate", Integer.class) public final ConfigNode<Integer> SPAWNING_ANIMALS_TICKS = node(ConfigNode
.builder("spawning.animals.tick-rate", Integer.class)
.defaultValue(-1) .defaultValue(-1)
.name("spawning-animals-ticks") .name("spawning-animals-ticks")
.onSetValue((oldValue, newValue) -> { .onSetValue((oldValue, newValue) -> {
if (world == null) { return; } if (world == null) return;
world.getBukkitWorld().peek(world -> world.setTicksPerAnimalSpawns(newValue)); world.getBukkitWorld().peek(world -> world.setTicksPerAnimalSpawns(newValue));
}) })
.build()); .build());
public final ConfigNode<List> SPAWNING_ANIMALS_EXCEPTIONS = node(ConfigNode.builder("spawning.animals.exceptions", List.class) public final ConfigNode<List> SPAWNING_ANIMALS_EXCEPTIONS = node(ConfigNode
.builder("spawning.animals.exceptions", List.class)
.defaultValue(new ArrayList<>()) .defaultValue(new ArrayList<>())
.name("spawning-animals-exceptions") .name("spawning-animals-exceptions")
.build()); .build());
public final ConfigNode<Boolean> SPAWNING_MONSTERS = node(ConfigNode.builder("spawning.monsters.spawn", Boolean.class) public final ConfigNode<Boolean> SPAWNING_MONSTERS = node(ConfigNode
.builder("spawning.monsters.spawn", Boolean.class)
.defaultValue(true) .defaultValue(true)
.name("spawning-monsters") .name("spawning-monsters")
.onSetValue((oldValue, newValue) -> { .onSetValue((oldValue, newValue) -> {
if (world == null) { return; } if (world == null) return;
world.getBukkitWorld().peek(world -> world.setSpawnFlags(newValue, world.getAllowAnimals())); world.getBukkitWorld().peek(world -> world.setSpawnFlags(newValue, world.getAllowAnimals()));
}) })
.build()); .build());
public final ConfigNode<Integer> SPAWNING_MONSTERS_TICKS = node(ConfigNode.builder("spawning.monsters.tick-rate", Integer.class) public final ConfigNode<Integer> SPAWNING_MONSTERS_TICKS = node(ConfigNode
.builder("spawning.monsters.tick-rate", Integer.class)
.defaultValue(-1) .defaultValue(-1)
.name("spawning-monsters-ticks") .name("spawning-monsters-ticks")
.onSetValue((oldValue, newValue) -> { .onSetValue((oldValue, newValue) -> {
if (world == null) { return; } if (world == null) return;
world.getBukkitWorld().peek(world -> world.setTicksPerMonsterSpawns(newValue)); world.getBukkitWorld().peek(world -> world.setTicksPerMonsterSpawns(newValue));
}) })
.build()); .build());
public final ConfigNode<List> SPAWNING_MONSTERS_EXCEPTIONS = node(ConfigNode.builder("spawning.monsters.exceptions", List.class) public final ConfigNode<List> SPAWNING_MONSTERS_EXCEPTIONS = node(ConfigNode
.builder("spawning.monsters.exceptions", List.class)
.defaultValue(new ArrayList<>()) .defaultValue(new ArrayList<>())
.name("spawning-monsters-exceptions") .name("spawning-monsters-exceptions")
.build()); .build());

View File

@ -15,7 +15,7 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
@Service @Service
public class WorldsConfigManager { public final class WorldsConfigManager {
private static final String CONFIG_FILENAME = "worlds2.yml"; private static final String CONFIG_FILENAME = "worlds2.yml";
private final Map<String, WorldConfig> worldConfigMap; private final Map<String, WorldConfig> worldConfigMap;

View File

@ -2,7 +2,6 @@ package com.onarandombox.MultiverseCore.worldnew.helpers;
import com.dumptruckman.minecraft.util.Logging; import com.dumptruckman.minecraft.util.Logging;
import com.onarandombox.MultiverseCore.worldnew.MVWorld; import com.onarandombox.MultiverseCore.worldnew.MVWorld;
import com.onarandombox.MultiverseCore.worldnew.OfflineWorld;
import org.bukkit.GameRule; import org.bukkit.GameRule;
import org.bukkit.World; import org.bukkit.World;
import org.jvnet.hk2.annotations.Service; import org.jvnet.hk2.annotations.Service;