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());
}
}
}
}
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;
}
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;
}
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;
}
Aggregations