Search in sources :

Example 1 with PlayerLogoutEvent

use of io.xol.chunkstories.api.events.player.PlayerLogoutEvent in project chunkstories by Hugobros3.

the class Ingame method destroy.

@Override
public void destroy() {
    // Logout sequence: Save the player entity
    if (world instanceof WorldMaster) {
        Player player = getPlayer();
        PlayerLogoutEvent playerDisconnectionEvent = new PlayerLogoutEvent(player);
        world.getPluginManager().fireEvent(playerDisconnectionEvent);
        if (this.playerEntity != null) {
            SerializedEntityFile playerEntityFile = new SerializedEntityFile(world.getFolderPath() + "/players/" + getPlayer().getName().toLowerCase() + ".csf");
            playerEntityFile.write(this.playerEntity);
        }
    }
    // Stop the game logic and save
    if (world instanceof WorldMaster) {
        // TODO: Stop simulation
        Fence fence = ((WorldMaster) world).stopLogic();
        // exitButton.text = "#{world.saving}";
        fence.traverse();
        fence = world.saveEverything();
        // exitButton.text = "#{world.saving}";
        fence.traverse();
    }
    // Disables plugins
    world.getPluginManager().disablePlugins();
    this.world.getWorldRenderer().destroy();
}
Also used : Player(io.xol.chunkstories.api.player.Player) LocalPlayer(io.xol.chunkstories.api.client.LocalPlayer) PlayerLogoutEvent(io.xol.chunkstories.api.events.player.PlayerLogoutEvent) SerializedEntityFile(io.xol.chunkstories.entity.SerializedEntityFile) Fence(io.xol.chunkstories.api.util.concurrency.Fence) WorldMaster(io.xol.chunkstories.api.world.WorldMaster)

Example 2 with PlayerLogoutEvent

use of io.xol.chunkstories.api.events.player.PlayerLogoutEvent in project chunkstories by Hugobros3.

the class ClientConnection method close.

@Override
public boolean close() {
    clientsManager.removeClient(this);
    if (player != null) {
        PlayerLogoutEvent playerDisconnectionEvent = new PlayerLogoutEvent(player);
        clientsManager.getServer().getPluginManager().fireEvent(playerDisconnectionEvent);
        clientsManager.getServer().broadcastMessage(playerDisconnectionEvent.getLogoutMessage());
        player.destroy();
    }
    return true;
}
Also used : PlayerLogoutEvent(io.xol.chunkstories.api.events.player.PlayerLogoutEvent)

Aggregations

PlayerLogoutEvent (io.xol.chunkstories.api.events.player.PlayerLogoutEvent)2 LocalPlayer (io.xol.chunkstories.api.client.LocalPlayer)1 Player (io.xol.chunkstories.api.player.Player)1 Fence (io.xol.chunkstories.api.util.concurrency.Fence)1 WorldMaster (io.xol.chunkstories.api.world.WorldMaster)1 SerializedEntityFile (io.xol.chunkstories.entity.SerializedEntityFile)1