-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
paper: Migrate data using world name to world keys for consistency wi…
…th other platforms (#30)
- Loading branch information
Showing
13 changed files
with
100 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
paper/src/main/java/xyz/jpenilla/squaremap/paper/util/WorldNameToKeyMigration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package xyz.jpenilla.squaremap.paper.util; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import net.minecraft.server.level.ServerLevel; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.World; | ||
import org.checkerframework.checker.nullness.qual.NonNull; | ||
import org.checkerframework.framework.qual.DefaultQualifier; | ||
import xyz.jpenilla.squaremap.common.SquaremapCommon; | ||
import xyz.jpenilla.squaremap.common.config.Advanced; | ||
import xyz.jpenilla.squaremap.common.config.Config; | ||
import xyz.jpenilla.squaremap.common.util.FileUtil; | ||
import xyz.jpenilla.squaremap.common.util.Util; | ||
|
||
@DefaultQualifier(NonNull.class) | ||
public final class WorldNameToKeyMigration { | ||
public static void migrateLoaded() { | ||
for (final World world : Bukkit.getWorlds()) { | ||
migrate(CraftBukkitReflection.serverLevel(world)); | ||
} | ||
} | ||
|
||
public static void migrate(final ServerLevel level) { | ||
final String oldName = CraftBukkitReflection.world(level).getName(); | ||
Config.config().migrateLevelSection(level, oldName); | ||
Advanced.config().migrateLevelSection(level, oldName); | ||
try { | ||
moveDirectories(level, oldName); | ||
} catch (final IOException ex) { | ||
throw new RuntimeException("Failed to migrate directories", ex); | ||
} | ||
} | ||
|
||
private static void moveDirectories(final ServerLevel level, final String oldName) throws IOException { | ||
final String webName = Util.levelWebName(level); | ||
final Path tilesFrom = FileUtil.TILES_DIR.resolve(oldName); | ||
if (Files.exists(tilesFrom)) { | ||
final Path tilesDest = FileUtil.TILES_DIR.resolve(webName); | ||
Files.move(tilesFrom, tilesDest); | ||
} | ||
|
||
final Path data = SquaremapCommon.instance().platform().dataDirectory().resolve("data"); | ||
final Path dataFrom = data.resolve(oldName); | ||
if (Files.exists(dataFrom)) { | ||
final Path dataDest = data.resolve(webName); | ||
Files.move(dataFrom, dataDest); | ||
} | ||
} | ||
} |