Search in sources :

Example 1 with SpectateMinigameEvent

use of au.com.mineauz.minigames.events.SpectateMinigameEvent in project Minigames by AddstarMC.

the class PlayerData method spectateMinigame.

public void spectateMinigame(MinigamePlayer player, Minigame minigame) {
    SpectateMinigameEvent event = new SpectateMinigameEvent(player, minigame);
    Bukkit.getServer().getPluginManager().callEvent(event);
    if (!event.isCancelled()) {
        boolean tpd = false;
        if (minigame.getSpectatorLocation() != null)
            tpd = player.teleport(minigame.getSpectatorLocation());
        else {
            player.sendMessage(MinigameUtils.getLang("minigame.error.noSpectatePos"), "error");
            return;
        }
        if (!tpd) {
            player.sendMessage(MinigameUtils.getLang("minigame.error.noTeleport"), "error");
            return;
        }
        player.storePlayerData();
        player.setMinigame(minigame);
        player.setGamemode(GameMode.ADVENTURE);
        minigame.addSpectator(player);
        if (minigame.canSpectateFly()) {
            player.getPlayer().setAllowFlight(true);
        }
        for (MinigamePlayer pl : minigame.getPlayers()) {
            pl.getPlayer().hidePlayer(player.getPlayer());
        }
        player.getPlayer().setScoreboard(minigame.getScoreboardManager());
        for (PotionEffect potion : player.getPlayer().getActivePotionEffects()) {
            player.getPlayer().removePotionEffect(potion.getType());
        }
        player.sendMessage(MinigameUtils.formStr("player.spectate.join.plyMsg", minigame.getName(true)) + "\n" + MinigameUtils.formStr("player.spectate.join.plyHelp", "\"/minigame quit\""), null);
        mdata.sendMinigameMessage(minigame, MinigameUtils.formStr("player.spectate.join.minigameMsg", player.getName(), minigame.getName(true)), null, player);
    }
}
Also used : SpectateMinigameEvent(au.com.mineauz.minigames.events.SpectateMinigameEvent) PotionEffect(org.bukkit.potion.PotionEffect)

Aggregations

SpectateMinigameEvent (au.com.mineauz.minigames.events.SpectateMinigameEvent)1 PotionEffect (org.bukkit.potion.PotionEffect)1