Search in sources :

Example 1 with IConfigSource

use of io.github.wysohn.triggerreactor.core.config.source.IConfigSource in project TriggerReactor by wysohn.

the class AbstractCommandTriggerManager method addCommandTrigger.

/**
 * @param adding CommandSender to send error message on script error
 * @param cmd    command to intercept
 * @param script script to be executed
 * @return true on success; false if cmd already binded.
 */
public boolean addCommandTrigger(ICommandSender adding, String cmd, String script) {
    if (has(cmd))
        return false;
    File file = getTriggerFile(folder, cmd, true);
    CommandTrigger trigger = null;
    try {
        String name = TriggerInfo.extractName(file);
        IConfigSource config = configSourceFactory.create(folder, name);
        TriggerInfo info = TriggerInfo.defaultInfo(file, config);
        trigger = new CommandTrigger(info, script);
    } catch (TriggerInitFailedException e1) {
        plugin.handleException(adding, e1);
        return false;
    }
    put(cmd, trigger);
    if (!registerCommand(cmd, trigger))
        return false;
    synchronizeCommandMap();
    plugin.saveAsynchronously(this);
    return true;
}
Also used : TriggerInfo(io.github.wysohn.triggerreactor.core.manager.trigger.TriggerInfo) IConfigSource(io.github.wysohn.triggerreactor.core.config.source.IConfigSource) File(java.io.File)

Example 2 with IConfigSource

use of io.github.wysohn.triggerreactor.core.config.source.IConfigSource in project TriggerReactor by wysohn.

the class AbstractRepeatingTriggerManager method createTrigger.

/**
 * Create trigger.
 *
 * @param triggerName name of the trigger.
 * @param script      the code.
 * @param interval    interval in milliseconds.
 * @return true on success; false if already exists.
 * @throws IOException     See {@link Trigger#init()}
 * @throws LexerException  See {@link Trigger#init()}
 * @throws ParserException See {@link Trigger#init()}
 */
public boolean createTrigger(String triggerName, File file, String script, long interval) throws TriggerInitFailedException, IOException {
    if (get(triggerName) != null) {
        return false;
    }
    String name = TriggerInfo.extractName(file);
    IConfigSource config = configSourceFactory.create(folder, name);
    TriggerInfo info = TriggerInfo.defaultInfo(file, config);
    RepeatingTrigger trigger = new RepeatingTrigger(info, script, interval);
    put(triggerName, trigger);
    return true;
}
Also used : TriggerInfo(io.github.wysohn.triggerreactor.core.manager.trigger.TriggerInfo) IConfigSource(io.github.wysohn.triggerreactor.core.config.source.IConfigSource)

Example 3 with IConfigSource

use of io.github.wysohn.triggerreactor.core.config.source.IConfigSource in project TriggerReactor by wysohn.

the class AbstractAreaTriggerManager method createArea.

/**
 * Create a new Area Trigger.
 *
 * @param name     name of the Area Trigger.
 * @param smallest smallest point (ex. 0,0,0)
 * @param largest  largest point(ex. 15,15,15)
 * @return true on success; false if exact same area (same smallest and largest) already exist.
 */
public boolean createArea(String name, SimpleLocation smallest, SimpleLocation largest) {
    Area area = new Area(smallest, largest);
    // exact same area found
    if (!getConflictingAreas(area, area::equals).isEmpty())
        return false;
    File areaFolder = new File(folder, name);
    IConfigSource config = configSourceFactory.create(folder, name);
    AreaTrigger trigger = new AreaTrigger(new AreaTriggerInfo(areaFolder, config, name), area, areaFolder);
    put(name, trigger);
    setupArea(trigger);
    return true;
}
Also used : Area(io.github.wysohn.triggerreactor.core.manager.location.Area) IConfigSource(io.github.wysohn.triggerreactor.core.config.source.IConfigSource) File(java.io.File)

Example 4 with IConfigSource

use of io.github.wysohn.triggerreactor.core.config.source.IConfigSource in project TriggerReactor by wysohn.

the class AbstractCustomTriggerManager method createCustomTrigger.

/**
 * Create a new CustomTrigger.
 *
 * @param eventName the class name of the Event that this Custom Trigger will
 *                  handle.
 * @param name      name of trigger (unique)
 * @param script    the script
 * @return true if created; false if trigger with the 'name' already exists.
 * @throws ClassNotFoundException throws if className is not in abbreviation list, not a valid
 *                                class name, or the specified event is not a valid event to
 *                                handle.
 * @throws ParserException
 * @throws LexerException
 * @throws IOException
 */
public boolean createCustomTrigger(String eventName, String name, String script) throws ClassNotFoundException, TriggerInitFailedException {
    if (has(name))
        return false;
    Class<?> event = registry.getEvent(eventName);
    File file = getTriggerFile(folder, name, true);
    IConfigSource config = configSourceFactory.create(folder, name);
    TriggerInfo info = TriggerInfo.defaultInfo(file, config);
    CustomTrigger trigger = new CustomTrigger(info, script, event, eventName);
    put(name, trigger);
    this.registerEvent(plugin, event, trigger);
    return true;
}
Also used : TriggerInfo(io.github.wysohn.triggerreactor.core.manager.trigger.TriggerInfo) IConfigSource(io.github.wysohn.triggerreactor.core.config.source.IConfigSource) File(java.io.File)

Example 5 with IConfigSource

use of io.github.wysohn.triggerreactor.core.config.source.IConfigSource 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)

Aggregations

IConfigSource (io.github.wysohn.triggerreactor.core.config.source.IConfigSource)8 File (java.io.File)7 TriggerInfo (io.github.wysohn.triggerreactor.core.manager.trigger.TriggerInfo)6 IPlayer (io.github.wysohn.triggerreactor.core.bridge.entity.IPlayer)2 IMigratable (io.github.wysohn.triggerreactor.core.config.IMigratable)1 IMigrationHelper (io.github.wysohn.triggerreactor.core.config.IMigrationHelper)1 Area (io.github.wysohn.triggerreactor.core.manager.location.Area)1 SimpleChunkLocation (io.github.wysohn.triggerreactor.core.manager.location.SimpleChunkLocation)1 SimpleLocation (io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation)1 SpongePlayer (io.github.wysohn.triggerreactor.sponge.bridge.entity.SpongePlayer)1 StringReader (java.io.StringReader)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Location (org.bukkit.Location)1 FileConfiguration (org.bukkit.configuration.file.FileConfiguration)1 Test (org.junit.Test)1 World (org.spongepowered.api.world.World)1