use of org.lanternpowered.server.world.LanternWorld in project LanternServer by LanternPowered.
the class NetworkSession method leavePlayer.
/**
* Is called when the {@link LanternPlayer} leaves the
* server and needs to be cleaned up.
*/
private void leavePlayer() {
checkState(this.player != null, "The player must first be available!");
final LanternWorld world = this.player.getWorld();
if (world != null) {
final CauseStack causeStack = CauseStack.current();
causeStack.pushCause(this.player);
// Close the open container
this.player.getContainerSession().setRawOpenContainer(causeStack, null);
final MessageChannel messageChannel = this.player.getMessageChannel();
final Text quitMessage = t("multiplayer.player.left", this.player.getName());
final ClientConnectionEvent.Disconnect event = SpongeEventFactory.createClientConnectionEventDisconnect(causeStack.getCurrentCause(), messageChannel, Optional.of(messageChannel), new MessageEvent.MessageFormatter(quitMessage), this.player, false);
Sponge.getEventManager().post(event);
if (!event.isMessageCancelled()) {
event.getChannel().ifPresent(channel -> channel.send(this.player, event.getMessage()));
}
causeStack.popCause();
// Remove the proxy user from the player and save the player data
this.player.getProxyUser().setInternalUser(null);
// Destroy the player entity
this.player.remove(LanternEntity.RemoveState.DESTROYED);
// Detach the player from the world
this.player.setWorld(null);
// Release the players entity id
EntityProtocolManager.releaseEntityId(this.player.getNetworkId());
}
}
use of org.lanternpowered.server.world.LanternWorld in project LanternServer by LanternPowered.
the class LanternPlayer method setRotation.
@Override
public void setRotation(Vector3d rotation) {
super.setRotation(rotation);
final LanternWorld world = getWorld();
if (world != null) {
this.session.send(new MessagePlayOutPlayerPositionAndLook(0, 0, 0, (float) rotation.getX(), (float) rotation.getY(), RELATIVE_POSITION, 0));
}
}
use of org.lanternpowered.server.world.LanternWorld in project LanternServer by LanternPowered.
the class LanternPlayer method resetBlockChange.
@Override
public void resetBlockChange(Vector3i position) {
checkNotNull(position, "position");
LanternWorld world = this.getWorld();
if (world == null) {
return;
}
this.session.send(new MessagePlayOutBlockChange(position, BlockRegistryModule.get().getStateInternalIdAndData(world.getBlock(position))));
}
use of org.lanternpowered.server.world.LanternWorld in project LanternServer by LanternPowered.
the class LanternPlayer method setPosition.
@Override
public void setPosition(Vector3d position) {
super.setPosition(position);
final LanternWorld world = getWorld();
if (world != null) {
this.session.send(new MessagePlayOutPlayerPositionAndLook(position.getX(), position.getY(), position.getZ(), 0, 0, RELATIVE_ROTATION, 0));
}
}
use of org.lanternpowered.server.world.LanternWorld in project LanternServer by LanternPowered.
the class UserStore method deserialize.
@Override
public void deserialize(T player, DataView dataView) {
super.deserialize(player, dataView);
final int dimension = dataView.getInt(DIMENSION).orElse(0);
Lantern.getWorldManager().getWorldProperties(dimension).ifPresent(worldProperties -> {
final LanternWorldProperties worldProperties0 = (LanternWorldProperties) worldProperties;
final Optional<LanternWorld> optWorld = worldProperties0.getWorld();
if (optWorld.isPresent()) {
player.setRawWorld(optWorld.get());
} else {
player.setUserWorld(worldProperties0);
}
});
}
Aggregations