Search in sources :

Example 1 with PlayerChangedWorldEvent

use of org.bukkit.event.player.PlayerChangedWorldEvent in project Glowstone by GlowstoneMC.

the class GlowPlayer method spawnAt.

/**
 * Spawn the player at the given location after they have already joined.
 *
 * <p>Used for changing worlds and respawning after death.
 *
 * @param location The location to place the player.
 */
private void spawnAt(Location location) {
    GlowWorld oldWorld;
    // switch worlds
    worldLock.writeLock().lock();
    try {
        oldWorld = world;
        world.getEntityManager().unregister(this);
        world = (GlowWorld) location.getWorld();
        world.getEntityManager().register(this);
        updateBossBars();
    } finally {
        worldLock.writeLock().unlock();
    }
    // switch chunk set
    // no need to send chunk unload messages - respawn unloads all chunks
    knownChunks.clear();
    chunkLock.clear();
    chunkLock = world.newChunkLock(getName());
    // spawn into world
    session.send(new RespawnMessage(world.getName(), world.getSeedHash(), getGameMode().getValue(), -1, false, world.getWorldType() == WorldType.FLAT, oldWorld.getEnvironment() != world.getEnvironment()));
    // take us to spawn position
    setRawLocation(location, false);
    session.send(new PositionRotationMessage(location));
    teleportedTo = location.clone();
    // set our compass target
    setCompassTarget(world.getSpawnLocation());
    // stream blocks
    streamBlocks();
    sendWeather();
    sendRainDensity();
    sendSkyDarkness();
    sendTime();
    updateInventory();
    // fire world change if needed
    if (oldWorld != world) {
        session.send(((GlowWorldBorder) world.getWorldBorder()).createMessage());
        EventFactory.getInstance().callEvent(new PlayerChangedWorldEvent(this, oldWorld));
    }
}
Also used : RespawnMessage(net.glowstone.net.message.play.game.RespawnMessage) PlayerChangedWorldEvent(org.bukkit.event.player.PlayerChangedWorldEvent) PositionRotationMessage(net.glowstone.net.message.play.game.PositionRotationMessage) GlowWorld(net.glowstone.GlowWorld)

Aggregations

GlowWorld (net.glowstone.GlowWorld)1 PositionRotationMessage (net.glowstone.net.message.play.game.PositionRotationMessage)1 RespawnMessage (net.glowstone.net.message.play.game.RespawnMessage)1 PlayerChangedWorldEvent (org.bukkit.event.player.PlayerChangedWorldEvent)1