Search in sources :

Example 1 with InvTriggerMigrationHelper

use of io.github.wysohn.triggerreactor.sponge.tools.migration.InvTriggerMigrationHelper in project TriggerReactor by wysohn.

the class TriggerReactor method migrateOldConfig.

private void migrateOldConfig() {
    new ContinuingTasks.Builder().append(() -> {
    // if (getPluginConfigManager().isMigrationNeeded()) {
    // File file = new File(getDataFolder(), "config.yml");
    // ConfigurationLoader<CommentedConfigurationNode> varFileConfigLoader
    // = HoconConfigurationLoader.builder().setPath(file.toPath()).build();
    // ConfigurationNode confFileConfig = null;
    // try {
    // confFileConfig = varFileConfigLoader.load();
    // } catch (IOException e) {
    // e.printStackTrace();
    // return;
    // }
    // getPluginConfigManager().migrate(new SpongeMigrationHelper(confFileConfig, file));
    // }
    }).append(() -> {
        if (getVariableManager().isMigrationNeeded()) {
            File file = new File(getDataFolder(), "var.yml");
            ConfigurationLoader<CommentedConfigurationNode> varFileConfigLoader = HoconConfigurationLoader.builder().setPath(file.toPath()).build();
            ConfigurationNode varFileConfig = null;
            try {
                varFileConfig = varFileConfigLoader.load();
            } catch (IOException e) {
                e.printStackTrace();
                return;
            }
            getVariableManager().migrate(new VariableMigrationHelper(varFileConfig, file));
        }
    }).append(() -> Optional.of(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");
        ConfigurationLoader<CommentedConfigurationNode> loader = HoconConfigurationLoader.builder().setPath(oldFile.toPath()).build();
        ConfigurationNode oldConfig = null;
        try {
            oldConfig = loader.load();
        } catch (IOException e) {
            e.printStackTrace();
            return;
        }
        triggerInfo.migrate(new InvTriggerMigrationHelper(oldFile, oldConfig));
    }))).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");
        ConfigurationLoader<CommentedConfigurationNode> loader = HoconConfigurationLoader.builder().setPath(oldFile.toPath()).build();
        ConfigurationNode oldConfig = null;
        try {
            oldConfig = loader.load();
        } catch (IOException e) {
            e.printStackTrace();
            return;
        }
        triggerInfo.migrate(new NaiveMigrationHelper(oldConfig, oldFile));
    }))).run();
}
Also used : AbstractRepeatingTriggerManager(io.github.wysohn.triggerreactor.core.manager.trigger.repeating.AbstractRepeatingTriggerManager) ConsoleSource(org.spongepowered.api.command.source.ConsoleSource) EventContextKeys(org.spongepowered.api.event.cause.EventContextKeys) Inject(com.google.inject.Inject) io.github.wysohn.triggerreactor.core.manager(io.github.wysohn.triggerreactor.core.manager) GameInitializationEvent(org.spongepowered.api.event.game.state.GameInitializationEvent) CommandCallable(org.spongepowered.api.command.CommandCallable) GsonConfigSource(io.github.wysohn.triggerreactor.core.config.source.GsonConfigSource) APISupport(io.github.wysohn.triggerreactor.sponge.manager.trigger.share.api.APISupport) AbstractLocationBasedTriggerManager(io.github.wysohn.triggerreactor.core.manager.trigger.location.AbstractLocationBasedTriggerManager) ConfigurationLoader(ninja.leaping.configurate.loader.ConfigurationLoader) SpongeDataSerializer(io.github.wysohn.triggerreactor.sponge.main.serialize.SpongeDataSerializer) ICommandSender(io.github.wysohn.triggerreactor.core.bridge.ICommandSender) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Future(java.util.concurrent.Future) AbstractInventoryTriggerManager(io.github.wysohn.triggerreactor.core.manager.trigger.inventory.AbstractInventoryTriggerManager) IItemStack(io.github.wysohn.triggerreactor.core.bridge.IItemStack) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) AbstractAreaTriggerManager(io.github.wysohn.triggerreactor.core.manager.trigger.area.AbstractAreaTriggerManager) MetricsLite2(org.bstats.sponge.MetricsLite2) Path(java.nio.file.Path) AbstractCustomTriggerManager(io.github.wysohn.triggerreactor.core.manager.trigger.custom.AbstractCustomTriggerManager) ScriptException(javax.script.ScriptException) Location(org.spongepowered.api.world.Location) AbstractTriggerManager(io.github.wysohn.triggerreactor.core.manager.trigger.AbstractTriggerManager) GameReloadEvent(org.spongepowered.api.event.game.GameReloadEvent) CommandSource(org.spongepowered.api.command.CommandSource) IInventory(io.github.wysohn.triggerreactor.core.bridge.IInventory) BlockTypes(org.spongepowered.api.block.BlockTypes) Sponge(org.spongepowered.api.Sponge) Carrier(org.spongepowered.api.item.inventory.Carrier) Logger(java.util.logging.Logger) IPlayer(io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer) Cause(org.spongepowered.api.event.cause.Cause) NaiveMigrationHelper(io.github.wysohn.triggerreactor.sponge.tools.migration.NaiveMigrationHelper) Cancellable(org.spongepowered.api.event.Cancellable) CarriedInventory(org.spongepowered.api.item.inventory.type.CarriedInventory) World(org.spongepowered.api.world.World) GameStartedServerEvent(org.spongepowered.api.event.game.state.GameStartedServerEvent) Entry(java.util.Map.Entry) InvTriggerMigrationHelper(io.github.wysohn.triggerreactor.sponge.tools.migration.InvTriggerMigrationHelper) SelfReference(io.github.wysohn.triggerreactor.core.script.wrapper.SelfReference) Player(org.spongepowered.api.entity.living.player.Player) EventContext(org.spongepowered.api.event.cause.EventContext) Inventory(org.spongepowered.api.item.inventory.Inventory) AbstractAPISupport(io.github.wysohn.triggerreactor.core.manager.trigger.share.api.AbstractAPISupport) java.util(java.util) Keys(org.spongepowered.api.data.key.Keys) GameStoppingServerEvent(org.spongepowered.api.event.game.state.GameStoppingServerEvent) Callable(java.util.concurrent.Callable) SpongeInventory(io.github.wysohn.triggerreactor.sponge.bridge.SpongeInventory) DelegatedPlayer(io.github.wysohn.triggerreactor.sponge.tools.DelegatedPlayer) DataSerializable(org.spongepowered.api.data.DataSerializable) TriggerReactorStopEvent(io.github.wysohn.triggerreactor.sponge.manager.event.TriggerReactorStopEvent) ContinuingTasks(io.github.wysohn.triggerreactor.tools.ContinuingTasks) Text(org.spongepowered.api.text.Text) TabCompleteEvent(org.spongepowered.api.event.command.TabCompleteEvent) Trigger(io.github.wysohn.triggerreactor.core.manager.trigger.Trigger) TriggerInfo(io.github.wysohn.triggerreactor.core.manager.trigger.TriggerInfo) CauseStackManager(org.spongepowered.api.event.CauseStackManager) PluginContainer(org.spongepowered.api.plugin.PluginContainer) ProcessInterrupter(io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.ProcessInterrupter) io.github.wysohn.triggerreactor.sponge.manager.trigger(io.github.wysohn.triggerreactor.sponge.manager.trigger) Node(io.github.wysohn.triggerreactor.core.script.parser.Node) CommandResult(org.spongepowered.api.command.CommandResult) AbstractCommandTriggerManager(io.github.wysohn.triggerreactor.core.manager.trigger.command.AbstractCommandTriggerManager) SpongeCommandSender(io.github.wysohn.triggerreactor.sponge.bridge.SpongeCommandSender) HoconConfigurationLoader(ninja.leaping.configurate.hocon.HoconConfigurationLoader) CommentedConfigurationNode(ninja.leaping.configurate.commented.CommentedConfigurationNode) Event(org.spongepowered.api.event.Event) SpongeExecutorService(org.spongepowered.api.scheduler.SpongeExecutorService) ConfigDir(org.spongepowered.api.config.ConfigDir) InventoryTrigger(io.github.wysohn.triggerreactor.core.manager.trigger.inventory.InventoryTrigger) InteractInventoryEvent(org.spongepowered.api.event.item.inventory.InteractInventoryEvent) IOException(java.io.IOException) IEvent(io.github.wysohn.triggerreactor.core.bridge.event.IEvent) CommonFunctions(io.github.wysohn.triggerreactor.sponge.manager.trigger.share.CommonFunctions) VariableMigrationHelper(io.github.wysohn.triggerreactor.sponge.tools.migration.VariableMigrationHelper) Interpreter(io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter) AbstractNamedTriggerManager(io.github.wysohn.triggerreactor.core.manager.trigger.named.AbstractNamedTriggerManager) Lag(io.github.wysohn.triggerreactor.tools.Lag) Entity(org.spongepowered.api.entity.Entity) io.github.wysohn.triggerreactor.sponge.manager(io.github.wysohn.triggerreactor.sponge.manager) File(java.io.File) TriggerReactorStartEvent(io.github.wysohn.triggerreactor.sponge.manager.event.TriggerReactorStartEvent) CommandException(org.spongepowered.api.command.CommandException) SimpleLocation(io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation) Plugin(org.spongepowered.api.plugin.Plugin) SpongePlayer(io.github.wysohn.triggerreactor.sponge.bridge.entity.SpongePlayer) SpongeWrapper(io.github.wysohn.triggerreactor.sponge.bridge.SpongeWrapper) GameAboutToStartServerEvent(org.spongepowered.api.event.game.state.GameAboutToStartServerEvent) Listener(org.spongepowered.api.event.Listener) SendCommandEvent(org.spongepowered.api.event.command.SendCommandEvent) TriggerInfo(io.github.wysohn.triggerreactor.core.manager.trigger.TriggerInfo) VariableMigrationHelper(io.github.wysohn.triggerreactor.sponge.tools.migration.VariableMigrationHelper) InvTriggerMigrationHelper(io.github.wysohn.triggerreactor.sponge.tools.migration.InvTriggerMigrationHelper) IOException(java.io.IOException) AbstractTriggerManager(io.github.wysohn.triggerreactor.core.manager.trigger.AbstractTriggerManager) NaiveMigrationHelper(io.github.wysohn.triggerreactor.sponge.tools.migration.NaiveMigrationHelper) ContinuingTasks(io.github.wysohn.triggerreactor.tools.ContinuingTasks) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) CommentedConfigurationNode(ninja.leaping.configurate.commented.CommentedConfigurationNode) CommentedConfigurationNode(ninja.leaping.configurate.commented.CommentedConfigurationNode) File(java.io.File) ConfigurationLoader(ninja.leaping.configurate.loader.ConfigurationLoader) HoconConfigurationLoader(ninja.leaping.configurate.hocon.HoconConfigurationLoader)

