Search in sources :

Example 1 with BukkitEntity

use of io.github.wysohn.triggerreactor.bukkit.bridge.entity.BukkitEntity in project TriggerReactor by wysohn.

the class AreaTriggerManager method onJoin.

@EventHandler(priority = EventPriority.MONITOR)
public void onJoin(PlayerJoinEvent e) {
    SimpleLocation currentSloc = LocationUtil.convertToSimpleLocation(e.getPlayer().getLocation());
    getAreaForLocation(currentSloc).stream().map(Map.Entry::getValue).forEach((trigger) -> trigger.addEntity(new BukkitEntity(e.getPlayer())));
}
Also used : BukkitEntity(io.github.wysohn.triggerreactor.bukkit.bridge.entity.BukkitEntity) SimpleLocation(io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation) EventHandler(org.bukkit.event.EventHandler)

Example 2 with BukkitEntity

use of io.github.wysohn.triggerreactor.bukkit.bridge.entity.BukkitEntity in project TriggerReactor by wysohn.

the class AreaTriggerManager method reload.

@Override
public void reload() {
    super.reload();
    // re-register entities
    for (World w : Bukkit.getWorlds()) {
        for (Entity e : w.getEntities()) {
            UUID uuid = e.getUniqueId();
            if (e.isDead() || !e.isValid())
                continue;
            SimpleLocation previous = null;
            SimpleLocation current = LocationUtil.convertToSimpleLocation(e.getLocation());
            entityLocationMap.put(uuid, current);
            entityTrackMap.put(uuid, new WeakReference<IEntity>(new BukkitEntity(e)));
            onEntityBlockMoveAsync(e, previous, current);
        }
    }
}
Also used : BukkitEntity(io.github.wysohn.triggerreactor.bukkit.bridge.entity.BukkitEntity) IEntity(io.github.wysohn.triggerreactor.core.bridge.entity.IEntity) Entity(org.bukkit.entity.Entity) BukkitEntity(io.github.wysohn.triggerreactor.bukkit.bridge.entity.BukkitEntity) IEntity(io.github.wysohn.triggerreactor.core.bridge.entity.IEntity) SimpleLocation(io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation) World(org.bukkit.World)

Example 3 with BukkitEntity

use of io.github.wysohn.triggerreactor.bukkit.bridge.entity.BukkitEntity in project TriggerReactor by wysohn.

the class AreaTriggerManager method onSpawn.

@EventHandler
public void onSpawn(EntitySpawnEvent e) {
    SimpleLocation sloc = LocationUtil.convertToSimpleLocation(e.getLocation());
    entityTrackMap.put(e.getEntity().getUniqueId(), new WeakReference<IEntity>(new BukkitEntity(e.getEntity())));
    entityLocationMap.put(e.getEntity().getUniqueId(), sloc);
    getAreaForLocation(sloc).stream().map(Map.Entry::getValue).forEach((trigger) -> trigger.addEntity(new BukkitEntity(e.getEntity())));
}
Also used : BukkitEntity(io.github.wysohn.triggerreactor.bukkit.bridge.entity.BukkitEntity) IEntity(io.github.wysohn.triggerreactor.core.bridge.entity.IEntity) SimpleLocation(io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation) EventHandler(org.bukkit.event.EventHandler)

Example 4 with BukkitEntity

use of io.github.wysohn.triggerreactor.bukkit.bridge.entity.BukkitEntity in project TriggerReactor by wysohn.

the class AreaTriggerManager method onLocationChange.

@EventHandler(priority = EventPriority.MONITOR)
public void onLocationChange(PlayerBlockLocationEvent e) {
    List<Map.Entry<Area, AreaTrigger>> from = getAreaForLocation(e.getFrom());
    List<Map.Entry<Area, AreaTrigger>> to = getAreaForLocation(e.getTo());
    Map<String, Object> varMap = new HashMap<>();
    varMap.put("player", e.getPlayer());
    varMap.put("from", e.getFrom());
    varMap.put("to", e.getTo());
    from.stream().filter(// only for area leaving
    (entry) -> !entry.getKey().isInThisArea(e.getTo())).map(Map.Entry::getValue).forEach((trigger) -> {
        trigger.removeEntity(e.getPlayer().getUniqueId());
        trigger.activate(e, varMap, EventType.EXIT);
    });
    to.stream().filter(// only for entering area
    (entry) -> !entry.getKey().isInThisArea(e.getFrom())).map(Map.Entry::getValue).forEach((trigger) -> {
        trigger.addEntity(new BukkitEntity(e.getPlayer()));
        trigger.activate(e, varMap, EventType.ENTER);
    });
}
Also used : BukkitEntity(io.github.wysohn.triggerreactor.bukkit.bridge.entity.BukkitEntity) EventHandler(org.bukkit.event.EventHandler)

Aggregations

BukkitEntity (io.github.wysohn.triggerreactor.bukkit.bridge.entity.BukkitEntity)4 SimpleLocation (io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation)3 EventHandler (org.bukkit.event.EventHandler)3 IEntity (io.github.wysohn.triggerreactor.core.bridge.entity.IEntity)2 World (org.bukkit.World)1 Entity (org.bukkit.entity.Entity)1