move legacy data before downloading libraries
This commit is contained in:
parent
5501e3a500
commit
2686cd4bb6
2 changed files with 19 additions and 11 deletions
|
@ -99,16 +99,6 @@ public class ZNpcsPlus {
|
|||
PluginManager pluginManager = Bukkit.getPluginManager();
|
||||
long before = System.currentTimeMillis();
|
||||
|
||||
boolean legacy = new File(getDataFolder(), "data.json").isFile() && !new File(getDataFolder(), "data").isDirectory();
|
||||
if (legacy) try {
|
||||
Files.move(getDataFolder().toPath(), new File(getDataFolder().getParentFile(), "ZNPCsPlusLegacy").toPath());
|
||||
} catch (IOException e) {
|
||||
log(ChatColor.RED + " * Moving legacy files to subfolder failed, plugin will shut down.");
|
||||
e.printStackTrace();
|
||||
pluginManager.disablePlugin(bootstrap);
|
||||
return;
|
||||
}
|
||||
|
||||
log(ChatColor.WHITE + " * Initializing libraries...");
|
||||
|
||||
packetEvents.init();
|
||||
|
@ -172,7 +162,7 @@ public class ZNpcsPlus {
|
|||
npcRegistry.reload();
|
||||
if (configManager.getConfig().autoSaveEnabled()) shutdownTasks.add(npcRegistry::save);
|
||||
|
||||
if (legacy) {
|
||||
if (bootstrap.movedLegacy()) {
|
||||
log(ChatColor.WHITE + " * Converting legacy data...");
|
||||
try {
|
||||
Collection<NpcEntryImpl> entries = importerRegistry.getImporter("znpcsplus_legacy").importData();
|
||||
|
|
|
@ -6,18 +6,32 @@ import lol.pyr.znpcsplus.libraries.LibraryLoader;
|
|||
import lol.pyr.znpcsplus.util.FileUtil;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.nio.file.Files;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class ZNpcsPlusBootstrap extends JavaPlugin {
|
||||
private ZNpcsPlus zNpcsPlus;
|
||||
private boolean legacy;
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
legacy = new File(getDataFolder(), "data.json").isFile() && !new File(getDataFolder(), "data").isDirectory();
|
||||
if (legacy) try {
|
||||
Files.move(getDataFolder().toPath(), new File(getDataFolder().getParentFile(), "ZNPCsPlusLegacy").toPath());
|
||||
} catch (IOException e) {
|
||||
getLogger().severe(ChatColor.RED + "Failed to move legacy data folder! Plugin will disable.");
|
||||
e.printStackTrace();
|
||||
Bukkit.getPluginManager().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
getLogger().info("Downloading and loading libraries, this might take a while if this is the first time you're launching the plugin");
|
||||
LibraryLoader loader = new LibraryLoader(this, new File(getDataFolder(), "libraries"));
|
||||
|
||||
|
@ -103,6 +117,10 @@ public class ZNpcsPlusBootstrap extends JavaPlugin {
|
|||
return context -> context.send(component);
|
||||
}
|
||||
|
||||
public boolean movedLegacy() {
|
||||
return legacy;
|
||||
}
|
||||
|
||||
// Ugly hack because of https://github.com/johnrengelman/shadow/issues/232
|
||||
private static String decrypt(String packageName) {
|
||||
return packageName.replace("..", ".");
|
||||
|
|
Loading…
Reference in a new issue