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