mirror of
https://github.com/FancyInnovations/FancyPlugins.git
synced 2025-12-06 07:43:36 +00:00
fancyholograms-v3: Add migrator for YAML
This commit is contained in:
@@ -27,7 +27,8 @@ import de.oliver.fancyholograms.listeners.WorldListener;
|
|||||||
import de.oliver.fancyholograms.metrics.FHMetrics;
|
import de.oliver.fancyholograms.metrics.FHMetrics;
|
||||||
import de.oliver.fancyholograms.registry.HologramRegistryImpl;
|
import de.oliver.fancyholograms.registry.HologramRegistryImpl;
|
||||||
import de.oliver.fancyholograms.storage.HologramStorage;
|
import de.oliver.fancyholograms.storage.HologramStorage;
|
||||||
import de.oliver.fancyholograms.storage.YamlHologramStorage;
|
import de.oliver.fancyholograms.storage.StorageMigrator;
|
||||||
|
import de.oliver.fancyholograms.storage.json.JsonStorage;
|
||||||
import de.oliver.fancyholograms.trait.HologramTraitRegistryImpl;
|
import de.oliver.fancyholograms.trait.HologramTraitRegistryImpl;
|
||||||
import de.oliver.fancyholograms.trait.builtin.MultiplePagesTrait;
|
import de.oliver.fancyholograms.trait.builtin.MultiplePagesTrait;
|
||||||
import de.oliver.fancyholograms.util.PluginUtils;
|
import de.oliver.fancyholograms.util.PluginUtils;
|
||||||
@@ -141,7 +142,7 @@ public final class FancyHologramsPlugin extends JavaPlugin implements FancyHolog
|
|||||||
fancyLogger.setCurrentLevel(logLevel);
|
fancyLogger.setCurrentLevel(logLevel);
|
||||||
IFancySitula.LOGGER.setCurrentLevel(logLevel);
|
IFancySitula.LOGGER.setCurrentLevel(logLevel);
|
||||||
|
|
||||||
storage = new YamlHologramStorage();
|
storage = new JsonStorage();
|
||||||
registry = new HologramRegistryImpl();
|
registry = new HologramRegistryImpl();
|
||||||
controller = new HologramControllerImpl();
|
controller = new HologramControllerImpl();
|
||||||
traitRegistry = new HologramTraitRegistryImpl();
|
traitRegistry = new HologramTraitRegistryImpl();
|
||||||
@@ -190,6 +191,8 @@ public final class FancyHologramsPlugin extends JavaPlugin implements FancyHolog
|
|||||||
metrics.register();
|
metrics.register();
|
||||||
metrics.registerLegacy();
|
metrics.registerLegacy();
|
||||||
|
|
||||||
|
new StorageMigrator().migrate();
|
||||||
|
|
||||||
for (World world : Bukkit.getWorlds()) {
|
for (World world : Bukkit.getWorlds()) {
|
||||||
Collection<HologramData> data = storage.loadAll(world.getName());
|
Collection<HologramData> data = storage.loadAll(world.getName());
|
||||||
for (HologramData d : data) {
|
for (HologramData d : data) {
|
||||||
@@ -218,6 +221,8 @@ public final class FancyHologramsPlugin extends JavaPlugin implements FancyHolog
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
|
savePersistentHolograms();
|
||||||
|
|
||||||
hologramThread.shutdown();
|
hologramThread.shutdown();
|
||||||
storageThread.shutdown();
|
storageThread.shutdown();
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package de.oliver.fancyholograms.storage;
|
||||||
|
|
||||||
|
import de.oliver.fancyholograms.api.data.HologramData;
|
||||||
|
import de.oliver.fancyholograms.api.hologram.Hologram;
|
||||||
|
import de.oliver.fancyholograms.main.FancyHologramsPlugin;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.World;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
public class StorageMigrator {
|
||||||
|
|
||||||
|
public void migrate() {
|
||||||
|
if (!YamlHologramStorage.HOLOGRAMS_CONFIG_FILE.exists()) {
|
||||||
|
FancyHologramsPlugin.get().getFancyLogger().debug("No holograms.yml file found, skipping migration.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
FancyHologramsPlugin.get().getFancyLogger().info("Migrating holograms.yml to JSON format...");
|
||||||
|
|
||||||
|
HologramStorage yamlStorage = new YamlHologramStorage();
|
||||||
|
for (World world : Bukkit.getWorlds()) {
|
||||||
|
Collection<HologramData> data = yamlStorage.loadAll(world.getName());
|
||||||
|
for (HologramData d : data) {
|
||||||
|
Hologram hologram = FancyHologramsPlugin.get().getHologramFactory().apply(d);
|
||||||
|
FancyHologramsPlugin.get().getRegistry().register(hologram);
|
||||||
|
FancyHologramsPlugin.get().getFancyLogger().info("Migrated hologram " + hologram.getData().getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!YamlHologramStorage.HOLOGRAMS_CONFIG_FILE.renameTo(YamlHologramStorage.HOLOGRAMS_CONFIG_FILE.getParentFile().toPath().resolve("holograms-old.yaml").toFile())) {
|
||||||
|
FancyHologramsPlugin.get().getFancyLogger().error("Failed to rename holograms.yml to holograms-old.yaml");
|
||||||
|
}
|
||||||
|
|
||||||
|
FancyHologramsPlugin.get().getFancyLogger().info("Migration completed");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -20,8 +20,8 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
|
|||||||
|
|
||||||
public class YamlHologramStorage implements HologramStorage {
|
public class YamlHologramStorage implements HologramStorage {
|
||||||
|
|
||||||
|
public static final File HOLOGRAMS_CONFIG_FILE = new File("plugins/FancyHolograms/holograms.yml");
|
||||||
private static final ReadWriteLock lock = new ReentrantReadWriteLock();
|
private static final ReadWriteLock lock = new ReentrantReadWriteLock();
|
||||||
private static final File HOLOGRAMS_CONFIG_FILE = new File("plugins/FancyHolograms/holograms.yml");
|
|
||||||
|
|
||||||
public void saveBatch(Collection<HologramData> holograms) {
|
public void saveBatch(Collection<HologramData> holograms) {
|
||||||
lock.readLock().lock();
|
lock.readLock().lock();
|
||||||
|
|||||||
Reference in New Issue
Block a user