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 @@ -14,6 +14,8 @@

/**
* Compatibility class used to handle API changes in {@link Bukkit} class.
*
* @since 5.6
*/
@ApiStatus.AvailableSince("5.6")
public final class BukkitCompatibility {
Expand All @@ -26,6 +28,23 @@ public final class BukkitCompatibility {
GET_WORLD_NAMESPACED_KEY_METHOD = Option.of(ReflectHelper.getMethod(Bukkit.class, "getWorld", NamespacedKey.class));
}

/**
* Check whether the server is using the new dimension storage system introduced in PaperMC 26.1.
* <br />
* This is based of whether getLevelDirectory method exists in the server class,which is the main API change for
* the new dimension storage system.
*
* @return True if the server is using the new dimension storage system, else false.
*
* @since 5.6
*/
@ApiStatus.AvailableSince("5.6")
public static boolean isUsingNewDimensionStorage() {
return GET_LEVEL_DIRECTORY_METHOD
.flatMap(method -> Option.of(ReflectHelper.invokeMethod(Bukkit.getServer(), method)))
.isDefined();
}

/**
* Gets the folder where all the worlds will be store. Before 26.1, all worlds are stored in the root directory
* of the server, which can be obtained by {@link Server#getWorldContainer()}.
Expand All @@ -34,6 +53,8 @@ public final class BukkitCompatibility {
* level directory, which needs to be manually parsed.
*
* @return The location where all the worlds folders should be, depending on server's mc version.
*
* @since 5.6
*/
@ApiStatus.AvailableSince("5.6")
@NotNull
Expand All @@ -55,6 +76,8 @@ public static Path getWorldFoldersDirectory() {
*
* @param nameOrKey Either a name or namespaced key string representation.
* @return The world if it exists
*
* @since 5.6
*/
@ApiStatus.AvailableSince("5.6")
@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,17 @@
String worldName = options.worldName();
if (!worldNameChecker.isValidWorldName(worldName)) {
return worldActionResult(ImportFailureReason.INVALID_WORLDNAME, worldName);
} else if (options.doFolderCheck() && !worldNameChecker.isValidWorldFolder(worldName)) {
return worldActionResult(ImportFailureReason.WORLD_FOLDER_INVALID, worldName);
} else if (options.doFolderCheck()) {
//todo This is a duplicate of folder check in load world

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

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Complete the task associated to this TODO comment.

See more on https://sonarcloud.io/project/issues?id=Multiverse_Multiverse-Core&issues=AZ1rC6i-6AnbEIDJ4xAQ&open=AZ1rC6i-6AnbEIDJ4xAQ&pullRequest=3439
WorldNameChecker.FolderStatus folderStatus = worldNameChecker.checkFolder(options.worldName());
if (!folderStatus.isLoadable()) {
return worldActionResult(ImportFailureReason.WORLD_FOLDER_INVALID, options.worldName());
}
if (folderStatus == WorldNameChecker.FolderStatus.REQUIRES_MIGRATION) {
Logging.info("World '%s' will be automatically migrated by PaperMC to the new dimension " +

Check warning on line 327 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 a new line. Raw Output: /github/workspace/src/main/java/org/mvplugins/multiverse/core/world/WorldManager.java:327:107: warning: '+' should be on a new line. (com.puppycrawl.tools.checkstyle.checks.whitespace.OperatorWrapCheck)

Check warning on line 327 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 🐶 The String "World '%s' will be automatically migrated by PaperMC to the new dimension " appears 2 times in the file. Raw Output: /github/workspace/src/main/java/org/mvplugins/multiverse/core/world/WorldManager.java:327:30: warning: The String "World '%s' will be automatically migrated by PaperMC to the new dimension " appears 2 times in the file. (com.puppycrawl.tools.checkstyle.checks.coding.MultipleStringLiteralsCheck)
"location. If you face any issue with migration, please contact PaperMC support!",

Check warning on line 328 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 🐶 The String "location. If you face any issue with migration, please contact PaperMC support!" appears 2 times in the file. Raw Output: /github/workspace/src/main/java/org/mvplugins/multiverse/core/world/WorldManager.java:328:33: warning: The String "location. If you face any issue with migration, please contact PaperMC support!" appears 2 times in the file. (com.puppycrawl.tools.checkstyle.checks.coding.MultipleStringLiteralsCheck)
options.worldName());
}
}
return worldActionResult(options);
}
Expand Down Expand Up @@ -480,8 +489,16 @@
return doLoadBukkitWorld(bukkitWorld, mvWorld);
}