Aggregations

Inject (com.google.inject.Inject)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 GsonConfigSource (io.github.wysohn.triggerreactor.core.config.source.GsonConfigSource)1 io.github.wysohn.triggerreactor.core.manager (io.github.wysohn.triggerreactor.core.manager)1 SimpleLocation (io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation)1 AbstractTriggerManager (io.github.wysohn.triggerreactor.core.manager.trigger.AbstractTriggerManager)1 Trigger (io.github.wysohn.triggerreactor.core.manager.trigger.Trigger)1 TriggerInfo (io.github.wysohn.triggerreactor.core.manager.trigger.TriggerInfo)1 AbstractAreaTriggerManager (io.github.wysohn.triggerreactor.core.manager.trigger.area.AbstractAreaTriggerManager)1 AbstractCommandTriggerManager (io.github.wysohn.triggerreactor.core.manager.trigger.command.AbstractCommandTriggerManager)1 AbstractCustomTriggerManager (io.github.wysohn.triggerreactor.core.manager.trigger.custom.AbstractCustomTriggerManager)1 AbstractInventoryTriggerManager (io.github.wysohn.triggerreactor.core.manager.trigger.inventory.AbstractInventoryTriggerManager)1 InventoryTrigger (io.github.wysohn.triggerreactor.core.manager.trigger.inventory.InventoryTrigger)1 AbstractLocationBasedTriggerManager (io.github.wysohn.triggerreactor.core.manager.trigger.location.AbstractLocationBasedTriggerManager)1 AbstractNamedTriggerManager (io.github.wysohn.triggerreactor.core.manager.trigger.named.AbstractNamedTriggerManager)1 AbstractRepeatingTriggerManager (io.github.wysohn.triggerreactor.core.manager.trigger.repeating.AbstractRepeatingTriggerManager)1