Search in sources :

Example 6 with TriggerInfo

use of io.github.wysohn.triggerreactor.core.manager.trigger.TriggerInfo in project TriggerReactor by wysohn.

the class LocationBasedTriggerManager method handleLocationSetting.

private void handleLocationSetting(BlockSnapshot clicked, Player p) {
    IPlayer player = new SpongePlayer(p);
    Location<World> loc = clicked.getLocation().orElse(null);
    if (loc == null)
        return;
    T trigger = getTriggerForLocation(loc);
    if (trigger != null) {
        p.sendMessage(Text.builder("Another trigger is set at there!").color(TextColors.RED).build());
        showTriggerInfo(player, clicked);
        return;
    }
    String script = getSettingLocationScript(player);
    if (script == null) {
        p.sendMessage(Text.builder("Could not find script... but how?").color(TextColors.RED).build());
        return;
    }
    File file = getTriggerFile(folder, LocationUtil.convertToSimpleLocation(loc).toString(), true);
    try {
        String name = TriggerInfo.extractName(file);
        IConfigSource config = configSourceFactory.create(folder, name);
        TriggerInfo info = TriggerInfo.defaultInfo(file, config);
        trigger = newTrigger(info, script);
    } catch (Exception e1) {
        p.sendMessage(Text.builder("Encounterd an error!").color(TextColors.RED).build());
        p.sendMessage(Text.builder(e1.getMessage()).color(TextColors.RED).build());
        p.sendMessage(Text.builder("If you are an administrator, check console to see details.").color(TextColors.RED).build());
        e1.printStackTrace();
        stopLocationSet(player);
        return;
    }
    setTriggerForLocation(loc, trigger);
    showTriggerInfo(player, clicked);
    stopLocationSet(player);
    plugin.saveAsynchronously(this);
}
Also used : IPlayer(io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer) SpongePlayer(io.github.wysohn.triggerreactor.sponge.bridge.entity.SpongePlayer) TriggerInfo(io.github.wysohn.triggerreactor.core.manager.trigger.TriggerInfo) World(org.spongepowered.api.world.World) IConfigSource(io.github.wysohn.triggerreactor.core.config.source.IConfigSource) File(java.io.File)

Example 7 with TriggerInfo

use of io.github.wysohn.triggerreactor.core.manager.trigger.TriggerInfo in project TriggerReactor by wysohn.

the class LocationBasedTriggerManager method handleLocationSetting.

private void handleLocationSetting(Block clicked, Player p) {
    IPlayer bukkitPlayer = BukkitTriggerReactorCore.getWrapper().wrap(p);
    Location loc = clicked.getLocation();
    T trigger = getTriggerForLocation(loc);
    if (trigger != null) {
        bukkitPlayer.sendMessage(ChatColor.RED + "Another trigger is set at there!");
        showTriggerInfo(bukkitPlayer, clicked);
        return;
    }
    String script = getSettingLocationScript(bukkitPlayer);
    if (script == null) {
        bukkitPlayer.sendMessage(ChatColor.RED + "Could not find script... but how?");
        return;
    }
    File file = getTriggerFile(folder, LocationUtil.convertToSimpleLocation(loc).toString(), true);
    try {
        String name = TriggerInfo.extractName(file);
        IConfigSource config = configSourceFactory.create(folder, name);
        TriggerInfo info = TriggerInfo.defaultInfo(file, config);
        trigger = newTrigger(info, script);
    } catch (TriggerInitFailedException e1) {
        bukkitPlayer.sendMessage(ChatColor.RED + "Encounterd an error!");
        bukkitPlayer.sendMessage(ChatColor.RED + e1.getMessage());
        bukkitPlayer.sendMessage(ChatColor.RED + "If you are an administrator, check console to see details.");
        e1.printStackTrace();
        stopLocationSet(bukkitPlayer);
        return;
    }
    setTriggerForLocation(loc, trigger);
    showTriggerInfo(bukkitPlayer, clicked);
    stopLocationSet(bukkitPlayer);
    plugin.saveAsynchronously(this);
}
Also used : IPlayer(io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer) TriggerInfo(io.github.wysohn.triggerreactor.core.manager.trigger.TriggerInfo) IConfigSource(io.github.wysohn.triggerreactor.core.config.source.IConfigSource) File(java.io.File) Location(org.bukkit.Location) SimpleLocation(io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation) SimpleChunkLocation(io.github.wysohn.triggerreactor.core.manager.location.SimpleChunkLocation)

Example 8 with TriggerInfo

use of io.github.wysohn.triggerreactor.core.manager.trigger.TriggerInfo 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)

Example 9 with TriggerInfo

use of io.github.wysohn.triggerreactor.core.manager.trigger.TriggerInfo in project TriggerReactor by wysohn.

the class AbstractInventoryTriggerManager method createTrigger.

/**
 * @param name this can contain color code &, but you should specify exact
 *             name for the title.
 * @return true on success; false if already exist
 * @throws ParserException See {@link Trigger#init()}
 * @throws LexerException  See {@link Trigger#init()}
 * @throws IOException     See {@link Trigger#init()}
 */
public boolean createTrigger(int size, String name, String script) throws TriggerInitFailedException {
    if (has(name))
        return false;
    File file = getTriggerFile(folder, name, true);
    IConfigSource config = configSourceFactory.create(folder, name);
    TriggerInfo info = TriggerInfo.defaultInfo(file, config);
    put(name, new InventoryTrigger(info, script, size, new HashMap<>()));
    return true;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) TriggerInfo(io.github.wysohn.triggerreactor.core.manager.trigger.TriggerInfo) IConfigSource(io.github.wysohn.triggerreactor.core.config.source.IConfigSource) File(java.io.File)

Aggregations

TriggerInfo (io.github.wysohn.triggerreactor.core.manager.trigger.TriggerInfo)9 File (java.io.File)7 IConfigSource (io.github.wysohn.triggerreactor.core.config.source.IConfigSource)6 IPlayer (io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer)5 SimpleLocation (io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation)4 ICommandSender (io.github.wysohn.triggerreactor.core.bridge.ICommandSender)3 IInventory (io.github.wysohn.triggerreactor.core.bridge.IInventory)3 IItemStack (io.github.wysohn.triggerreactor.core.bridge.IItemStack)3 IEvent (io.github.wysohn.triggerreactor.core.bridge.event.IEvent)3 AbstractTriggerManager (io.github.wysohn.triggerreactor.core.manager.trigger.AbstractTriggerManager)3 Trigger (io.github.wysohn.triggerreactor.core.manager.trigger.Trigger)3 InventoryTrigger (io.github.wysohn.triggerreactor.core.manager.trigger.inventory.InventoryTrigger)3 Interpreter (io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter)3 SelfReference (io.github.wysohn.triggerreactor.core.script.wrapper.SelfReference)3 GsonConfigSource (io.github.wysohn.triggerreactor.core.config.source.GsonConfigSource)2 io.github.wysohn.triggerreactor.core.manager (io.github.wysohn.triggerreactor.core.manager)2 SimpleChunkLocation (io.github.wysohn.triggerreactor.core.manager.location.SimpleChunkLocation)2 AbstractAreaTriggerManager (io.github.wysohn.triggerreactor.core.manager.trigger.area.AbstractAreaTriggerManager)2 AbstractCommandTriggerManager (io.github.wysohn.triggerreactor.core.manager.trigger.command.AbstractCommandTriggerManager)2 AbstractCustomTriggerManager (io.github.wysohn.triggerreactor.core.manager.trigger.custom.AbstractCustomTriggerManager)2