Search in sources :

Example 1 with SpectatorMenu

use of com.gmail.stefvanschiedev.buildinggame.utils.guis.spectatormenu.SpectatorMenu in project buildinggame by stefvanschie.

the class Plot method addSpectator.

/**
 * Adds a spectator to the plot
 *
 * @param spectator the player that wants to spectate
 * @param spectates the player the spectator wants to spectate
 * @since 2.1.0
 */
@Contract("null, _ -> fail; _, null -> fail")
public void addSpectator(final Player spectator, GamePlayer spectates) {
    YamlConfiguration config = SettingsManager.getInstance().getConfig();
    final var gamePlayer = new GamePlayer(spectator, GamePlayerType.SPECTATOR);
    gamePlayer.setSpectates(spectates);
    getAllGamePlayers().add(gamePlayer);
    getAllGamePlayers().forEach(player -> player.getPlayer().hidePlayer(Main.getInstance(), spectator));
    Material material = SettingsManager.getInstance().getMaterial("leave-item.id", Material.BARRIER);
    spectator.getInventory().setItem(config.getInt("leave-item.slot"), new ItemBuilder(spectator, material).setDisplayName(MessageManager.translate(SettingsManager.getInstance().getMessages().getString("leave-item.name"), spectator)).setClickEvent(event -> {
        gamePlayer.connect(MainSpawnManager.getInstance().getServer(), MainSpawnManager.getInstance().getMainSpawn());
        removeSpectator(gamePlayer);
        MessageManager.getInstance().send(spectator, ChatColor.GREEN + "Stopped spectating");
        event.setCancelled(true);
    }).build());
    spectator.getInventory().setItem(8, new ItemBuilder(spectator, Material.EMERALD).setDisplayName(ChatColor.GREEN + "Spectator menu").setClickEvent(event -> {
        new SpectatorMenu().show(spectator);
        event.setCancelled(true);
    }).build());
    spectator.teleport(spectates.getPlayer().getLocation());
    spectator.setGameMode(GameMode.CREATIVE);
    spectator.setCanPickupItems(false);
}
Also used : GamePlayer(com.gmail.stefvanschiedev.buildinggame.utils.gameplayer.GamePlayer) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) SpectatorMenu(com.gmail.stefvanschiedev.buildinggame.utils.guis.spectatormenu.SpectatorMenu) Contract(org.jetbrains.annotations.Contract)

Aggregations

GamePlayer (com.gmail.stefvanschiedev.buildinggame.utils.gameplayer.GamePlayer)1 SpectatorMenu (com.gmail.stefvanschiedev.buildinggame.utils.guis.spectatormenu.SpectatorMenu)1 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)1 Contract (org.jetbrains.annotations.Contract)1