Search in sources :

Example 6 with IConfigSource

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));
}
Also used : FileConfiguration(org.bukkit.configuration.file.FileConfiguration) IMigrationHelper(io.github.wysohn.triggerreactor.core.config.IMigrationHelper) StringReader(java.io.StringReader) IMigratable(io.github.wysohn.triggerreactor.core.config.IMigratable) IConfigSource(io.github.wysohn.triggerreactor.core.config.source.IConfigSource) File(java.io.File) Test(org.junit.Test)

Example 7 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(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 IConfigSource

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

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