import org.spout.vanilla.protocol.msg.player.pos.PlayerSpawnPositionMessage;
public class PlayerStatusHandler extends MessageHandler<PlayerStatusMessage> {
@Override
public void handleServer(ServerSession session, PlayerStatusMessage message) {
final Server server = session.getEngine();
if (message.getStatus() == PlayerStatusMessage.INITIAL_SPAWN) {
server.getEventManager().callEvent(new PlayerConnectEvent(session, (String) session.getDataMap().get("username"), 10));
if (server.debugMode()) {
server.getLogger().info("Login took " + (System.currentTimeMillis() - session.getDataMap().get(VanillaProtocol.LOGIN_TIME)) + " ms");
}
final ManagedMap data = session.getPlayer().getWorld().getData();
final Human human = session.getPlayer().add(Human.class);
final Difficulty difficulty = data.get(VanillaData.DIFFICULTY);
final Dimension dimension = data.get(VanillaData.DIMENSION);
final WorldType worldType = data.get(VanillaData.WORLD_TYPE);
GameMode gamemode;
int entityId = session.getPlayer().getId();
// MC Packet Order: 0x01 Login, 0xFA Custom (ServerTypeName), 0x06 SpawnPos, 0xCA PlayerAbilities, 0x10 BlockSwitch
gamemode = data.get(VanillaData.GAMEMODE);
final PlayerLoginRequestMessage idMsg = new PlayerLoginRequestMessage(entityId, worldType.toString(), gamemode.getId(), (byte) dimension.getId(), difficulty.getId(), (byte) server.getMaxPlayers());
session.send(Session.SendType.FORCE, idMsg);
session.setState(Session.State.GAME);
if (human.getAttachedCount() <= 1) {
// If we haven't logged in before, we want to set all abilities to the default gamemode
human.setGamemode(gamemode, false);
}
} else if (message.getStatus() == PlayerStatusMessage.RESPAWN) {
Player player = session.getPlayer();
Point point = player.getWorld().getSpawnPoint().getPosition();
if (PlayerRespawnEvent.getHandlerList().getRegisteredListeners().length > 0) {
PlayerRespawnEvent event = server.getEventManager().callEvent(new PlayerRespawnEvent(player, point));
if (event.isCancelled()) {
return;
}
point = event.getPoint();