mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-25 20:16:06 +01:00
Merge pull request #3001 from Multiverse/dtm/mv5/world-revamp-continue-patch
Apply basic checkstyle fixes.
This commit is contained in:
commit
27ff3b7a7b
@ -31,8 +31,7 @@ public class MVWorld extends OfflineWorld {
|
||||
@NotNull WorldConfig worldConfig,
|
||||
@NotNull BlockSafety blockSafety,
|
||||
@NotNull SafeTTeleporter safeTTeleporter,
|
||||
@NotNull LocationManipulation locationManipulation
|
||||
) {
|
||||
@NotNull LocationManipulation locationManipulation) {
|
||||
super(world.getName(), worldConfig);
|
||||
this.worldUid = world.getUID();
|
||||
this.blockSafety = blockSafety;
|
||||
@ -118,11 +117,11 @@ public class MVWorld extends OfflineWorld {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MVWorld{" +
|
||||
"name='" + worldName + "', " +
|
||||
"env='" + getEnvironment() + "', " +
|
||||
"type='" + getWorldType().getOrNull() + "', " +
|
||||
"gen='" + getGenerator() + "'" +
|
||||
'}';
|
||||
return "MVWorld{"
|
||||
+ "name='" + worldName + "', "
|
||||
+ "env='" + getEnvironment() + "', "
|
||||
+ "type='" + getWorldType().getOrNull() + "', "
|
||||
+ "gen='" + getGenerator() + "'"
|
||||
+ '}';
|
||||
}
|
||||
}
|
||||
|
@ -300,10 +300,10 @@ public class OfflineWorld {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "OfflineWorld{" +
|
||||
"name='" + worldName + "', " +
|
||||
"env='" + getEnvironment() + "', " +
|
||||
"gen='" + getGenerator() + "'" +
|
||||
'}';
|
||||
return "OfflineWorld{"
|
||||
+ "name='" + worldName + "', "
|
||||
+ "env='" + getEnvironment() + "', "
|
||||
+ "gen='" + getGenerator() + "'"
|
||||
+ '}';
|
||||
}
|
||||
}
|
||||
|
@ -130,14 +130,13 @@ public class WorldManager {
|
||||
* Load worlds that are already loaded by bukkit before Multiverse-Core is loaded.
|
||||
*/
|
||||
private void loadDefaultWorlds() {
|
||||
Bukkit.getWorlds().forEach((world) -> {
|
||||
Bukkit.getWorlds().forEach(world -> {
|
||||
if (isOfflineWorld(world.getName())) {
|
||||
return;
|
||||
}
|
||||
importWorld(ImportWorldOptions.worldName(world.getName())
|
||||
.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()) {
|
||||
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) {
|
||||
// Params validations
|
||||
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()) {
|
||||
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()) {
|
||||
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());
|
||||
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());
|
||||
@ -180,17 +183,16 @@ public class WorldManager {
|
||||
.generateStructures(options.generateStructures())
|
||||
.generator(parsedGenerator)
|
||||
.seed(options.seed())
|
||||
.type(options.worldType())
|
||||
).fold(
|
||||
(exception) -> Result.failure(CreateWorldResult.Failure.BUKKIT_CREATION_FAILED,
|
||||
replace("{world}").with(options.worldName()),
|
||||
replace("{error}").with(exception.getMessage())
|
||||
),
|
||||
(world) -> {
|
||||
newMVWorld(world, parsedGenerator, options.useSpawnAdjust());
|
||||
return Result.success(CreateWorldResult.Success.CREATED, replace("{world}").with(world.getName()));
|
||||
}
|
||||
);
|
||||
.type(options.worldType()))
|
||||
.fold(
|
||||
exception -> Result.failure(CreateWorldResult.Failure.BUKKIT_CREATION_FAILED,
|
||||
replace("{world}").with(options.worldName()),
|
||||
replace("{error}").with(exception.getMessage())),
|
||||
world -> {
|
||||
newMVWorld(world, parsedGenerator, options.useSpawnAdjust());
|
||||
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) {
|
||||
// Params validations
|
||||
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())) {
|
||||
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())) {
|
||||
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())) {
|
||||
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());
|
||||
return createBukkitWorld(WorldCreator.name(options.worldName())
|
||||
.environment(options.environment())
|
||||
.generator(parsedGenerator)
|
||||
).fold(
|
||||
(exception) -> Result.failure(ImportWorldResult.Failure.BUKKIT_CREATION_FAILED,
|
||||
replace("{world}").with(options.worldName()),
|
||||
replace("{error}").with(exception.getMessage())
|
||||
),
|
||||
(world) -> {
|
||||
newMVWorld(world, parsedGenerator, options.useSpawnAdjust());
|
||||
return Result.success(ImportWorldResult.Success.IMPORTED, replace("{world}").with(options.worldName()));
|
||||
}
|
||||
);
|
||||
.generator(parsedGenerator))
|
||||
.fold(
|
||||
exception -> Result.failure(ImportWorldResult.Failure.BUKKIT_CREATION_FAILED,
|
||||
replace("{world}").with(options.worldName()),
|
||||
replace("{error}").with(exception.getMessage())),
|
||||
world -> {
|
||||
newMVWorld(world, parsedGenerator, options.useSpawnAdjust());
|
||||
return Result.success(ImportWorldResult.Success.IMPORTED,
|
||||
replace("{world}").with(options.worldName()));
|
||||
});
|
||||
}
|
||||
|
||||
private @Nullable String parseGenerator(@NotNull String worldName, @Nullable String generator) {
|
||||
@ -259,8 +264,10 @@ public class WorldManager {
|
||||
return getOfflineWorld(worldName)
|
||||
.map(this::loadWorld)
|
||||
.getOrElse(() -> worldNameChecker.isValidWorldFolder(worldName)
|
||||
? Result.failure(LoadWorldResult.Failure.WORLD_EXIST_FOLDER, replace("{world}").with(worldName))
|
||||
: Result.failure(LoadWorldResult.Failure.WORLD_NON_EXISTENT, replace("{world}").with(worldName)));
|
||||
? Result.failure(LoadWorldResult.Failure.WORLD_EXIST_FOLDER,
|
||||
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())) {
|
||||
// This is to prevent recursive calls by WorldLoadEvent
|
||||
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)) {
|
||||
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())
|
||||
.environment(offlineWorld.getEnvironment())
|
||||
.generator(Strings.isNullOrEmpty(offlineWorld.getGenerator()) ? null : offlineWorld.getGenerator())
|
||||
.seed(offlineWorld.getSeed())
|
||||
).fold(
|
||||
(exception) -> Result.failure(LoadWorldResult.Failure.BUKKIT_CREATION_FAILED,
|
||||
replace("{world}").with(offlineWorld.getName()),
|
||||
replace("{error}").with(exception.getMessage())
|
||||
),
|
||||
(world) -> {
|
||||
WorldConfig worldConfig = worldsConfigManager.getWorldConfig(offlineWorld.getName());
|
||||
MVWorld mvWorld = new MVWorld(world, worldConfig, blockSafety, safeTTeleporter, locationManipulation);
|
||||
worldsMap.put(mvWorld.getName(), mvWorld);
|
||||
saveWorldsConfig();
|
||||
return Result.success(LoadWorldResult.Success.LOADED, replace("{world}").with(mvWorld.getName()));
|
||||
}
|
||||
);
|
||||
.seed(offlineWorld.getSeed())).fold(
|
||||
exception -> Result.failure(LoadWorldResult.Failure.BUKKIT_CREATION_FAILED,
|
||||
replace("{world}").with(offlineWorld.getName()),
|
||||
replace("{error}").with(exception.getMessage())),
|
||||
world -> {
|
||||
WorldConfig worldConfig = worldsConfigManager.getWorldConfig(offlineWorld.getName());
|
||||
MVWorld mvWorld = new MVWorld(world, worldConfig, blockSafety,
|
||||
safeTTeleporter, locationManipulation);
|
||||
worldsMap.put(mvWorld.getName(), mvWorld);
|
||||
saveWorldsConfig();
|
||||
return Result.success(LoadWorldResult.Success.LOADED,
|
||||
replace("{world}").with(mvWorld.getName()));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -320,8 +328,10 @@ public class WorldManager {
|
||||
return getMVWorld(worldName)
|
||||
.map(this::unloadWorld)
|
||||
.getOrElse(() -> isOfflineOnlyWorld(worldName)
|
||||
? Result.failure(UnloadWorldResult.Failure.WORLD_OFFLINE, replace("{world}").with(worldName))
|
||||
: Result.failure(UnloadWorldResult.Failure.WORLD_NON_EXISTENT, replace("{world}").with(worldName)));
|
||||
? Result.failure(UnloadWorldResult.Failure.WORLD_OFFLINE,
|
||||
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())) {
|
||||
// This is to prevent recursive calls by WorldUnloadEvent
|
||||
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?
|
||||
|
||||
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("{error}").with(exception.getMessage())
|
||||
),
|
||||
(success) -> Option.of(worldsMap.remove(world.getName())).fold(
|
||||
replace("{error}").with(exception.getMessage())),
|
||||
success -> Option.of(worldsMap.remove(world.getName())).fold(
|
||||
() -> {
|
||||
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());
|
||||
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) {
|
||||
return getMVWorld(world).fold(
|
||||
() -> 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.
|
||||
* World files will not be deleted.
|
||||
* Removes an existing multiverse world. It will be deleted from the worlds config and will no longer be an offline
|
||||
* world. World files will not be deleted.
|
||||
*
|
||||
* @param world The multiverse world to remove.
|
||||
* @return The result of the remove.
|
||||
@ -406,7 +415,8 @@ public class WorldManager {
|
||||
* @param world The multiverse world to 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
|
||||
offlineWorldsMap.remove(world.getName());
|
||||
worldsConfigManager.deleteWorldConfig(world.getName());
|
||||
@ -425,7 +435,8 @@ public class WorldManager {
|
||||
public Result<DeleteWorldResult.Success, DeleteWorldResult.Failure> deleteWorld(@NotNull String worldName) {
|
||||
return getOfflineWorld(worldName)
|
||||
.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);
|
||||
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);
|
||||
},
|
||||
this::deleteWorld
|
||||
);
|
||||
this::deleteWorld);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -458,7 +469,8 @@ public class WorldManager {
|
||||
File worldFolder = world.getBukkitWorld().map(World::getWorldFolder).getOrNull();
|
||||
if (worldFolder == null || !worldNameChecker.isValidWorldFolder(worldFolder)) {
|
||||
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);
|
||||
@ -469,12 +481,11 @@ public class WorldManager {
|
||||
// Erase world files from disk
|
||||
// TODO: Possible config options to keep certain files
|
||||
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("{error}").with(exception.getMessage())
|
||||
),
|
||||
(success) -> Result.success(DeleteWorldResult.Success.DELETED, replace("{world}").with(world.getName()))
|
||||
);
|
||||
replace("{error}").with(exception.getMessage())),
|
||||
success -> Result.success(DeleteWorldResult.Success.DELETED,
|
||||
replace("{world}").with(world.getName())));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -488,24 +499,24 @@ public class WorldManager {
|
||||
.onSuccessThen(s -> importWorld(
|
||||
ImportWorldOptions.worldName(options.newWorldName())
|
||||
.environment(options.world().getEnvironment())
|
||||
.generator(options.world().getGenerator())
|
||||
).fold(
|
||||
failure -> Result.failure(CloneWorldResult.Failure.IMPORT_FAILED, failure.getReasonMessage()),
|
||||
success -> Result.success()
|
||||
))
|
||||
.generator(options.world().getGenerator()))
|
||||
.fold(
|
||||
failure -> Result.failure(CloneWorldResult.Failure.IMPORT_FAILED, failure.getReasonMessage()),
|
||||
success -> Result.success()))
|
||||
.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 -> {
|
||||
cloneWorldTransferData(options, mvWorld);
|
||||
saveWorldsConfig();
|
||||
return Result.success(CloneWorldResult.Success.CLONED,
|
||||
replace("{world}").with(options.world().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();
|
||||
if (!worldNameChecker.isValidWorldName(newWorldName)) {
|
||||
Logging.severe("Invalid world name: " + newWorldName);
|
||||
@ -525,14 +536,15 @@ public class WorldManager {
|
||||
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 newWorldFolder = new File(Bukkit.getWorldContainer(), options.newWorldName());
|
||||
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("{error}").with(exception.getMessage())),
|
||||
(success) -> Result.success());
|
||||
success -> Result.success());
|
||||
}
|
||||
|
||||
private void cloneWorldTransferData(@NotNull CloneWorldOptions options, @NotNull MVWorld newWorld) {
|
||||
@ -571,11 +583,11 @@ public class WorldManager {
|
||||
}
|
||||
|
||||
CreateWorldOptions createWorldOptions = CreateWorldOptions.worldName(world.getName())
|
||||
.environment(world.getEnvironment())
|
||||
.generateStructures(world.canGenerateStructures().getOrElse(true))
|
||||
.generator(world.getGenerator())
|
||||
.seed(options.seed())
|
||||
.worldType(world.getWorldType().getOrElse(WorldType.NORMAL));
|
||||
.environment(world.getEnvironment())
|
||||
.generateStructures(world.canGenerateStructures().getOrElse(true))
|
||||
.generator(world.getGenerator())
|
||||
.seed(options.seed())
|
||||
.worldType(world.getWorldType().getOrElse(WorldType.NORMAL));
|
||||
|
||||
var deleteResult = deleteWorld(world);
|
||||
if (deleteResult.isFailure()) {
|
||||
|
@ -60,7 +60,7 @@ public class WorldPurger {
|
||||
}
|
||||
|
||||
public void purgeWorld(MVWorld mvworld, List<String> thingsToKill,
|
||||
boolean negateAnimals, boolean negateMonsters, CommandSender sender) {
|
||||
boolean negateAnimals, boolean negateMonsters, CommandSender sender) {
|
||||
if (mvworld == null) {
|
||||
return;
|
||||
}
|
||||
@ -77,8 +77,7 @@ public class WorldPurger {
|
||||
List<LivingEntity> livingEntities = new ArrayList<LivingEntity>(worldEntities.size());
|
||||
List<Projectile> projectiles = new ArrayList<Projectile>(worldEntities.size());
|
||||
for (final Entity e : worldEntities) {
|
||||
if (e instanceof Projectile) {
|
||||
final Projectile p = (Projectile) e;
|
||||
if (e instanceof Projectile p) {
|
||||
if (p.getShooter() != null) {
|
||||
projectiles.add((Projectile) e);
|
||||
}
|
||||
@ -107,7 +106,7 @@ public class WorldPurger {
|
||||
}
|
||||
|
||||
private boolean killDecision(Entity e, List<String> thingsToKill, boolean negateAnimals,
|
||||
boolean negateMonsters, boolean specifiedAnimals, boolean specifiedMonsters) {
|
||||
boolean negateMonsters, boolean specifiedAnimals, boolean specifiedMonsters) {
|
||||
boolean negate = false;
|
||||
boolean specified = false;
|
||||
if (e instanceof Golem || e instanceof Squid || e instanceof Animals
|
||||
@ -149,7 +148,8 @@ public class WorldPurger {
|
||||
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 specifiedAnimals = thingsToKill.contains("ANIMALS") || specifiedAll;
|
||||
boolean specifiedMonsters = thingsToKill.contains("MONSTERS") || specifiedAll;
|
||||
|
@ -20,7 +20,7 @@ public final class NullLocation extends SpawnLocation {
|
||||
@Override
|
||||
public Location clone() {
|
||||
throw new UnsupportedOperationException();
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> serialize() {
|
||||
@ -44,10 +44,10 @@ public final class NullLocation extends SpawnLocation {
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return -1;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Location{null}";
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package com.onarandombox.MultiverseCore.worldnew.config;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
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.worldnew.MVWorld;
|
||||
import io.vavr.control.Try;
|
||||
@ -18,7 +17,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class WorldConfig {
|
||||
public final class WorldConfig {
|
||||
|
||||
private final String worldName;
|
||||
private final WorldConfigNodes configNodes;
|
||||
|
@ -49,7 +49,7 @@ public class WorldConfigNodes {
|
||||
.defaultValue(true)
|
||||
.name("allow-weather")
|
||||
.onSetValue((oldValue, newValue) -> {
|
||||
if (world == null) { return; }
|
||||
if (world == null) return;
|
||||
world.getBukkitWorld().peek(world -> {
|
||||
if (!world.isClearWeather() && !newValue) {
|
||||
world.setThundering(false);
|
||||
@ -78,7 +78,7 @@ public class WorldConfigNodes {
|
||||
.defaultValue(Difficulty.NORMAL)
|
||||
.name("difficulty")
|
||||
.onSetValue((oldValue, newValue) -> {
|
||||
if (world == null) { return; }
|
||||
if (world == null) return;
|
||||
world.getBukkitWorld().peek(world -> world.setDifficulty(newValue));
|
||||
})
|
||||
.build());
|
||||
@ -93,7 +93,8 @@ public class WorldConfigNodes {
|
||||
.name("entryfee-currency")
|
||||
.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)
|
||||
.name("environment")
|
||||
.build());
|
||||
@ -118,11 +119,12 @@ public class WorldConfigNodes {
|
||||
.name("hunger")
|
||||
.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)
|
||||
.name("keep-spawn-in-memory")
|
||||
.onSetValue((oldValue, newValue) -> {
|
||||
if (world == null) { return; }
|
||||
if (world == null) return;
|
||||
world.getBukkitWorld().peek(world -> world.setKeepSpawnInMemory(newValue));
|
||||
})
|
||||
.build());
|
||||
@ -132,7 +134,8 @@ public class WorldConfigNodes {
|
||||
.name("player-limit")
|
||||
.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)
|
||||
.name("portal-form")
|
||||
.build());
|
||||
@ -141,7 +144,7 @@ public class WorldConfigNodes {
|
||||
.defaultValue(true)
|
||||
.name("pvp")
|
||||
.onSetValue((oldValue, newValue) -> {
|
||||
if (world == null) { return; }
|
||||
if (world == null) return;
|
||||
world.getBukkitWorld().peek(world -> world.setPVP(newValue));
|
||||
})
|
||||
.build());
|
||||
@ -165,7 +168,7 @@ public class WorldConfigNodes {
|
||||
.defaultValue(new NullLocation())
|
||||
.name("spawn-location")
|
||||
.onSetValue((oldValue, newValue) -> {
|
||||
if (world == null) { return; }
|
||||
if (world == null) return;
|
||||
world.getBukkitWorld().peek(world -> {
|
||||
world.setSpawnLocation(newValue.getBlockX(), newValue.getBlockY(), newValue.getBlockZ());
|
||||
newValue.setWorld(world);
|
||||
@ -177,44 +180,49 @@ public class WorldConfigNodes {
|
||||
.defaultValue(true)
|
||||
.name("spawning-animals")
|
||||
.onSetValue((oldValue, newValue) -> {
|
||||
if (world == null) { return; }
|
||||
if (world == null) return;
|
||||
world.getBukkitWorld().peek(world -> world.setSpawnFlags(world.getAllowMonsters(), newValue));
|
||||
})
|
||||
.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)
|
||||
.name("spawning-animals-ticks")
|
||||
.onSetValue((oldValue, newValue) -> {
|
||||
if (world == null) { return; }
|
||||
if (world == null) return;
|
||||
world.getBukkitWorld().peek(world -> world.setTicksPerAnimalSpawns(newValue));
|
||||
})
|
||||
.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<>())
|
||||
.name("spawning-animals-exceptions")
|
||||
.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)
|
||||
.name("spawning-monsters")
|
||||
.onSetValue((oldValue, newValue) -> {
|
||||
if (world == null) { return; }
|
||||
if (world == null) return;
|
||||
world.getBukkitWorld().peek(world -> world.setSpawnFlags(newValue, world.getAllowAnimals()));
|
||||
})
|
||||
.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)
|
||||
.name("spawning-monsters-ticks")
|
||||
.onSetValue((oldValue, newValue) -> {
|
||||
if (world == null) { return; }
|
||||
if (world == null) return;
|
||||
world.getBukkitWorld().peek(world -> world.setTicksPerMonsterSpawns(newValue));
|
||||
})
|
||||
.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<>())
|
||||
.name("spawning-monsters-exceptions")
|
||||
.build());
|
||||
|
@ -15,7 +15,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@Service
|
||||
public class WorldsConfigManager {
|
||||
public final class WorldsConfigManager {
|
||||
private static final String CONFIG_FILENAME = "worlds2.yml";
|
||||
|
||||
private final Map<String, WorldConfig> worldConfigMap;
|
||||
|
@ -2,7 +2,6 @@ package com.onarandombox.MultiverseCore.worldnew.helpers;
|
||||
|
||||
import com.dumptruckman.minecraft.util.Logging;
|
||||
import com.onarandombox.MultiverseCore.worldnew.MVWorld;
|
||||
import com.onarandombox.MultiverseCore.worldnew.OfflineWorld;
|
||||
import org.bukkit.GameRule;
|
||||
import org.bukkit.World;
|
||||
import org.jvnet.hk2.annotations.Service;
|
||||
|
Loading…
Reference in New Issue
Block a user