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