Search in sources :

Example 1 with SimpleChunkLocation

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

the class SpongePlayer method getChunk.

@Override
public SimpleChunkLocation getChunk() {
    World world = player.getLocation().getExtent();
    Vector3i vector = player.getLocation().getChunkPosition();
    return new SimpleChunkLocation(world.getName(), vector.getX(), vector.getZ());
}
Also used : Vector3i(com.flowpowered.math.vector.Vector3i) SimpleChunkLocation(io.github.wysohn.triggerreactor.core.manager.location.SimpleChunkLocation) World(org.spongepowered.api.world.World)

Example 2 with SimpleChunkLocation

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

the class AbstractAreaTriggerManager method setupArea.

/**
 * reset the area cache. Should be called for reloading.
 * @param trigger
 */
protected void setupArea(AreaTrigger trigger) {
    Area area = trigger.area;
    Set<SimpleChunkLocation> sclocs = Area.getAllChunkLocations(area);
    for (SimpleChunkLocation scloc : sclocs) {
        Map<Area, AreaTrigger> map = areaTriggers.get(scloc);
        if (map == null) {
            map = new ConcurrentHashMap<>();
            areaTriggers.put(scloc, map);
        }
        map.put(area, trigger);
    }
}
Also used : Area(io.github.wysohn.triggerreactor.core.manager.location.Area) SimpleChunkLocation(io.github.wysohn.triggerreactor.core.manager.location.SimpleChunkLocation)

Example 3 with SimpleChunkLocation

use of io.github.wysohn.triggerreactor.core.manager.location.SimpleChunkLocation 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 4 with SimpleChunkLocation

use of io.github.wysohn.triggerreactor.core.manager.location.SimpleChunkLocation 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 5 with SimpleChunkLocation

use of io.github.wysohn.triggerreactor.core.manager.location.SimpleChunkLocation 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)

Aggregations

SimpleChunkLocation (io.github.wysohn.triggerreactor.core.manager.location.SimpleChunkLocation)12 Area (io.github.wysohn.triggerreactor.core.manager.location.Area)6 SimpleLocation (io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation)5 File (java.io.File)3 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Trigger (io.github.wysohn.triggerreactor.core.manager.trigger.AbstractTriggerManager.Trigger)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Vector3i (com.flowpowered.math.vector.Vector3i)1 IInventory (io.github.wysohn.triggerreactor.core.bridge.IInventory)1 IItemStack (io.github.wysohn.triggerreactor.core.bridge.IItemStack)1 ILocation (io.github.wysohn.triggerreactor.core.bridge.ILocation)1 IPlayer (io.github.wysohn.triggerreactor.core.bridge.player.IPlayer)1 AbstractAreaSelectionManager (io.github.wysohn.triggerreactor.core.manager.AbstractAreaSelectionManager)1 AbstractExecutorManager (io.github.wysohn.triggerreactor.core.manager.AbstractExecutorManager)1 AbstractPermissionManager (io.github.wysohn.triggerreactor.core.manager.AbstractPermissionManager)1 AbstractPlaceholderManager (io.github.wysohn.triggerreactor.core.manager.AbstractPlaceholderManager)1 AbstractPlayerLocationManager (io.github.wysohn.triggerreactor.core.manager.AbstractPlayerLocationManager)1