Skip to content

Commit

Permalink
Ensure VersionMigrator is applied in the correct order
Browse files Browse the repository at this point in the history
  • Loading branch information
benwoo1110 committed Feb 28, 2025
1 parent 74e595b commit cfd7be2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.mvplugins.multiverse.core.configuration.migration;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.dumptruckman.minecraft.util.Logging;
Expand Down Expand Up @@ -43,8 +44,8 @@ public void migrate(ConfigurationSection config) {
return;
}

double versionNumber = config.getDouble(versionNode.getPath());
for (VersionMigrator versionMigrator : versionMigrators) {
double versionNumber = config.getDouble(versionNode.getPath());
if (versionNumber < versionMigrator.getVersion()) {
Logging.info("Migrating config from version %s to %s...", versionNumber, versionMigrator.getVersion());
versionMigrator.migrate(config);
Expand Down Expand Up @@ -101,6 +102,7 @@ public Builder addVersionMigrator(VersionMigrator versionMigrator) {
* @return The built ConfigMigrator.
*/
public ConfigMigrator build() {
Collections.sort(versionMigrators);
return new ConfigMigrator(versionNode, versionMigrators);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
import java.util.List;

import org.bukkit.configuration.ConfigurationSection;
import org.jetbrains.annotations.NotNull;

/**
* A version migrator is a collection of migrator actions that are performed when migrating a config to a specific version.
*/
public class VersionMigrator {
public class VersionMigrator implements Comparable<VersionMigrator> {

/**
* Creates a new builder for a VersionMigrator.
Expand Down Expand Up @@ -46,6 +47,11 @@ public double getVersion() {
return version;
}

@Override
public int compareTo(@NotNull VersionMigrator o) {
return Double.compare(version, o.version);
}

/**
* A builder for a VersionMigrator.
*/
Expand Down

0 comments on commit cfd7be2

Please sign in to comment.