if (options.doFolderCheck() && !worldNameChecker.isValidWorldFolder(mvWorld.getName())) {
return worldActionResult(LoadFailureReason.WORLD_FOLDER_INVALID, mvWorld.getName());
if (options.doFolderCheck()) {
WorldNameChecker.FolderStatus folderStatus = worldNameChecker.checkFolder(mvWorld.getName());
if (!folderStatus.isLoadable()) {
return worldActionResult(LoadFailureReason.WORLD_FOLDER_INVALID, mvWorld.getName());
}
if (folderStatus == WorldNameChecker.FolderStatus.REQUIRES_MIGRATION) {
Logging.info("World '%s' will be automatically migrated by PaperMC to the new dimension " +

Check warning on line 498 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 a new line. Raw Output: /github/workspace/src/main/java/org/mvplugins/multiverse/core/world/WorldManager.java:498:107: warning: '+' should be on a new line. (com.puppycrawl.tools.checkstyle.checks.whitespace.OperatorWrapCheck)
"location. If you face any issue with migration, please contact PaperMC support!",
mvWorld.getName());
}
}

WorldCreator worldCreator = WorldCreator.name(mvWorld.getName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
import java.util.Locale;
import java.util.Set;

import com.dumptruckman.minecraft.util.Logging;
import io.vavr.control.Option;
import org.bukkit.Bukkit;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jvnet.hk2.annotations.Service;
Expand Down Expand Up @@ -95,7 +96,7 @@
* @return True if check result is valid, else false.
*/
public boolean isValidWorldFolder(@Nullable String worldName) {
return checkFolder(worldName) == FolderStatus.VALID;
return checkFolder(worldName).loadable;
}

/**
Expand All @@ -105,7 +106,7 @@
* @return True if check result is valid, else false.
*/
public boolean isValidWorldFolder(@Nullable File worldFolder) {
return checkFolder(worldFolder) == FolderStatus.VALID;
return checkFolder(worldFolder).loadable;
}

/**
Expand All @@ -120,7 +121,13 @@
return FolderStatus.DOES_NOT_EXIST;
}
File worldFolder = BukkitCompatibility.getWorldFoldersDirectory().resolve(worldName).toFile();
Logging.finer("Checking valid folder for world '%s' at: '%s'", worldName, worldFolder.getPath());
if (BukkitCompatibility.isUsingNewDimensionStorage()) {
File oldWorldFolder = Bukkit.getWorldContainer().toPath().resolve(worldName).toFile();
if (checkFolder(oldWorldFolder) == FolderStatus.VALID) {
return FolderStatus.REQUIRES_MIGRATION;
}
}

return checkFolder(worldFolder);
}

Expand Down Expand Up @@ -230,16 +237,39 @@
/**
* Folder is valid.
*/
VALID,
VALID(true),

/**

Check warning on line 242 in src/main/java/org/mvplugins/multiverse/core/world/helpers/WorldNameChecker.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 First sentence should end with a period. Raw Output: /github/workspace/src/main/java/org/mvplugins/multiverse/core/world/helpers/WorldNameChecker.java:242:0: warning: First sentence should end with a period. (com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocStyleCheck)
* This folder will cause PaperMC to migrate to new dimension world folder in 26.1+
*/
REQUIRES_MIGRATION(true),

/**
* Folder exist, but contents in it doesnt look like a world.
*/
NOT_A_WORLD,
NOT_A_WORLD(false),

/**
* Folder does not exist.
*/
DOES_NOT_EXIST
DOES_NOT_EXIST(false),
;

Check warning on line 256 in src/main/java/org/mvplugins/multiverse/core/world/helpers/WorldNameChecker.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/helpers/WorldNameChecker.java:256:9: warning: ';' should be on the previous line. (SeparatorWrapEol)

Check warning on line 256 in src/main/java/org/mvplugins/multiverse/core/world/helpers/WorldNameChecker.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 ';' is preceded with whitespace. Raw Output: /github/workspace/src/main/java/org/mvplugins/multiverse/core/world/helpers/WorldNameChecker.java:256:9: warning: ';' is preceded with whitespace. (AllowedWhitespaceBeforeWithoutLinebreak)

private final boolean loadable;

FolderStatus(boolean loadable) {
this.loadable = loadable;
}

/**
* Whether this folder status is loadable, meaning it has the basic world data and can be loaded as a world.
* Note that this does not guarantee the server will definitely load the world with no errors.
*
* @return True if folder probably is loadable by the server, else false.
*/
@ApiStatus.AvailableSince("5.6")
public boolean isLoadable() {
return loadable;
}
}
}
Loading