Search in sources :

Example 1 with IEntity

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

the class AreaTrigger method getEntity.

public IEntity getEntity(UUID uuid) {
    WeakReference<IEntity> ref = this.trackedEntities.get(uuid);
    if (ref == null)
        return null;
    IEntity entity = ref.get();
    // just remove it as it's got garbage-collected.
    if (entity == null) {
        this.trackedEntities.remove(uuid);
    }
    return entity;
}
Also used : IEntity(io.github.wysohn.triggerreactor.core.bridge.entity.IEntity)

Example 2 with IEntity

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

the class CommonFunctions method getEntitiesInArea.

/**
 * Get list of entities tracked by this AreaTrigger.
 *
 * @param areaTriggerName name of AreaTrigger to get entities from
 * @return List of entities. null if the AreaTrigger with specified name
 * doesn't exist.
 */
public List<Entity> getEntitiesInArea(String areaTriggerName) {
    AbstractAreaTriggerManager areaManager = plugin.getAreaManager();
    AreaTrigger trigger = areaManager.get(areaTriggerName);
    if (trigger == null)
        return null;
    List<Entity> entities = new ArrayList<>();
    for (IEntity ie : trigger.getEntities()) entities.add(ie.get());
    return entities;
}
Also used : IEntity(io.github.wysohn.triggerreactor.core.bridge.entity.IEntity) Entity(org.spongepowered.api.entity.Entity) AbstractAreaTriggerManager(io.github.wysohn.triggerreactor.core.manager.trigger.area.AbstractAreaTriggerManager) IEntity(io.github.wysohn.triggerreactor.core.bridge.entity.IEntity) AreaTrigger(io.github.wysohn.triggerreactor.core.manager.trigger.area.AreaTrigger)

Example 3 with IEntity

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

the class AreaTriggerManager method onSpawn.

@Listener
public void onSpawn(RespawnPlayerEvent e) {
    SimpleLocation sloc = LocationUtil.convertToSimpleLocation(e.getTargetEntity().getLocation());
    entityTrackMap.put(e.getTargetEntity().getUniqueId(), new WeakReference<IEntity>(new SpongeEntity(e.getTargetEntity())));
    entityLocationMap.put(e.getTargetEntity().getUniqueId(), sloc);
    getAreaForLocation(sloc).stream().map(Entry::getValue).forEach((trigger) -> trigger.addEntity(new SpongeEntity(e.getTargetEntity())));
}
Also used : IEntity(io.github.wysohn.triggerreactor.core.bridge.entity.IEntity) SimpleLocation(io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation) SpongeEntity(io.github.wysohn.triggerreactor.sponge.bridge.entity.SpongeEntity) Listener(org.spongepowered.api.event.Listener)

Example 4 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 : Sponge.getServer().getWorlds()) {
        for (Entity e : w.getEntities()) {
            UUID uuid = e.getUniqueId();
            if (e.isRemoved() || !e.isLoaded())
                continue;
            SimpleLocation previous = null;
            SimpleLocation current = LocationUtil.convertToSimpleLocation(e.getLocation());
            entityLocationMap.put(uuid, current);
            entityTrackMap.put(uuid, new WeakReference<IEntity>(new SpongeEntity(e)));
            onEntityBlockMoveAsync(e, previous, current);
        }
    }
}
Also used : IEntity(io.github.wysohn.triggerreactor.core.bridge.entity.IEntity) SpongeEntity(io.github.wysohn.triggerreactor.sponge.bridge.entity.SpongeEntity) Entity(org.spongepowered.api.entity.Entity) IEntity(io.github.wysohn.triggerreactor.core.bridge.entity.IEntity) SimpleLocation(io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation) SpongeEntity(io.github.wysohn.triggerreactor.sponge.bridge.entity.SpongeEntity) World(org.spongepowered.api.world.World) UUID(java.util.UUID)

Example 5 with IEntity

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

the class AbstractCommonFunctions method getEntitiesInArea.

/**
 * Get list of entities tracked by this AreaTrigger.
 *
 * @param areaTriggerName name of AreaTrigger to get entities from
 * @return List of entities. null if the AreaTrigger with specified name doesn't exist.
 */
public List<Entity> getEntitiesInArea(String areaTriggerName) {
    AbstractAreaTriggerManager areaManager = plugin.getAreaManager();
    AreaTrigger trigger = areaManager.get(areaTriggerName);
    if (trigger == null)
        return null;
    List<Entity> entities = new ArrayList<>();
    for (IEntity ie : trigger.getEntities()) entities.add(ie.get());
    return entities;
}
Also used : Entity(org.bukkit.entity.Entity) IEntity(io.github.wysohn.triggerreactor.core.bridge.entity.IEntity) AbstractAreaTriggerManager(io.github.wysohn.triggerreactor.core.manager.trigger.area.AbstractAreaTriggerManager) IEntity(io.github.wysohn.triggerreactor.core.bridge.entity.IEntity) AreaTrigger(io.github.wysohn.triggerreactor.core.manager.trigger.area.AreaTrigger)

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