Search in sources :

Example 6 with IEntity

use of io.github.wysohn.triggerreactor.core.bridge.entity.IEntity 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 7 with IEntity

use of io.github.wysohn.triggerreactor.core.bridge.entity.IEntity 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 8 with IEntity

use of io.github.wysohn.triggerreactor.core.bridge.entity.IEntity in project TriggerReactor by wysohn.

the class AreaTrigger method getEntities.

public List<IEntity> getEntities() {
    List<IEntity> entities = new ArrayList<>();
    Set<UUID> remove = new HashSet<>();
    for (Map.Entry<UUID, WeakReference<IEntity>> entry : this.trackedEntities.entrySet()) {
        WeakReference<IEntity> ref = entry.getValue();
        IEntity entity = ref.get();
        if (entity != null) {
            entities.add(entity);
        } else {
            remove.remove(entry.getKey());
        }
    }
    for (UUID uuid : remove) {
        this.trackedEntities.remove(uuid);
    }
    return entities;
}
Also used : IEntity(io.github.wysohn.triggerreactor.core.bridge.entity.IEntity) WeakReference(java.lang.ref.WeakReference) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

IEntity (io.github.wysohn.triggerreactor.core.bridge.entity.IEntity)8 SimpleLocation (io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation)4 BukkitEntity (io.github.wysohn.triggerreactor.bukkit.bridge.entity.BukkitEntity)2 AbstractAreaTriggerManager (io.github.wysohn.triggerreactor.core.manager.trigger.area.AbstractAreaTriggerManager)2 AreaTrigger (io.github.wysohn.triggerreactor.core.manager.trigger.area.AreaTrigger)2 SpongeEntity (io.github.wysohn.triggerreactor.sponge.bridge.entity.SpongeEntity)2 Entity (org.bukkit.entity.Entity)2 Entity (org.spongepowered.api.entity.Entity)2 WeakReference (java.lang.ref.WeakReference)1 UUID (java.util.UUID)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 World (org.bukkit.World)1 EventHandler (org.bukkit.event.EventHandler)1 Listener (org.spongepowered.api.event.Listener)1 World (org.spongepowered.api.world.World)1