Search in sources :

Example 1 with Utf8YamlConfiguration

use of io.github.wysohn.triggerreactor.bukkit.tools.Utf8YamlConfiguration in project TriggerReactor by wysohn.

the class AbstractJavaPlugin method migrateOldConfig.

private void migrateOldConfig() {
    new ContinuingTasks.Builder().append(() -> {
        if (core.getPluginConfigManager().isMigrationNeeded()) {
            core.getPluginConfigManager().migrate(new NaiveMigrationHelper(getConfig(), new File(getDataFolder(), "config.yml")));
        }
    }).append(() -> {
        if (core.getVariableManager().isMigrationNeeded()) {
            File file = new File(getDataFolder(), "var.yml");
            FileConfiguration conf = new Utf8YamlConfiguration();
            try {
                conf.load(file);
            } catch (IOException | InvalidConfigurationException e) {
                e.printStackTrace();
            }
            core.getVariableManager().migrate(new NaiveMigrationHelper(conf, file));
        }
    }).append(() -> {
        Optional.of(core.getInvManager()).map(AbstractTriggerManager::getTriggerInfos).ifPresent(triggerInfos -> Arrays.stream(triggerInfos).filter(TriggerInfo::isMigrationNeeded).forEach(triggerInfo -> {
            File folder = triggerInfo.getSourceCodeFile().getParentFile();
            File oldFile = new File(folder, triggerInfo.getTriggerName() + ".yml");
            FileConfiguration oldFileConfig = YamlConfiguration.loadConfiguration(oldFile);
            triggerInfo.migrate(new InvTriggerMigrationHelper(oldFile, oldFileConfig));
        }));
    }).append(() -> {
        Manager.getManagers().stream().filter(AbstractTriggerManager.class::isInstance).map(AbstractTriggerManager.class::cast).map(AbstractTriggerManager::getTriggerInfos).forEach(triggerInfos -> Arrays.stream(triggerInfos).filter(TriggerInfo::isMigrationNeeded).forEach(triggerInfo -> {
            File folder = triggerInfo.getSourceCodeFile().getParentFile();
            File oldFile = new File(folder, triggerInfo.getTriggerName() + ".yml");
            FileConfiguration oldFileConfig = YamlConfiguration.loadConfiguration(oldFile);
            triggerInfo.migrate(new NaiveMigrationHelper(oldFileConfig, oldFile));
        }));
    }).run();
}
Also used : FileConfiguration(org.bukkit.configuration.file.FileConfiguration) Utf8YamlConfiguration(io.github.wysohn.triggerreactor.bukkit.tools.Utf8YamlConfiguration) Connection(java.sql.Connection) BukkitConfigurationSerializer(io.github.wysohn.triggerreactor.bukkit.main.serialize.BukkitConfigurationSerializer) Event(org.bukkit.event.Event) GsonConfigSource(io.github.wysohn.triggerreactor.core.config.source.GsonConfigSource) Player(org.bukkit.entity.Player) ConfigurationSerializable(org.bukkit.configuration.serialization.ConfigurationSerializable) Inventory(org.bukkit.inventory.Inventory) ICommandSender(io.github.wysohn.triggerreactor.core.bridge.ICommandSender) Future(java.util.concurrent.Future) Location(org.bukkit.Location) ResultSet(java.sql.ResultSet) IItemStack(io.github.wysohn.triggerreactor.core.bridge.IItemStack) BukkitUtil(io.github.wysohn.triggerreactor.bukkit.tools.BukkitUtil) Method(java.lang.reflect.Method) ByteArrayDataOutput(com.google.common.io.ByteArrayDataOutput) Material(org.bukkit.Material) BlockEvent(org.bukkit.event.block.BlockEvent) Bukkit(org.bukkit.Bukkit) BukkitCommandSender(io.github.wysohn.triggerreactor.bukkit.bridge.BukkitCommandSender) MiniConnectionPoolManager(io.github.wysohn.triggerreactor.tools.mysql.MiniConnectionPoolManager) CommandSender(org.bukkit.command.CommandSender) MysqlConnectionPoolDataSource(com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource) AbstractTriggerManager(io.github.wysohn.triggerreactor.core.manager.trigger.AbstractTriggerManager) Entity(org.bukkit.entity.Entity) IInventory(io.github.wysohn.triggerreactor.core.bridge.IInventory) NaiveMigrationHelper(io.github.wysohn.triggerreactor.bukkit.tools.migration.NaiveMigrationHelper) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) EntityEvent(org.bukkit.event.entity.EntityEvent) PreparedStatement(java.sql.PreparedStatement) PluginCommand(org.bukkit.command.PluginCommand) Sets(com.google.common.collect.Sets) IPlayer(io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer) ItemStack(org.bukkit.inventory.ItemStack) InvocationTargetException(java.lang.reflect.InvocationTargetException) JavaPlugin(org.bukkit.plugin.java.JavaPlugin) TriggerReactorStartEvent(io.github.wysohn.triggerreactor.bukkit.manager.event.TriggerReactorStartEvent) PlayerDeathEvent(org.bukkit.event.entity.PlayerDeathEvent) org.bukkit.event.inventory(org.bukkit.event.inventory) ByteStreams(com.google.common.io.ByteStreams) Command(org.bukkit.command.Command) SelfReference(io.github.wysohn.triggerreactor.core.script.wrapper.SelfReference) InvalidConfigurationException(org.bukkit.configuration.InvalidConfigurationException) TriggerReactorStopEvent(io.github.wysohn.triggerreactor.bukkit.manager.event.TriggerReactorStopEvent) HandlerList(org.bukkit.event.HandlerList) InvTriggerMigrationHelper(io.github.wysohn.triggerreactor.bukkit.tools.migration.InvTriggerMigrationHelper) Iterables(com.google.common.collect.Iterables) java.util(java.util) Cancellable(org.bukkit.event.Cancellable) ItemMeta(org.bukkit.inventory.meta.ItemMeta) ICommandMapHandler(io.github.wysohn.triggerreactor.bukkit.manager.trigger.ICommandMapHandler) Callable(java.util.concurrent.Callable) FileConfiguration(org.bukkit.configuration.file.FileConfiguration) PluginMessageListener(org.bukkit.plugin.messaging.PluginMessageListener) SQLException(java.sql.SQLException) ContinuingTasks(io.github.wysohn.triggerreactor.tools.ContinuingTasks) ByteArrayDataInput(com.google.common.io.ByteArrayDataInput) Trigger(io.github.wysohn.triggerreactor.core.manager.trigger.Trigger) TriggerInfo(io.github.wysohn.triggerreactor.core.manager.trigger.TriggerInfo) PlayerCommandPreprocessEvent(org.bukkit.event.player.PlayerCommandPreprocessEvent) Node(io.github.wysohn.triggerreactor.core.script.parser.Node) Listener(org.bukkit.event.Listener) HumanEntity(org.bukkit.entity.HumanEntity) ScriptEngineManager(javax.script.ScriptEngineManager) InventoryTrigger(io.github.wysohn.triggerreactor.core.manager.trigger.inventory.InventoryTrigger) IEvent(io.github.wysohn.triggerreactor.core.bridge.event.IEvent) Interpreter(io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter) SimpleLocation(io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation) Manager(io.github.wysohn.triggerreactor.core.manager.Manager) java.io(java.io) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) PlayerEvent(org.bukkit.event.player.PlayerEvent) Utf8YamlConfiguration(io.github.wysohn.triggerreactor.bukkit.tools.Utf8YamlConfiguration) NaiveMigrationHelper(io.github.wysohn.triggerreactor.bukkit.tools.migration.NaiveMigrationHelper) AbstractTriggerManager(io.github.wysohn.triggerreactor.core.manager.trigger.AbstractTriggerManager) ContinuingTasks(io.github.wysohn.triggerreactor.tools.ContinuingTasks) TriggerInfo(io.github.wysohn.triggerreactor.core.manager.trigger.TriggerInfo) InvTriggerMigrationHelper(io.github.wysohn.triggerreactor.bukkit.tools.migration.InvTriggerMigrationHelper)

