use of io.github.wysohn.triggerreactor.core.config.source.IConfigSource in project TriggerReactor by wysohn.
the class NaiveMigrationHelperTest method migrate.
@Test
public void migrate() {
IConfigSource mockSource = mock(IConfigSource.class);
FileConfiguration mockConfig = YamlConfiguration.loadConfiguration(new StringReader("" + "Mysql:\n" + " Enable: false\n" + " Address: 127.0.0.1:3306\n" + " DbName: TriggerReactor\n" + " UserName: root\n" + " Password: '1234'\n" + " Deep: \n" + " Value: 5555\n" + " Value2: 52.24\n" + "PermissionManager:\n" + " Intercept: true" + ""));
File mockFile = mock(File.class);
IMigratable mockMigratable = new IMigratable() {
@Override
public boolean isMigrationNeeded() {
return true;
}
@Override
public void migrate(IMigrationHelper migrationHelper) {
migrationHelper.migrate(mockSource);
}
};
NaiveMigrationHelper helper = new NaiveMigrationHelper(mockConfig, mockFile);
mockMigratable.migrate(helper);
Mockito.verify(mockSource).put(Mockito.eq("Mysql.Enable"), Mockito.eq(false));
Mockito.verify(mockSource).put(Mockito.eq("Mysql.Address"), Mockito.eq("127.0.0.1:3306"));
Mockito.verify(mockSource).put(Mockito.eq("Mysql.DbName"), Mockito.eq("TriggerReactor"));
Mockito.verify(mockSource).put(Mockito.eq("Mysql.UserName"), Mockito.eq("root"));
Mockito.verify(mockSource).put(Mockito.eq("Mysql.Password"), Mockito.eq("1234"));
Mockito.verify(mockSource).put(Mockito.eq("Mysql.Deep.Value"), Mockito.eq(5555));
Mockito.verify(mockSource).put(Mockito.eq("Mysql.Deep.Value2"), Mockito.eq(52.24));
Mockito.verify(mockSource).put(Mockito.eq("PermissionManager.Intercept"), Mockito.eq(true));
}
use of io.github.wysohn.triggerreactor.core.config.source.IConfigSource 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.config.source.IConfigSource 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