crwdns122453:0crwdne122453:0

crwdns122455:0:javadoc:crwdnd122455:0:javadoc:crwdnd122455:0:javadoc:crwdnd122455:0:javadoc:crwdne122455:0

crwdns122457:0crwdne122457:0

import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.entity.EntityTypes;
import org.spongepowered.api.event.CauseStackManager.StackFrame;
import org.spongepowered.api.event.cause.entity.spawn.SpawnTypes;
import org.spongepowered.api.world.Location;
import org.spongepowered.api.world.World;

import java.util.Optional;

public void spawnEntity(Location<World> spawnLocation) {
    World world = spawnLocation.getExtent();

    Entity creeper = world.createEntity(EntityTypes.CREEPER, spawnLocation.getPosition());

    // We need to push a new cause StackFrame to the stack so we can add our own causes
    // In previous versions of the API you had to submit a Cause parameter
    // that would often not contain the real root cause
    // By default the current plugin's PluginContainer is already pushed to the stack.
    try (StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
        frame.addContext(EventContextKeys.SPAWN_TYPE, SpawnTypes.PLUGIN);
        world.spawnEntity(creeper);
    }
}

crwdns122459:0:javadoc:crwdne122459:0

crwdns122461:0:javadoc:crwdnd122461:0:javadoc:crwdnd122461:0:javadoc:crwdne122461:0