Aggregations

Iterables (com.google.common.collect.Iterables)1 Sets (com.google.common.collect.Sets)1 ByteArrayDataInput (com.google.common.io.ByteArrayDataInput)1 ByteArrayDataOutput (com.google.common.io.ByteArrayDataOutput)1 ByteStreams (com.google.common.io.ByteStreams)1 MysqlConnectionPoolDataSource (com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource)1 BukkitCommandSender (io.github.wysohn.triggerreactor.bukkit.bridge.BukkitCommandSender)1 BukkitConfigurationSerializer (io.github.wysohn.triggerreactor.bukkit.main.serialize.BukkitConfigurationSerializer)1 TriggerReactorStartEvent (io.github.wysohn.triggerreactor.bukkit.manager.event.TriggerReactorStartEvent)1 TriggerReactorStopEvent (io.github.wysohn.triggerreactor.bukkit.manager.event.TriggerReactorStopEvent)1 ICommandMapHandler (io.github.wysohn.triggerreactor.bukkit.manager.trigger.ICommandMapHandler)1 BukkitUtil (io.github.wysohn.triggerreactor.bukkit.tools.BukkitUtil)1 Utf8YamlConfiguration (io.github.wysohn.triggerreactor.bukkit.tools.Utf8YamlConfiguration)1 InvTriggerMigrationHelper (io.github.wysohn.triggerreactor.bukkit.tools.migration.InvTriggerMigrationHelper)1 NaiveMigrationHelper (io.github.wysohn.triggerreactor.bukkit.tools.migration.NaiveMigrationHelper)1 ICommandSender (io.github.wysohn.triggerreactor.core.bridge.ICommandSender)1 IInventory (io.github.wysohn.triggerreactor.core.bridge.IInventory)1 IItemStack (io.github.wysohn.triggerreactor.core.bridge.IItemStack)1 IPlayer (io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer)1 IEvent (io.github.wysohn.triggerreactor.core.bridge.event.IEvent)1