Search in sources :

Example 1 with SpongeEntity

use of io.github.wysohn.triggerreactor.sponge.bridge.entity.SpongeEntity in project TriggerReactor by wysohn.

the class AreaTriggerManager method onJoin.

@Listener(order = Order.POST)
public void onJoin(ClientConnectionEvent.Join e) {
    SimpleLocation currentSloc = LocationUtil.convertToSimpleLocation(e.getTargetEntity().getLocation());
    getAreaForLocation(currentSloc).stream().map(Entry::getValue).forEach((trigger) -> trigger.addEntity(new SpongeEntity(e.getTargetEntity())));
}
Also used : 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 2 with SpongeEntity

use of io.github.wysohn.triggerreactor.sponge.bridge.entity.SpongeEntity 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 3 with SpongeEntity

use of io.github.wysohn.triggerreactor.sponge.bridge.entity.SpongeEntity in project TriggerReactor by wysohn.

the class AreaTriggerManager method onLocationChange.

@Listener(order = Order.POST)
public void onLocationChange(PlayerBlockLocationEvent e) {
    List<Entry<Area, AreaTrigger>> from = getAreaForLocation(e.getFrom());
    List<Entry<Area, AreaTrigger>> to = getAreaForLocation(e.getTo());
    Map<String, Object> varMap = new HashMap<>();
    varMap.put("player", e.getTargetEntity());
    varMap.put("from", e.getFrom());
    varMap.put("to", e.getTo());
    from.stream().filter(// only for area leaving
    (entry) -> !entry.getKey().isInThisArea(e.getTo())).map(Entry::getValue).forEach((trigger) -> {
        trigger.removeEntity(e.getTargetEntity().getUniqueId());
        trigger.activate(e, varMap, EventType.EXIT);
    });
    to.stream().filter(// only for entering area
    (entry) -> !entry.getKey().isInThisArea(e.getFrom())).map(Entry::getValue).forEach((trigger) -> {
        trigger.addEntity(new SpongeEntity(e.getTargetEntity()));
        trigger.activate(e, varMap, EventType.ENTER);
    });
}
Also used : Entry(java.util.Map.Entry) HashMap(java.util.HashMap) SpongeEntity(io.github.wysohn.triggerreactor.sponge.bridge.entity.SpongeEntity) Listener(org.spongepowered.api.event.Listener)

Example 4 with SpongeEntity

use of io.github.wysohn.triggerreactor.sponge.bridge.entity.SpongeEntity 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)

Aggregations

SpongeEntity (io.github.wysohn.triggerreactor.sponge.bridge.entity.SpongeEntity)4 SimpleLocation (io.github.wysohn.triggerreactor.core.manager.location.SimpleLocation)3 Listener (org.spongepowered.api.event.Listener)3 IEntity (io.github.wysohn.triggerreactor.core.bridge.entity.IEntity)2 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1 UUID (java.util.UUID)1 Entity (org.spongepowered.api.entity.Entity)1 World (org.spongepowered.api.world.World)1