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