Improves some GUI items, and removes some redundancy

This commit is contained in:
Kristian Knarvik 2024-04-05 17:28:40 +02:00
parent aa39243232
commit a632de5b1f
7 changed files with 90 additions and 58 deletions

View File

@ -4,15 +4,19 @@ import net.knarcraft.knargui.AbstractGUI;
import net.knarcraft.knargui.GUIAction; import net.knarcraft.knargui.GUIAction;
import net.knarcraft.knargui.item.GUIItemFactory; import net.knarcraft.knargui.item.GUIItemFactory;
import net.knarcraft.knargui.item.PlayerHeadGUIItemFactory; import net.knarcraft.knargui.item.PlayerHeadGUIItemFactory;
import net.knarcraft.knargui.item.SimpleGUIItemFactory;
import net.knarcraft.minigames.MiniGames; import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.ArenaPlayerRegistry; import net.knarcraft.minigames.arena.ArenaPlayerRegistry;
import net.knarcraft.minigames.arena.ArenaSession; import net.knarcraft.minigames.arena.ArenaSession;
import net.knarcraft.minigames.arena.PlayerVisibilityManager; import net.knarcraft.minigames.arena.PlayerVisibilityManager;
import net.knarcraft.minigames.arena.parkour.ParkourArenaSession; import net.knarcraft.minigames.arena.parkour.ParkourArenaSession;
import net.knarcraft.minigames.util.GeyserHelper;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -33,32 +37,41 @@ public abstract class ArenaGUI extends AbstractGUI {
} }
/** /**
* Gets an item describing a retry arena action * Gets an item describing a retry arena action (for Java edition)
* *
* @return <p>An arena restart item</p> * @return <p>An arena restart item</p>
*/ */
protected ItemStack getRestartItem() { @NotNull
protected ItemStack getRestartItemJava() {
PlayerHeadGUIItemFactory restartItemFactory = new PlayerHeadGUIItemFactory(); PlayerHeadGUIItemFactory restartItemFactory = new PlayerHeadGUIItemFactory();
restartItemFactory.useSkin("e23b225ed0443c4eec7cf30a034490485904e6eb3d53ef2ab9e39c73bdf22c30"); restartItemFactory.useSkin("e23b225ed0443c4eec7cf30a034490485904e6eb3d53ef2ab9e39c73bdf22c30");
List<String> loreLines = getLoreLines(); return setRestartItemData(restartItemFactory);
loreLines.add(ChatColor.GRAY + "Use this item to retry the arena");
restartItemFactory.setName(ChatColor.BLUE + "Retry arena");
restartItemFactory.setLore(loreLines);
return restartItemFactory.build();
} }
/** /**
* Gets an item describing a retry arena action * Gets an item describing a retry arena action (for Bedrock edition)
* *
* @return <p>An arena restart item</p> * @return <p>An arena restart item</p>
*/ */
@NotNull
protected ItemStack getRestartItemBedrock() { protected ItemStack getRestartItemBedrock() {
GUIItemFactory restartItemFactory = new GUIItemFactory(Material.MAGENTA_GLAZED_TERRACOTTA); return setRestartItemData(new SimpleGUIItemFactory(Material.MAGENTA_GLAZED_TERRACOTTA));
}
/**
* Sets the lore and name for a retry item, and returns the finished item
*
* @param guiItemFactory <p>The factory to apply the data to</p>
* @return <p>The finished item, with the data applied</p>
*/
@NotNull
protected ItemStack setRestartItemData(@NotNull GUIItemFactory guiItemFactory) {
List<String> loreLines = getLoreLines(); List<String> loreLines = getLoreLines();
loreLines.add(ChatColor.GRAY + "Use this item to retry the arena"); loreLines.add(ChatColor.GRAY + "Use this item to retry the arena");
restartItemFactory.setName(ChatColor.BLUE + "Retry arena"); loreLines.add(ChatColor.GRAY + "(deaths and time is reset to 0)");
restartItemFactory.setLore(loreLines); guiItemFactory.setName(ChatColor.BLUE + "Retry arena");
return restartItemFactory.build(); guiItemFactory.setLore(loreLines);
return guiItemFactory.build();
} }
/** /**
@ -67,7 +80,7 @@ public abstract class ArenaGUI extends AbstractGUI {
* @return <p>A player toggle item</p> * @return <p>A player toggle item</p>
*/ */
protected ItemStack getTogglePlayersItemDisabled() { protected ItemStack getTogglePlayersItemDisabled() {
GUIItemFactory togglePlayersItemFactory = new GUIItemFactory(Material.PLAYER_HEAD); GUIItemFactory togglePlayersItemFactory = new SimpleGUIItemFactory(Material.PLAYER_HEAD);
List<String> loreLines = getLoreLines(); List<String> loreLines = getLoreLines();
loreLines.add(ChatColor.GRAY + "Use this item to disable the visibility"); loreLines.add(ChatColor.GRAY + "Use this item to disable the visibility");
loreLines.add(ChatColor.GRAY + "of other players"); loreLines.add(ChatColor.GRAY + "of other players");
@ -79,17 +92,26 @@ public abstract class ArenaGUI extends AbstractGUI {
/** /**
* Gets an item describing player visibility toggling * Gets an item describing player visibility toggling
* *
* @param player <p>The player to get the item for</p>
* @return <p>A player toggle item</p> * @return <p>A player toggle item</p>
*/ */
protected ItemStack getTogglePlayersItemEnabled() { protected ItemStack getTogglePlayersItemEnabled(Player player) {
if (GeyserHelper.isGeyserPlayer(player)) {
return getTogglePlayersItemEnabledBedrock();
} else {
return getTogglePlayersItemEnabledJava();
}
}
/**
* Gets an item describing player visibility toggling
*
* @return <p>A player toggle item</p>
*/
protected ItemStack getTogglePlayersItemEnabledJava() {
PlayerHeadGUIItemFactory togglePlayersItemFactory = new PlayerHeadGUIItemFactory(); PlayerHeadGUIItemFactory togglePlayersItemFactory = new PlayerHeadGUIItemFactory();
togglePlayersItemFactory.useSkin("c10591e6909e6a281b371836e462d67a2c78fa0952e910f32b41a26c48c1757c"); togglePlayersItemFactory.useSkin("c10591e6909e6a281b371836e462d67a2c78fa0952e910f32b41a26c48c1757c");
List<String> loreLines = getLoreLines(); return setTogglePlayersItemData(togglePlayersItemFactory);
loreLines.add(ChatColor.GRAY + "Use this item to enable the visibility");
loreLines.add(ChatColor.GRAY + "of other players");
togglePlayersItemFactory.setName(ChatColor.BLUE + "Enable Players");
togglePlayersItemFactory.setLore(loreLines);
return togglePlayersItemFactory.build();
} }
/** /**
@ -98,13 +120,22 @@ public abstract class ArenaGUI extends AbstractGUI {
* @return <p>A player toggle item</p> * @return <p>A player toggle item</p>
*/ */
protected ItemStack getTogglePlayersItemEnabledBedrock() { protected ItemStack getTogglePlayersItemEnabledBedrock() {
GUIItemFactory togglePlayersItemFactory = new GUIItemFactory(Material.SKELETON_SKULL); return setTogglePlayersItemData(new SimpleGUIItemFactory(Material.SKELETON_SKULL));
}
/**
* Sets the lore and name for a toggle players item, and returns the finished item
*
* @param itemFactory <p>The factory to apply the data to</p>
* @return <p>The finished item, with the data applied</p>
*/
protected ItemStack setTogglePlayersItemData(@NotNull GUIItemFactory itemFactory) {
List<String> loreLines = getLoreLines(); List<String> loreLines = getLoreLines();
loreLines.add(ChatColor.GRAY + "Use this item to enable the visibility"); loreLines.add(ChatColor.GRAY + "Use this item to enable the visibility");
loreLines.add(ChatColor.GRAY + "of other players"); loreLines.add(ChatColor.GRAY + "of other players");
togglePlayersItemFactory.setName(ChatColor.BLUE + "Enable Players"); itemFactory.setName(ChatColor.BLUE + "Enable Players");
togglePlayersItemFactory.setLore(loreLines); itemFactory.setLore(loreLines);
return togglePlayersItemFactory.build(); return itemFactory.build();
} }
/** /**
@ -113,10 +144,10 @@ public abstract class ArenaGUI extends AbstractGUI {
* @return <p>A give up item</p> * @return <p>A give up item</p>
*/ */
protected ItemStack getGiveUpItem() { protected ItemStack getGiveUpItem() {
GUIItemFactory giveUpItemFactory = new GUIItemFactory(Material.RESPAWN_ANCHOR); GUIItemFactory giveUpItemFactory = new SimpleGUIItemFactory(Material.RESPAWN_ANCHOR);
List<String> loreLines = getLoreLines(); List<String> loreLines = getLoreLines();
loreLines.add(ChatColor.GRAY + "Use this item to give up"); loreLines.add(ChatColor.GRAY + "Use this item to give up and");
loreLines.add(ChatColor.GRAY + "and go to the last checkpoint"); loreLines.add(ChatColor.GRAY + "go to your current checkpoint");
giveUpItemFactory.setName(ChatColor.RED + "Give up"); giveUpItemFactory.setName(ChatColor.RED + "Give up");
giveUpItemFactory.setLore(loreLines); giveUpItemFactory.setLore(loreLines);
return giveUpItemFactory.build(); return giveUpItemFactory.build();
@ -128,7 +159,7 @@ public abstract class ArenaGUI extends AbstractGUI {
* @return <p>A leave item</p> * @return <p>A leave item</p>
*/ */
protected ItemStack getLeaveItem() { protected ItemStack getLeaveItem() {
GUIItemFactory leaveItemFactory = new GUIItemFactory(Material.BARRIER); GUIItemFactory leaveItemFactory = new SimpleGUIItemFactory(Material.BARRIER);
List<String> loreLines = getLoreLines(); List<String> loreLines = getLoreLines();
loreLines.add(ChatColor.GRAY + "Use this item to leave the arena"); loreLines.add(ChatColor.GRAY + "Use this item to leave the arena");
leaveItemFactory.setName(ChatColor.DARK_RED + "Leave"); leaveItemFactory.setName(ChatColor.DARK_RED + "Leave");
@ -198,7 +229,7 @@ public abstract class ArenaGUI extends AbstractGUI {
PlayerVisibilityManager visibilityManager = MiniGames.getInstance().getPlayerVisibilityManager(); PlayerVisibilityManager visibilityManager = MiniGames.getInstance().getPlayerVisibilityManager();
visibilityManager.toggleHidePlayers(playerRegistry, player); visibilityManager.toggleHidePlayers(playerRegistry, player);
if (MiniGames.getInstance().getPlayerVisibilityManager().isHidingPlayers(player)) { if (MiniGames.getInstance().getPlayerVisibilityManager().isHidingPlayers(player)) {
setItem(inventorySlot, getTogglePlayersItemEnabled()); setItem(inventorySlot, getTogglePlayersItemEnabled(player));
} else { } else {
setItem(inventorySlot, getTogglePlayersItemDisabled()); setItem(inventorySlot, getTogglePlayersItemDisabled());
} }

View File

@ -16,12 +16,12 @@ public class DropperGUI extends ArenaGUI {
public DropperGUI(Player player) { public DropperGUI(Player player) {
super(9, "Dropper"); super(9, "Dropper");
if (MiniGames.getInstance().getPlayerVisibilityManager().isHidingPlayers(player)) { if (MiniGames.getInstance().getPlayerVisibilityManager().isHidingPlayers(player)) {
setItem(0, getTogglePlayersItemEnabled()); setItem(0, getTogglePlayersItemEnabled(player));
} else { } else {
setItem(0, getTogglePlayersItemDisabled()); setItem(0, getTogglePlayersItemDisabled());
} }
setItem(2, getLeaveItem()); setItem(2, getLeaveItem());
setItem(4, getRestartItem()); setItem(4, getRestartItemJava());
setAnyClickAction(0, getTogglePlayersAction(MiniGames.getInstance().getDropperArenaPlayerRegistry(), 0)); setAnyClickAction(0, getTogglePlayersAction(MiniGames.getInstance().getDropperArenaPlayerRegistry(), 0));
setAnyClickAction(2, getLeaveAction()); setAnyClickAction(2, getLeaveAction());

View File

@ -16,16 +16,16 @@ public class DropperGUIBedrock extends ArenaGUI {
public DropperGUIBedrock(Player player) { public DropperGUIBedrock(Player player) {
super(27, "Dropper"); super(27, "Dropper");
if (MiniGames.getInstance().getPlayerVisibilityManager().isHidingPlayers(player)) { if (MiniGames.getInstance().getPlayerVisibilityManager().isHidingPlayers(player)) {
setItem(9, getTogglePlayersItemEnabledBedrock()); setItem(10, getTogglePlayersItemEnabledBedrock());
} else { } else {
setItem(9, getTogglePlayersItemDisabled()); setItem(10, getTogglePlayersItemDisabled());
} }
setItem(11, getLeaveItem()); setItem(12, getLeaveItem());
setItem(13, getRestartItemBedrock()); setItem(14, getRestartItemBedrock());
setAnyClickAction(9, getTogglePlayersAction(MiniGames.getInstance().getDropperArenaPlayerRegistry(), 9)); setAnyClickAction(10, getTogglePlayersAction(MiniGames.getInstance().getDropperArenaPlayerRegistry(), 10));
setAnyClickAction(11, getLeaveAction()); setAnyClickAction(12, getLeaveAction());
setAnyClickAction(13, getRestartAction()); setAnyClickAction(14, getRestartAction());
} }
} }

View File

@ -16,7 +16,7 @@ public class MiniGamesGUI extends ArenaGUI {
public MiniGamesGUI(Player player) { public MiniGamesGUI(Player player) {
super(9, "MiniGames"); super(9, "MiniGames");
if (MiniGames.getInstance().getPlayerVisibilityManager().isHidingPlayers(player)) { if (MiniGames.getInstance().getPlayerVisibilityManager().isHidingPlayers(player)) {
setItem(0, getTogglePlayersItemEnabled()); setItem(0, getTogglePlayersItemEnabled(player));
} else { } else {
setItem(0, getTogglePlayersItemDisabled()); setItem(0, getTogglePlayersItemDisabled());
} }

View File

@ -16,18 +16,18 @@ public class ParkourGUI extends ArenaGUI {
public ParkourGUI(Player player) { public ParkourGUI(Player player) {
super(9, "Parkour"); super(9, "Parkour");
if (MiniGames.getInstance().getPlayerVisibilityManager().isHidingPlayers(player)) { if (MiniGames.getInstance().getPlayerVisibilityManager().isHidingPlayers(player)) {
setItem(0, getTogglePlayersItemEnabled()); setItem(1, getTogglePlayersItemEnabled(player));
} else { } else {
setItem(0, getTogglePlayersItemDisabled()); setItem(1, getTogglePlayersItemDisabled());
} }
setItem(2, getGiveUpItem()); setItem(3, getGiveUpItem());
setItem(4, getLeaveItem()); setItem(5, getLeaveItem());
setItem(6, getRestartItem()); setItem(7, getRestartItemJava());
setAnyClickAction(0, getTogglePlayersAction(MiniGames.getInstance().getParkourArenaPlayerRegistry(), 0)); setAnyClickAction(1, getTogglePlayersAction(MiniGames.getInstance().getParkourArenaPlayerRegistry(), 1));
setAnyClickAction(2, getGiveUpAction()); setAnyClickAction(3, getGiveUpAction());
setAnyClickAction(4, getLeaveAction()); setAnyClickAction(5, getLeaveAction());
setAnyClickAction(6, getRestartAction()); setAnyClickAction(7, getRestartAction());
} }
} }

View File

@ -16,18 +16,18 @@ public class ParkourGUIBedrock extends ArenaGUI {
public ParkourGUIBedrock(Player player) { public ParkourGUIBedrock(Player player) {
super(27, "Parkour"); super(27, "Parkour");
if (MiniGames.getInstance().getPlayerVisibilityManager().isHidingPlayers(player)) { if (MiniGames.getInstance().getPlayerVisibilityManager().isHidingPlayers(player)) {
setItem(9, getTogglePlayersItemEnabledBedrock()); setItem(10, getTogglePlayersItemEnabled(player));
} else { } else {
setItem(9, getTogglePlayersItemDisabled()); setItem(10, getTogglePlayersItemDisabled());
} }
setItem(11, getGiveUpItem()); setItem(12, getGiveUpItem());
setItem(13, getLeaveItem()); setItem(14, getLeaveItem());
setItem(15, getRestartItemBedrock()); setItem(16, getRestartItemBedrock());
setAnyClickAction(9, getTogglePlayersAction(MiniGames.getInstance().getParkourArenaPlayerRegistry(), 9)); setAnyClickAction(10, getTogglePlayersAction(MiniGames.getInstance().getParkourArenaPlayerRegistry(), 10));
setAnyClickAction(11, getGiveUpAction()); setAnyClickAction(12, getGiveUpAction());
setAnyClickAction(13, getLeaveAction()); setAnyClickAction(14, getLeaveAction());
setAnyClickAction(15, getRestartAction()); setAnyClickAction(16, getRestartAction());
} }
} }

View File

@ -2,6 +2,7 @@ package net.knarcraft.minigames.util;
import net.knarcraft.knargui.item.GUIItemFactory; import net.knarcraft.knargui.item.GUIItemFactory;
import net.knarcraft.knargui.item.PlayerHeadGUIItemFactory; import net.knarcraft.knargui.item.PlayerHeadGUIItemFactory;
import net.knarcraft.knargui.item.SimpleGUIItemFactory;
import net.knarcraft.minigames.MiniGames; import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.ArenaSession; import net.knarcraft.minigames.arena.ArenaSession;
import net.knarcraft.minigames.gui.MiniGamesGUI; import net.knarcraft.minigames.gui.MiniGamesGUI;
@ -64,7 +65,7 @@ public final class GUIHelper {
* @return <p>The item used for opening the GUI</p> * @return <p>The item used for opening the GUI</p>
*/ */
public static ItemStack getGUIOpenItemBedrock() { public static ItemStack getGUIOpenItemBedrock() {
GUIItemFactory factory = new GUIItemFactory(Material.BEACON); GUIItemFactory factory = new SimpleGUIItemFactory(Material.BEACON);
factory.setName(ChatColor.AQUA + "MiniGames Menu"); factory.setName(ChatColor.AQUA + "MiniGames Menu");
ItemStack item = factory.build(); ItemStack item = factory.build();
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();