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 @@ -84,24 +84,34 @@
Path oldWorldConfig = worldConfigFile.toPath().getParent().resolve(CONFIG_FILENAME + ".old");
Files.copy(worldConfigFile.toPath(), oldWorldConfig, COPY_ATTRIBUTES);

return configData.replace("==: MVWorld", "")
return configData.replace("==: MVWorld", "w@: world")
.replace("==: MVSpawnSettings", "")
.replace("==: MVSpawnSubSettings", "")
.replace("==: MVEntryFee", "");
})
.andThenTry(configData -> Files.writeString(worldConfigFile.toPath(), configData))
.andThenTry(() -> {
YamlConfiguration config = YamlConfiguration.loadConfiguration(worldConfigFile);
List<ConfigurationSection> worlds = config.getConfigurationSection("worlds")
.getKeys(false)
.stream()
.map(worldName -> config.getConfigurationSection("worlds." + worldName))
.toList();

ConfigurationSection worldsSection = config.getConfigurationSection("worlds");

Check warning on line 96 in src/main/java/org/mvplugins/multiverse/core/world/WorldsConfigManager.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 The String "worlds" appears 3 times in the file. Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/world/WorldsConfigManager.java:96:89: warning: The String "worlds" appears 3 times in the file. (com.puppycrawl.tools.checkstyle.checks.coding.MultipleStringLiteralsCheck)
if (worldsSection == null) {
worldsSection = config.createSection("worlds");
}

List<String> worldNames = getOldConfigWorldNames(worldsSection);

Map<String, ConfigurationSection> worldConfigMap = new HashMap<>();
for (String worldName : worldNames) {
ConfigurationSection worldSection = worldsSection.getConfigurationSection(worldName);
if (worldSection != null) {
worldConfigMap.put(worldName, worldSection);
}
}

config.set("worlds", null);

for (ConfigurationSection world : worlds) {
config.createSection(world.getName(), world.getValues(true));
for (Map.Entry<String, ConfigurationSection> entry : worldConfigMap.entrySet()) {
config.set(encodeWorldName(entry.getKey()), entry.getValue());
}
config.save(worldConfigFile);
})
Expand All @@ -115,6 +125,35 @@
});
}

private @NotNull List<String> getOldConfigWorldNames(ConfigurationSection worldsSection) {
List<String> worldNames = new ArrayList<>();
recursiveGetOldConfigWorldNames(worldsSection, worldNames);
return worldNames;
}

private void recursiveGetOldConfigWorldNames(ConfigurationSection section, List<String> worldNames) {

Check warning on line 134 in src/main/java/org/mvplugins/multiverse/core/world/WorldsConfigManager.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 Return count is 2 (max allowed for void methods/constructors/lambdas is 1). Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/world/WorldsConfigManager.java:134:5: info: Return count is 2 (max allowed for void methods/constructors/lambdas is 1). (com.puppycrawl.tools.checkstyle.checks.coding.ReturnCountCheck)
Set<String> keys = section.getKeys(false);
if (keys.isEmpty()) {
// No keys in this section, nothing to do
return;
}

if (keys.contains("w@")) {
// this is the world data section already, get path without the "worlds." prefix
worldNames.add(section.getCurrentPath().substring(7));

Check warning on line 143 in src/main/java/org/mvplugins/multiverse/core/world/WorldsConfigManager.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 '7' is a magic number. Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/world/WorldsConfigManager.java:143:63: warning: '7' is a magic number. (com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck)
return;
}

for (String key : keys) {
ConfigurationSection dataSection = section.getConfigurationSection(key);
if (dataSection == null) {
// Something is wrong with the config, skip this key
continue;
}
recursiveGetOldConfigWorldNames(dataSection, worldNames);
}
}

