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;
}
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;
}
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;
}
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;
}
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);
}
Aggregations