Spawning an entity with a cause

So I’m trying to spawn an entity, and that’s all fine and dandy (except for the fact that not all my precious Keys work yet, but that’s another problem)… The entity spawns perfectly too. The problem I have, is I also need to prevent entity spawning, but not the ones I spawn, so I pass a Cause to the entity when I spawn it:

    public boolean spawn() {
                Optional<Entity> entityOptional = this.location.getExtent().createEntity(EntityTypes.ARMOR_STAND, this.location.getPosition());
                if(entityOptional.isPresent()) {
                    this.kill();
                    this.entity = (ArmorStand) entityOptional.get();
                    this.entity.getOrCreate(DisplayNameData.class).get().set(Keys.DISPLAY_NAME, this.name).set(Keys.SHOWS_DISPLAY_NAME, true);
                    this.entity.getOrCreate(InvisibilityData.class).get().set(Keys.INVISIBLE, true);
                    this.entity.setGravity(false);
                    this.entity.setSmall(true);
                    StarMain.getOperatingInstance().getGame().getEventManager().registerListeners(StarMain.getOperatingInstance(), new Hologram.Listener(this));
                    this.location.getExtent().spawnEntity(entity, Cause.of(this));
                    return true;
                } else {
                    return false;
                }
            }

As you can see, I use the Cause of ‘this,’ or the class that is wrapping the entity. And then my listener checks:

    @Listener
    public void onSpawn(SpawnEntityEvent ev) {
        if(!ev.getCause().any(Hologram.class) && !ev.getCause().any(UnmovingNonPlayableCharacter.class) && this.lobby.is(ev.getTargetEntity().getWorld())){
            StarMain.getOperatingInstance().getLogger().info("We should prevent spawning of a '".concat(ev.getTargetEntity().getClass().getName()).concat("' here"));
        }
    }

The spawn method is in the Hologram class, and as such ‘this’ refers to the Hologram class, however, this listener prints out that we should prevent spawning of the armor stands created by my hologram, and I don’t know why. Any help is much appreciated.

Add StarMain.getOperatingInstance().getLogger().info(ev.toString()); to the listener and post the output from spawning the entity. (At least, I think that works, based on your code.)

I did that and it’s saying the cause is a BlockSnapshot -_-

Could you post the full output? Also post the output of Thread.dumpStack(); - it might help.

Note: I changed the cause to my plugin (the instance of StarMain)

Listener code:

    @Listener
public void onSpawn(SpawnEntityEvent ev) {
    if(this.lobby.is(ev.getTargetEntity().getLocation().getExtent()) && !ev.getCause().any(StarMain.class)) {
        StarMain.getOperatingInstance().getLogger().info("------------------------------------------------------------------------------------------------------");
        StarMain.getOperatingInstance().getLogger().info("We should prevent spawning of a '".concat(ev.getTargetEntity().getClass().getName()).concat("' here"));
        StarMain.getOperatingInstance().getLogger().info(ev.toString());
        Thread.dumpStack();
        StarMain.getOperatingInstance().getLogger().info("------------------------------------------------------------------------------------------------------");
    }
}

Result: http://pastebin.com/uRmEijJ5

EDIT:
Strange… the cause has changed, it now says its my fault (as a player), and its the other entities fault… yet I wasn’t even logged in… humdehum

It’s a bug in SpongeCommon, the cause argument is ignored
https://github.com/SpongePowered/SpongeCommon/blob/master/src/main/java/org/spongepowered/common/mixin/core/world/MixinWorld.java#L442-L452

But why… Any ETA for a fix

The upcoming merge of @blood 's item drops branch addresses this and more.

Thank you! I look forward to it…