/**
* Parses the worlds.yml file and creates a WorldConfig for each world in the file if it doesn't already exist.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class WorldConfigMangerTest : TestWithMockBukkit() {
assertEquals(MVEconomist.VAULT_ECONOMY_MATERIAL, endWorldConfig.entryFeeCurrency)
assertEquals(0.0, endWorldConfig.entryFeeAmount)

val worldConfig = worldConfigManager.getWorldConfig("world").orNull
val worldConfig = worldConfigManager.getWorldConfig("world.a.b").orNull
assertNotNull(worldConfig)

assertEquals(-5176596003035866649, worldConfig.seed)
Expand All @@ -58,6 +58,9 @@ class WorldConfigMangerTest : TestWithMockBukkit() {
assertEquals(Material.DIRT, worldConfig.entryFeeCurrency)
assertEquals(5.0, worldConfig.entryFeeAmount)

val world2Config = worldConfigManager.getWorldConfig("world.a.c").orNull
assertNotNull(world2Config)

assertConfigEquals("/worlds/migrated_worlds.yml", "worlds.yml")
}

Expand Down
51 changes: 50 additions & 1 deletion src/test/resources/worlds/migrated_worlds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ world_the_end:
tick-rate: -1
world-blacklist: []
version: 1.2
world:
world[dot]a[dot]b:
adjust-spawn: true
alias: ''
allow-advancement-grant: true
Expand Down Expand Up @@ -95,3 +95,52 @@ world:
world-blacklist:
- test
version: 1.2
world[dot]a[dot]c:
adjust-spawn: true
alias: ''
allow-advancement-grant: true
allow-flight: false
allow-weather: true
anchor-respawn: true
auto-heal: true
auto-load: true
bed-respawn: true
difficulty: normal
entry-fee:
enabled: true
amount: 5.0
currency: DIRT
environment: normal
gamemode: survival
biome: ''
generator: ''
hidden: false
hunger: true
keep-spawn-in-memory: true
player-limit: -1
portal-form: all
pvp: true
respawn-world: ''
scale: 1.0
seed: -5176596003035866649
spawn-location:
==: MVSpawnLocation
x: -64.0
y: 64.0
z: 48.0
pitch: 0.0
yaw: 0.0
spawning:
animal:
exceptions: [ ]
spawn: true
spawn-limit: -1
tick-rate: -1
monster:
exceptions: [ ]
spawn: true
spawn-limit: -1
tick-rate: -1
world-blacklist:
- test
version: 1.2
51 changes: 50 additions & 1 deletion src/test/resources/worlds/old_worlds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ worlds:
generator: 'null'
playerLimit: '-1'
allowFlight: 'true'
world:
world.a.b:
==: MVWorld
hidden: 'false'
alias: ''
Expand Down Expand Up @@ -95,3 +95,52 @@ worlds:
generator: 'null'
playerLimit: '-1'
allowFlight: 'false'
world.a.c:
==: MVWorld
hidden: 'false'
alias: ''
color: WHITE
style: NORMAL
pvp: 'true'
scale: '1.0'
respawnWorld: ''
allowWeather: 'true'
difficulty: NORMAL
spawning:
==: MVSpawnSettings
animals:
==: MVSpawnSubSettings
spawn: 'true'
spawnrate: '-1'
exceptions: []
monsters:
==: MVSpawnSubSettings
spawn: 'true'
spawnrate: '-1'
exceptions: []
entryfee:
==: MVEntryFee
amount: '5.0'
currency: 'DIRT'
hunger: 'true'
autoHeal: 'true'
adjustSpawn: 'true'
portalForm: ALL
gameMode: SURVIVAL
keepSpawnInMemory: 'true'
spawnLocation:
==: MVSpawnLocation
x: -64.0
y: 64.0
z: 48.0
pitch: 0.0
yaw: 0.0
autoLoad: 'true'
bedRespawn: 'true'
worldBlacklist:
- test
environment: NORMAL
seed: '-5176596003035866649'
generator: 'null'
playerLimit: '-1'
allowFlight: 'false'
Loading