Search in sources :

Example 1 with PlayerApplicable

use of pl.themolka.arcade.game.PlayerApplicable in project Arcade2 by ShootGame.

the class TeamApplyListeners method playerRespawn.

// This is a special listener where we manually set player's
// respawn location by looping all apply contents.
@Handler(priority = Priority.LOWEST)
public void playerRespawn(PlayerRespawnEvent event) {
    GamePlayer player = event.getGamePlayer();
    Team team = this.game.getTeam(player);
    if (this.shouldApplyTo(team)) {
        player.getPlayer().clearInventory(true);
        Location spawn = this.fetchSpawn(team, MatchApplyContext.EventType.PLAYER_RESPAWN, player);
        if (spawn != null) {
            event.setRespawnPosition(spawn);
        }
        // The player must be spawned to be able to be meta attachable.
        this.game.getServer().getScheduler().runTaskLater(this.game.getPlugin(), new Runnable() {

            @Override
            public void run() {
                if (!player.isOnline()) {
                    return;
                }
                for (PlayerApplicable content : team.getApplyContext().getAllContent(MatchApplyContext.EventType.PLAYER_RESPAWN)) {
                    if (!(content instanceof SpawnApply)) {
                        content.apply(player);
                    }
                }
            }
        }, Time.ZERO.toTicks());
    }
}
Also used : PlayerApplicable(pl.themolka.arcade.game.PlayerApplicable) GamePlayer(pl.themolka.arcade.game.GamePlayer) SpawnApply(pl.themolka.arcade.spawn.SpawnApply) Location(org.bukkit.Location) Handler(net.engio.mbassy.listener.Handler)

Aggregations

Handler (net.engio.mbassy.listener.Handler)1 Location (org.bukkit.Location)1 GamePlayer (pl.themolka.arcade.game.GamePlayer)1 PlayerApplicable (pl.themolka.arcade.game.PlayerApplicable)1 SpawnApply (pl.themolka.arcade.spawn.SpawnApply)1