mirror of
https://github.com/SunNetservers/MiniGames.git
synced 2025-07-17 13:34:43 +02:00
Adds a partially usable arena menu openable through a command
This commit is contained in:
96
src/main/java/net/knarcraft/minigames/gui/ArenaGUI.java
Normal file
96
src/main/java/net/knarcraft/minigames/gui/ArenaGUI.java
Normal file
@ -0,0 +1,96 @@
|
||||
package net.knarcraft.minigames.gui;
|
||||
|
||||
import net.knarcraft.knargui.AbstractGUI;
|
||||
import net.knarcraft.knargui.GUIAction;
|
||||
import net.knarcraft.knargui.item.GUIItemFactory;
|
||||
import net.knarcraft.minigames.MiniGames;
|
||||
import net.knarcraft.minigames.arena.ArenaSession;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A generic GUI for all arenas
|
||||
*/
|
||||
public abstract class ArenaGUI extends AbstractGUI {
|
||||
|
||||
/**
|
||||
* Instantiates a new arena gui
|
||||
*
|
||||
* @param inventorySize <p>The size of the GUI's inventory</p>
|
||||
* @param inventoryName <p>The name of the inventory</p>
|
||||
*/
|
||||
public ArenaGUI(int inventorySize, String inventoryName) {
|
||||
super(inventorySize, inventoryName, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an item describing player visibility toggling
|
||||
*
|
||||
* @return <p>A player toggle item</p>
|
||||
*/
|
||||
protected ItemStack getTogglePlayersItem() {
|
||||
GUIItemFactory togglePlayersItemFactory = new GUIItemFactory(Material.PLAYER_HEAD);
|
||||
List<String> loreLines = getLoreLines();
|
||||
loreLines.add(ChatColor.GRAY + "Use this item to toggle the visibility");
|
||||
loreLines.add(ChatColor.GRAY + "of other players");
|
||||
togglePlayersItemFactory.setName(ChatColor.BLUE + "Toggle Players");
|
||||
togglePlayersItemFactory.setLore(loreLines);
|
||||
return togglePlayersItemFactory.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an item describing a leave arena action
|
||||
*
|
||||
* @return <p>A leave item</p>
|
||||
*/
|
||||
protected ItemStack getLeaveItem() {
|
||||
GUIItemFactory leaveItemFactory = new GUIItemFactory(Material.BARRIER);
|
||||
List<String> loreLines = getLoreLines();
|
||||
loreLines.add(ChatColor.GRAY + "Use this item to leave the arena");
|
||||
leaveItemFactory.setName(ChatColor.DARK_RED + "Leave");
|
||||
leaveItemFactory.setLore(loreLines);
|
||||
return leaveItemFactory.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an arraylist with one blank line lore-lines can be added to
|
||||
*
|
||||
* @return <p>An arraylist with one blank line</p>
|
||||
*/
|
||||
protected List<String> getLoreLines() {
|
||||
List<String> loreLines = new ArrayList<>();
|
||||
loreLines.add("");
|
||||
return loreLines;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a click action for both right-click and left-click
|
||||
*
|
||||
* @param inventorySlot <p>The inventory slot the action should be added to</p>
|
||||
* @param action <p>The action to register</p>
|
||||
*/
|
||||
protected void setAnyClickAction(int inventorySlot, GUIAction action) {
|
||||
setClickAction(inventorySlot, ClickType.LEFT, action);
|
||||
setClickAction(inventorySlot, ClickType.RIGHT, action);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the action to run when triggering the leave item
|
||||
*
|
||||
* @return <p>The leave action</p>
|
||||
*/
|
||||
protected GUIAction getLeaveAction() {
|
||||
return (player) -> {
|
||||
ArenaSession session = MiniGames.getInstance().getSession(player.getUniqueId());
|
||||
if (session != null) {
|
||||
session.triggerQuit(false);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
19
src/main/java/net/knarcraft/minigames/gui/DropperGUI.java
Normal file
19
src/main/java/net/knarcraft/minigames/gui/DropperGUI.java
Normal file
@ -0,0 +1,19 @@
|
||||
package net.knarcraft.minigames.gui;
|
||||
|
||||
/**
|
||||
* A GUI used in the dropper arena
|
||||
*/
|
||||
public class DropperGUI extends ArenaGUI {
|
||||
|
||||
/**
|
||||
* Instantiates a new dropper gui
|
||||
*/
|
||||
public DropperGUI() {
|
||||
super(9, "Dropper");
|
||||
setItem(0, getTogglePlayersItem());
|
||||
setItem(2, getLeaveItem());
|
||||
|
||||
setAnyClickAction(2, getLeaveAction());
|
||||
}
|
||||
|
||||
}
|
58
src/main/java/net/knarcraft/minigames/gui/ParkourGUI.java
Normal file
58
src/main/java/net/knarcraft/minigames/gui/ParkourGUI.java
Normal file
@ -0,0 +1,58 @@
|
||||
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.inventory.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A GUI used in the parkour arena
|
||||
*/
|
||||
public class ParkourGUI extends ArenaGUI {
|
||||
|
||||
public ParkourGUI() {
|
||||
super(9, "Parkour");
|
||||
setItem(0, getTogglePlayersItem());
|
||||
setItem(2, getGiveUpItem());
|
||||
setItem(4, getLeaveItem());
|
||||
|
||||
setAnyClickAction(2, getGiveUpAction());
|
||||
setAnyClickAction(4, getLeaveAction());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an item describing a give up action
|
||||
*
|
||||
* @return <p>A give up item</p>
|
||||
*/
|
||||
private ItemStack getGiveUpItem() {
|
||||
GUIItemFactory giveUpItemFactory = new GUIItemFactory(Material.SKELETON_SKULL);
|
||||
List<String> 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 <p>The give up action</p>
|
||||
*/
|
||||
private GUIAction getGiveUpAction() {
|
||||
return (player) -> {
|
||||
ArenaSession session = MiniGames.getInstance().getSession(player.getUniqueId());
|
||||
if (session instanceof ParkourArenaSession) {
|
||||
session.triggerLoss();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user