Search in sources :

Example 16 with SimpleLocation

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);
    }
}
Also used : Player(org.bukkit.entity.Player) SimpleLocation(io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation) SimpleLocation(io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation) Location(org.bukkit.Location)

Example 17 with SimpleLocation

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;
    }
}
Also used : Area(io.github.wysohn.triggerreactor.core.manager.location.Area) SimpleLocation(io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation)

Example 18 with SimpleLocation

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;
}
Also used : SimpleLocation(io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation) IOException(java.io.IOException)

Example 19 with SimpleLocation

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);
        }
    }
}
Also used : SimpleChunkLocation(io.github.wysohn.triggerreactor.core.manager.location.SimpleChunkLocation) SimpleLocation(io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map) File(java.io.File) IOException(java.io.IOException) HashSet(java.util.HashSet)

Example 20 with SimpleLocation

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;
}
Also used : SimpleChunkLocation(io.github.wysohn.triggerreactor.core.manager.location.SimpleChunkLocation) SimpleLocation(io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation)

Aggregations

SimpleLocation (io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation)20 Location (org.bukkit.Location)8 Player (org.bukkit.entity.Player)8 SimpleChunkLocation (io.github.wysohn.triggerreactor.core.manager.location.SimpleChunkLocation)7 EventHandler (org.bukkit.event.EventHandler)5 IOException (java.io.IOException)4 Trigger (io.github.wysohn.triggerreactor.core.manager.trigger.AbstractTriggerManager.Trigger)3 File (java.io.File)3 Area (io.github.wysohn.triggerreactor.core.manager.location.Area)2 HashMap (java.util.HashMap)2 BukkitPlayerBlockLocationEvent (io.github.wysohn.triggerreactor.bukkit.bridge.event.BukkitPlayerBlockLocationEvent)1 BukkitPlayer (io.github.wysohn.triggerreactor.bukkit.bridge.player.BukkitPlayer)1 PlayerBlockLocationEvent (io.github.wysohn.triggerreactor.bukkit.manager.event.PlayerBlockLocationEvent)1 DelegatedPlayer (io.github.wysohn.triggerreactor.bukkit.tools.DelegatedPlayer)1 IPlayer (io.github.wysohn.triggerreactor.core.bridge.player.IPlayer)1 InventoryTrigger (io.github.wysohn.triggerreactor.core.manager.trigger.AbstractInventoryTriggerManager.InventoryTrigger)1 FileFilter (java.io.FileFilter)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 UUID (java.util.UUID)1