Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,21 @@
import co.aikar.locales.MessageKey;
import co.aikar.locales.MessageKeyProvider;

import org.jetbrains.annotations.ApiStatus;

Check warning on line 6 in src/main/java/org/mvplugins/multiverse/core/utils/result/FailureReason.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 Extra separation in import group before 'org.jetbrains.annotations.ApiStatus' Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/utils/result/FailureReason.java:6:1: warning: Extra separation in import group before 'org.jetbrains.annotations.ApiStatus' (com.puppycrawl.tools.checkstyle.checks.imports.ImportOrderCheck)
import org.mvplugins.multiverse.core.locale.MVCorei18n;

/**
* Represents a failure reason for an {@link Attempt}.
*/
public interface FailureReason extends MessageKeyProvider {
/**
* A generic failure reason that can be used when no specific reason is applicable.
*
* @since 5.2
*/
@ApiStatus.AvailableSince("5.2")
FailureReason GENERIC = new FailureReason() { };

default MessageKey getMessageKey() {
return MVCorei18n.GENERIC_FAILURE.getMessageKey();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,21 @@
import co.aikar.locales.MessageKey;
import co.aikar.locales.MessageKeyProvider;

import org.jetbrains.annotations.ApiStatus;

Check warning on line 6 in src/main/java/org/mvplugins/multiverse/core/utils/result/SuccessReason.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 Extra separation in import group before 'org.jetbrains.annotations.ApiStatus' Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/utils/result/SuccessReason.java:6:1: warning: Extra separation in import group before 'org.jetbrains.annotations.ApiStatus' (com.puppycrawl.tools.checkstyle.checks.imports.ImportOrderCheck)
import org.mvplugins.multiverse.core.locale.MVCorei18n;

/**
* Represents a success reason for an {@link Attempt}.
*/
public interface SuccessReason extends MessageKeyProvider {
/**
* A generic success reason that can be used when no specific reason is applicable.
*
* @since 5.2
*/
@ApiStatus.AvailableSince("5.2")
SuccessReason GENERIC = new SuccessReason() { };

default MessageKey getMessageKey() {
return MVCorei18n.GENERIC_SUCCESS.getMessageKey();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,11 @@
}

private void removeWorldsNotInConfigs(Collection<String> removedWorlds) {
removedWorlds.forEach(worldName -> removeWorld(worldName)
removedWorlds.forEach(worldName -> getWorld(worldName)
.fold(
() -> Attempt.failure(FailureReason.GENERIC, Message.of("world already removed")),
world -> removeWorld(RemoveWorldOptions.world(world))
)

Check warning on line 176 in src/main/java/org/mvplugins/multiverse/core/world/WorldManager.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 ')' should be on the previous line. Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/world/WorldManager.java:176:17: warning: ')' should be on the previous line. (SeparatorWrapEol)
.onFailure(failure -> Logging.severe("Failed to unload world %s: %s", worldName, failure))
.onSuccess(success -> Logging.fine("Unloaded world %s as it was removed from config", worldName)));
}
Expand Down Expand Up @@ -513,10 +517,14 @@
*
* @param worldName The name of the world to remove.
* @return The result of the remove.
*
* @deprecated Get the {@link MultiverseWorld} yourself and use {@link #removeWorld(RemoveWorldOptions)} instead.
*/
@Deprecated(since = "5.2", forRemoval = true)
@ApiStatus.ScheduledForRemoval(inVersion = "6.0")
public Attempt<String, RemoveFailureReason> removeWorld(@NotNull String worldName) {
return getWorld(worldName)
.map(this::removeWorld)
.map(world -> removeWorld(RemoveWorldOptions.world(world)))
.getOrElse(() -> worldActionResult(RemoveFailureReason.WORLD_NON_EXISTENT, worldName));
}

Expand All @@ -526,7 +534,11 @@
*
* @param world The multiverse world to remove.
* @return The result of the remove.
*
* @deprecated Use {@link #removeWorld(RemoveWorldOptions)} instead.
*/
@Deprecated(since = "5.2", forRemoval = true)
@ApiStatus.ScheduledForRemoval(inVersion = "6.0")
public Attempt<String, RemoveFailureReason> removeWorld(@NotNull MultiverseWorld world) {
return removeWorld(RemoveWorldOptions.world(world));
}
Expand All @@ -537,9 +549,13 @@
*
* @param loadedWorld The multiverse world to remove.
* @return The result of the remove.
*
* @deprecated Use {@link #removeWorld(RemoveWorldOptions)} instead.
*/
@Deprecated(since = "5.2", forRemoval = true)
@ApiStatus.ScheduledForRemoval(inVersion = "6.0")
public Attempt<String, RemoveFailureReason> removeWorld(@NotNull LoadedMultiverseWorld loadedWorld) {
return unloadBeforeRemoveWorld(loadedWorld, RemoveWorldOptions.world(loadedWorld));
return removeWorld(RemoveWorldOptions.world(loadedWorld));
}

/**
Expand Down Expand Up @@ -620,7 +636,11 @@
? Attempt.failure(DeleteFailureReason.EVENT_CANCELLED)
: Attempt.success(null);
})
.mapAttempt(() -> removeWorld(world).transform(DeleteFailureReason.REMOVE_FAILED))
.mapAttempt(() -> removeWorld(RemoveWorldOptions
.world(world)
.unloadBukkitWorld(true)
.saveBukkitWorld(false)
).transform(DeleteFailureReason.REMOVE_FAILED))

Check warning on line 643 in src/main/java/org/mvplugins/multiverse/core/world/WorldManager.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 ')' should be on the previous line. Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/world/WorldManager.java:643:17: warning: ')' should be on the previous line. (SeparatorWrapEol)
.mapAttempt(() -> fileUtils.deleteFolder(worldFolder.get(), options.keepFiles()).fold(
exception -> worldActionResult(DeleteFailureReason.FAILED_TO_DELETE_FOLDER,
world.getName(), exception),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@
import co.aikar.locales.MessageKey;
import co.aikar.locales.MessageKeyProvider;

import org.jetbrains.annotations.ApiStatus;

Check warning on line 6 in src/main/java/org/mvplugins/multiverse/core/world/reasons/RemoveFailureReason.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 Extra separation in import group before 'org.jetbrains.annotations.ApiStatus' Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/world/reasons/RemoveFailureReason.java:6:1: warning: Extra separation in import group before 'org.jetbrains.annotations.ApiStatus' (com.puppycrawl.tools.checkstyle.checks.imports.ImportOrderCheck)
import org.mvplugins.multiverse.core.locale.MVCorei18n;
import org.mvplugins.multiverse.core.utils.result.FailureReason;
import org.mvplugins.multiverse.core.world.WorldManager;

/**
* Result of a world removal operation.
*/
public enum RemoveFailureReason implements FailureReason {
/**
* The world does not exist.
*
* @deprecated No longer in use as {@link WorldManager#removeWorld(String)} is now deprecated.
*/
@Deprecated(forRemoval = true, since = "5.2")
@ApiStatus.ScheduledForRemoval(inVersion = "6.0")
WORLD_NON_EXISTENT(MVCorei18n.REMOVEWORLD_WORLDNONEXISTENT),

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import org.mvplugins.multiverse.core.world.options.CloneWorldOptions
import org.mvplugins.multiverse.core.world.options.CreateWorldOptions
import org.mvplugins.multiverse.core.world.options.DeleteWorldOptions
import org.mvplugins.multiverse.core.world.options.RegenWorldOptions
import org.mvplugins.multiverse.core.world.options.RemoveWorldOptions
import org.mvplugins.multiverse.core.world.options.UnloadWorldOptions
import org.mvplugins.multiverse.core.world.reasons.CloneFailureReason
import org.mvplugins.multiverse.core.world.reasons.CreateFailureReason
Expand Down Expand Up @@ -102,7 +103,7 @@ class WorldManagerTest : TestWithMockBukkit() {

@Test
fun `Remove world`() {
assertTrue(worldManager.removeWorld(world).isSuccess)
assertTrue(worldManager.removeWorld(RemoveWorldOptions.world(world)).isSuccess)
assertFalse(worldManager.getWorld("world").isDefined)
assertFalse(worldManager.getLoadedWorld("world").isDefined)
assertFalse(worldManager.getUnloadedWorld("world").isDefined)
Expand Down