package net.knarcraft.minigames.gui; import net.knarcraft.knargui.GUIAction; import net.knarcraft.knargui.item.GUIItemFactory; import net.knarcraft.minigames.MiniGames; import net.knarcraft.minigames.arena.ArenaSession; import net.knarcraft.minigames.arena.parkour.ParkourArenaSession; import net.md_5.bungee.api.ChatColor; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import java.util.List; /** * A GUI used in the parkour arena */ public class ParkourGUI extends ArenaGUI { /** * Instantiates a new parkour gui * * @param player

The player the GUI is created for

*/ public ParkourGUI(Player player) { super(9, "Parkour"); if (MiniGames.getInstance().getPlayerVisibilityManager().isHidingPlayers(player)) { setItem(0, getTogglePlayersItemEnabled()); } else { setItem(0, getTogglePlayersItemDisabled()); } setItem(2, getGiveUpItem()); setItem(4, getLeaveItem()); setItem(6, getRestartItem()); setAnyClickAction(0, getTogglePlayersAction(MiniGames.getInstance().getParkourArenaPlayerRegistry())); setAnyClickAction(2, getGiveUpAction()); setAnyClickAction(4, getLeaveAction()); setAnyClickAction(6, getRestartAction()); } /** * Gets an item describing a give up action * * @return

A give up item

*/ private ItemStack getGiveUpItem() { GUIItemFactory giveUpItemFactory = new GUIItemFactory(Material.RESPAWN_ANCHOR); List loreLines = getLoreLines(); loreLines.add(ChatColor.GRAY + "Use this item to give up"); loreLines.add(ChatColor.GRAY + "and go to the last checkpoint"); giveUpItemFactory.setName(ChatColor.RED + "Give up"); giveUpItemFactory.setLore(loreLines); return giveUpItemFactory.build(); } /** * Gets the action to run when triggering the give up item * * @return

The give up action

*/ public static GUIAction getGiveUpAction() { return (player) -> { ArenaSession session = MiniGames.getInstance().getSession(player.getUniqueId()); if (session instanceof ParkourArenaSession) { session.triggerLoss(); } }; } }