Search in sources :

Example 6 with Area

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

the class AbstractAreaTriggerManager method saveAll.

@Override
public void saveAll() {
    Set<AreaTrigger> saveReady = new HashSet<>();
    for (Entry<SimpleChunkLocation, Map<Area, AreaTrigger>> oentry : areaTriggers.entrySet()) {
        SimpleChunkLocation scloc = oentry.getKey();
        for (Entry<Area, AreaTrigger> entry : oentry.getValue().entrySet()) {
            Area area = entry.getKey();
            AreaTrigger trigger = entry.getValue();
            saveReady.add(trigger);
        }
    }
    for (AreaTrigger trigger : saveReady) {
        Area area = trigger.getArea();
        File ymlfile = new File(folder, trigger.getTriggerName() + ".yml");
        if (!ymlfile.exists()) {
            try {
                ymlfile.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
                plugin.getLogger().warning("Could not create " + ymlfile);
                continue;
            }
        }
        try {
            setData(ymlfile, SMALLEST, area.getSmallest().toString());
            setData(ymlfile, LARGEST, area.getLargest().toString());
            setData(ymlfile, SYNC, trigger.isSync());
        } catch (IOException e1) {
            e1.printStackTrace();
            continue;
        }
        File triggerFolder = new File(folder, trigger.getTriggerName());
        if (!triggerFolder.exists()) {
            triggerFolder.mkdirs();
        }
        if (trigger.getEnterTrigger() != null) {
            try {
                FileUtil.writeToFile(new File(triggerFolder, "Enter.trg"), trigger.getEnterTrigger().getScript());
            } catch (IOException e) {
                e.printStackTrace();
                plugin.getLogger().warning("Could not save Area Trigger [Enter] " + trigger.getTriggerName());
            }
        }
        if (trigger.getExitTrigger() != null) {
            try {
                FileUtil.writeToFile(new File(triggerFolder, "Exit.trg"), trigger.getExitTrigger().getScript());
            } catch (IOException e) {
                e.printStackTrace();
                plugin.getLogger().warning("Could not save Area Trigger [Exit] " + trigger.getTriggerName());
            }
        }
    }
}
Also used : Area(io.github.wysohn.triggerreactor.core.manager.location.Area) SimpleChunkLocation(io.github.wysohn.triggerreactor.core.manager.location.SimpleChunkLocation) IOException(java.io.IOException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map) File(java.io.File) HashSet(java.util.HashSet)

Example 7 with Area

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

the class AbstractAreaTriggerManager method getConflictingAreas.

/**
 * get all the area that is conflicting with given area. This does not include the area itself.
 * It's quite a CPU intensive work; use it wisely
 * @param area
 * @return never be null; can be empty if no conflicts are found
 */
public Set<Area> getConflictingAreas(Area area) {
    Set<Area> conflicts = new HashSet<>();
    Set<SimpleChunkLocation> sclocs = Area.getAllChunkLocations(area);
    for (SimpleChunkLocation scloc : sclocs) {
        Map<Area, AreaTrigger> map = areaTriggers.get(scloc);
        if (map == null)
            continue;
        for (Entry<Area, AreaTrigger> mapentry : map.entrySet()) {
            Area areaOther = mapentry.getKey();
            if (area.equals(areaOther))
                continue;
            if (Area.isConflicting(area, areaOther)) {
                conflicts.add(areaOther);
            }
        }
    }
    return conflicts;
}
Also used : Area(io.github.wysohn.triggerreactor.core.manager.location.Area) SimpleChunkLocation(io.github.wysohn.triggerreactor.core.manager.location.SimpleChunkLocation) HashSet(java.util.HashSet)

Example 8 with Area

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

the class AbstractAreaTriggerManager method deleteArea.

/**
 * Try to remove Area Trigger by given name
 * @param name
 * @return false if can't find any Area Trigger with the name; true if deleted.
 */
public boolean deleteArea(String name) {
    AreaTrigger trigger = nameMapper.get(name);
    if (trigger == null)
        return false;
    for (SimpleChunkLocation scloc : Area.getAllChunkLocations(trigger.area)) {
        Map<Area, AreaTrigger> map = areaTriggers.get(scloc);
        map.remove(trigger.area);
    }
    deleteInfo(trigger);
    nameMapper.remove(name);
    return true;
}
Also used : Area(io.github.wysohn.triggerreactor.core.manager.location.Area) SimpleChunkLocation(io.github.wysohn.triggerreactor.core.manager.location.SimpleChunkLocation)

Example 9 with Area

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

the class AbstractAreaTriggerManager method deleteArea.

/**
 * Try to remove Area Trigger at given location.
 * @param location
 * @return false if no area found at location; true if deleted
 */
public boolean deleteArea(SimpleLocation sloc) {
    Entry<Area, AreaTrigger> areaEntry = getAreaForLocation(sloc);
    if (areaEntry == null)
        return false;
    AreaTrigger trigger = areaEntry.getValue();
    for (SimpleChunkLocation scloc : Area.getAllChunkLocations(areaEntry.getKey())) {
        Map<Area, AreaTrigger> map = areaTriggers.get(scloc);
        map.remove(areaEntry.getKey());
    }
    deleteInfo(nameMapper.remove(trigger.getTriggerName()));
    return true;
}
Also used : Area(io.github.wysohn.triggerreactor.core.manager.location.Area) SimpleChunkLocation(io.github.wysohn.triggerreactor.core.manager.location.SimpleChunkLocation)

Aggregations

Area (io.github.wysohn.triggerreactor.core.manager.location.Area)9 SimpleChunkLocation (io.github.wysohn.triggerreactor.core.manager.location.SimpleChunkLocation)6 File (java.io.File)3 SimpleLocation (io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 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 AbstractScriptEditManager (io.github.wysohn.triggerreactor.core.manager.AbstractScriptEditManager)1 AbstractVariableManager (io.github.wysohn.triggerreactor.core.manager.AbstractVariableManager)1 Manager (io.github.wysohn.triggerreactor.core.manager.Manager)1 AbstractAreaTriggerManager (io.github.wysohn.triggerreactor.core.manager.trigger.AbstractAreaTriggerManager)1