use of io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation in project TriggerReactor by wysohn.
the class PlayerLocationManager method reload.
@Override
public void reload() {
for (Player player : BukkitUtil.getOnlinePlayers()) {
Location loc = player.getLocation();
SimpleLocation sloc = LocationUtil.convertToSimpleLocation(loc);
setCurrentBlockLocation(player.getUniqueId(), sloc);
}
}
use of io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation in project TriggerReactor by wysohn.
the class AbstractAreaSelectionManager method getSelection.
/**
* @param player
* @return null if invalid selection; Area if done
*/
public Area getSelection(UUID uuid) {
SimpleLocation left = leftPosition.get(uuid);
SimpleLocation right = rightPosition.get(uuid);
if (left != null && right != null) {
if (!left.getWorld().equals(right.getWorld())) {
return null;
}
SimpleLocation smallest = getSmallest(left, right);
SimpleLocation largest = getLargest(left, right);
return new Area(smallest, largest);
} else {
return null;
}
}
use of io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation in project TriggerReactor by wysohn.
the class AbstractLocationBasedTriggerManager method pasteTrigger.
/**
* @param player
* @param sloc
* @return true if pasted; false if nothing in the clipboard
*/
protected boolean pasteTrigger(IPlayer player, SimpleLocation sloc) {
ClipBoard board = clipboard.get(player.getUniqueId());
if (board == null)
return false;
SimpleLocation from = board.location;
if (from == null) {
return false;
}
T trigger = getTriggerForLocation(from);
if (trigger == null) {
return false;
}
try {
if (board.type == ClipBoard.BoardType.CUT)
trigger = removeTriggerForLocation(board.location);
T copy = (T) trigger.clone();
copy.setTriggerName(sloc.toString());
setTriggerForLocation(sloc, copy);
} catch (Exception e) {
e.printStackTrace();
// put it back if failed
if (board.type == ClipBoard.BoardType.CUT && trigger != null) {
setTriggerForLocation(board.location, (T) trigger.clone());
}
}
return true;
}
use of io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation in project TriggerReactor by wysohn.
the class AbstractLocationBasedTriggerManager method saveAll.
@Override
public void saveAll() {
for (Entry<SimpleChunkLocation, Map<SimpleLocation, T>> chunkEntry : locationTriggers.entrySet()) {
SimpleChunkLocation scloc = chunkEntry.getKey();
Map<SimpleLocation, T> slocMap = chunkEntry.getValue();
Set<SimpleLocation> failed = new HashSet<>();
for (Entry<SimpleLocation, T> entry : slocMap.entrySet()) {
SimpleLocation sloc = entry.getKey();
T trigger = entry.getValue();
String fileName = slocToString(sloc);
String script = trigger.getScript();
File file = new File(folder, fileName + ".trg");
try {
FileUtil.writeToFile(file, script);
} catch (Exception e) {
e.printStackTrace();
plugin.getLogger().severe("Could not save a trigger at " + sloc);
failed.add(sloc);
}
}
for (SimpleLocation sloc : failed) {
slocMap.remove(sloc);
}
}
}
use of io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation in project TriggerReactor by wysohn.
the class AbstractLocationBasedTriggerManager method removeTriggerForLocation.
protected T removeTriggerForLocation(SimpleLocation sloc) {
SimpleChunkLocation scloc = new SimpleChunkLocation(sloc);
Map<SimpleLocation, T> triggerMap = locationTriggers.get(scloc);
if (!locationTriggers.containsKey(scloc)) {
return null;
}
T result = triggerMap.remove(sloc);
deleteInfo(result);
plugin.saveAsynchronously(this);
return result;
}
Aggregations