Search in sources :

Example 6 with SimpleLocation

use of io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation in project TriggerReactor by wysohn.

the class AbstractLocationBasedTriggerManager method loadTriggers.

private void loadTriggers(File[] target) {
    for (File file : target) {
        if (file.isDirectory()) {
            loadTriggers(file.listFiles());
        } else {
            if (!isTriggerFile(file))
                continue;
            String triggerName = extractName(file);
            SimpleLocation sloc = null;
            try {
                sloc = stringToSloc(triggerName);
            } catch (Exception e) {
                e.printStackTrace();
                continue;
            }
            String script = null;
            try {
                script = FileUtil.readFromFile(file);
            } catch (IOException e1) {
                e1.printStackTrace();
                continue;
            }
            T trigger = null;
            try {
                trigger = constructTrigger(sloc.toString(), script);
            } catch (TriggerInitFailedException e) {
                e.printStackTrace();
                continue;
            }
            if (sloc != null && trigger != null) {
                SimpleChunkLocation scloc = new SimpleChunkLocation(sloc);
                Map<SimpleLocation, T> triggerMap = locationTriggers.get(scloc);
                if (!locationTriggers.containsKey(scloc)) {
                    triggerMap = new ConcurrentHashMap<>();
                    locationTriggers.put(scloc, triggerMap);
                }
                if (triggerMap.containsKey(sloc)) {
                    Trigger previous = triggerMap.get(sloc);
                    plugin.getLogger().warning("Found a duplicating " + trigger.getClass().getSimpleName());
                    plugin.getLogger().warning("Existing: " + previous.file.getAbsolutePath());
                    plugin.getLogger().warning("Skipped: " + trigger.file.getAbsolutePath());
                } else {
                    triggerMap.put(sloc, trigger);
                }
            }
        }
    }
}
Also used : Trigger(io.github.wysohn.triggerreactor.core.manager.trigger.AbstractTriggerManager.Trigger) SimpleChunkLocation(io.github.wysohn.triggerreactor.core.manager.location.SimpleChunkLocation) SimpleLocation(io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation) IOException(java.io.IOException) File(java.io.File) IOException(java.io.IOException)

Example 7 with SimpleLocation

use of io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation in project TriggerReactor by wysohn.

the class AbstractLocationBasedTriggerManager method getTriggerForLocation.

protected T getTriggerForLocation(SimpleLocation sloc) {
    SimpleChunkLocation scloc = new SimpleChunkLocation(sloc);
    if (!locationTriggers.containsKey(scloc))
        return null;
    Map<SimpleLocation, T> triggerMap = locationTriggers.get(scloc);
    if (!triggerMap.containsKey(sloc))
        return null;
    T trigger = triggerMap.get(sloc);
    return trigger;
}
Also used : SimpleChunkLocation(io.github.wysohn.triggerreactor.core.manager.location.SimpleChunkLocation) SimpleLocation(io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation)

Example 8 with SimpleLocation

use of io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation in project TriggerReactor by wysohn.

the class AbstractLocationBasedTriggerManager method setTriggerForLocation.

protected void setTriggerForLocation(SimpleLocation sloc, T trigger) {
    SimpleChunkLocation scloc = new SimpleChunkLocation(sloc);
    Map<SimpleLocation, T> triggerMap = locationTriggers.get(scloc);
    if (!locationTriggers.containsKey(scloc)) {
        triggerMap = new ConcurrentHashMap<>();
        locationTriggers.put(scloc, triggerMap);
    }
    triggerMap.put(sloc, trigger);
    plugin.saveAsynchronously(this);
}
Also used : SimpleChunkLocation(io.github.wysohn.triggerreactor.core.manager.location.SimpleChunkLocation) SimpleLocation(io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation)

Example 9 with SimpleLocation

use of io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation in project TriggerReactor by wysohn.

the class LocationUtil method convertToBukkitLocation.

public static Location convertToBukkitLocation(SimpleLocation sloc) {
    World world = Bukkit.getWorld(sloc.getWorld());
    int x = sloc.getX();
    int y = sloc.getY();
    int z = sloc.getZ();
    return new Location(world, x + 0.5, y, z + 0.5);
}
Also used : World(org.bukkit.World) SimpleLocation(io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation) Location(org.bukkit.Location) SimpleChunkLocation(io.github.wysohn.triggerreactor.core.manager.location.SimpleChunkLocation)

Example 10 with SimpleLocation

use of io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation in project TriggerReactor by wysohn.

the class AbstractAreaSelectionManager method onClick.

/**
 * gets called when player clicks on a block.
 * <b>This should be called manually by the child class upon player interaction event.</b>
 * @param action the {@link ClickAction} associated with this player interaction.
 * @param uuid the uuid of player
 * @param sloc location where interaction occurred
 * @return the result as {@link ClickResult}
 */
protected ClickResult onClick(ClickAction action, UUID uuid, SimpleLocation sloc) {
    if (action == ClickAction.LEFT_CLICK_BLOCK) {
        leftPosition.put(uuid, sloc);
    } else if (action == ClickAction.RIGHT_CLICK_BLOCK) {
        rightPosition.put(uuid, sloc);
    }
    SimpleLocation left = leftPosition.get(uuid);
    SimpleLocation right = rightPosition.get(uuid);
    if (left != null && right != null) {
        if (!left.getWorld().equals(right.getWorld())) {
            return ClickResult.DIFFERENTWORLD;
        }
        return ClickResult.COMPLETE;
    } else if (left != null) {
        return ClickResult.LEFTSET;
    } else if (right != null) {
        return ClickResult.RIGHTSET;
    } else {
        return null;
    }
}
Also used : SimpleLocation(io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation)

Aggregations

SimpleLocation (io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation)20 Location (org.bukkit.Location)8 Player (org.bukkit.entity.Player)8 SimpleChunkLocation (io.github.wysohn.triggerreactor.core.manager.location.SimpleChunkLocation)7 EventHandler (org.bukkit.event.EventHandler)5 IOException (java.io.IOException)4 Trigger (io.github.wysohn.triggerreactor.core.manager.trigger.AbstractTriggerManager.Trigger)3 File (java.io.File)3 Area (io.github.wysohn.triggerreactor.core.manager.location.Area)2 HashMap (java.util.HashMap)2 BukkitPlayerBlockLocationEvent (io.github.wysohn.triggerreactor.bukkit.bridge.event.BukkitPlayerBlockLocationEvent)1 BukkitPlayer (io.github.wysohn.triggerreactor.bukkit.bridge.player.BukkitPlayer)1 PlayerBlockLocationEvent (io.github.wysohn.triggerreactor.bukkit.manager.event.PlayerBlockLocationEvent)1 DelegatedPlayer (io.github.wysohn.triggerreactor.bukkit.tools.DelegatedPlayer)1 IPlayer (io.github.wysohn.triggerreactor.core.bridge.player.IPlayer)1 InventoryTrigger (io.github.wysohn.triggerreactor.core.manager.trigger.AbstractInventoryTriggerManager.InventoryTrigger)1 FileFilter (java.io.FileFilter)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 UUID (java.util.UUID)1