Skip to content

Commit

Permalink
Added backward compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Picono435 committed May 30, 2021
1 parent 6e5073d commit c297559
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.gmail.picono435.picojobs.storage.file;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;

import org.spongepowered.configurate.ConfigurationNode;
import org.spongepowered.configurate.loader.ConfigurationLoader;
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
Expand All @@ -10,6 +15,25 @@ public class YamlStorage extends ConfigurationStorageFactory {

@Override
protected ConfigurationLoader<? extends ConfigurationNode> loadFile() {
File oldData = new File(PicoJobsPlugin.getInstance().getDataFolder().toPath().toAbsolutePath().resolve("data.yml").toString());
if(oldData.exists()) {
try {
String content = new String(Files.readAllBytes(oldData.toPath()));
content = content.replace("playerdata:", "");
content = content.replace("/^ /mg", "");
oldData.delete();
File newData = new File(PicoJobsPlugin.getInstance().getDataFolder().toPath().toAbsolutePath()
.resolve("storage").resolve("picojobs.yml").toString());
newData.getParentFile().mkdirs();
newData.createNewFile();
FileWriter myWriter = new FileWriter(newData);
myWriter.write(content);
myWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}

return YamlConfigurationLoader.builder()
.indent(2)
.path(PicoJobsPlugin.getInstance().getDataFolder().toPath().toAbsolutePath()
Expand Down

0 comments on commit c297559

Please sign in to comment.