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.item.GUIItemFactory;
import net.knarcraft.knargui.item.PlayerHeadGUIItemFactory;
import net.knarcraft.knargui.item.SimpleGUIItemFactory;
import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.ArenaPlayerRegistry;
import net.knarcraft.minigames.arena.ArenaSession;
import net.knarcraft.minigames.arena.PlayerVisibilityManager;
import net.knarcraft.minigames.arena.parkour.ParkourArenaSession;
import net.knarcraft.minigames.util.GeyserHelper;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
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>
*/
protected ItemStack getRestartItem() {
@NotNull
protected ItemStack getRestartItemJava() {
PlayerHeadGUIItemFactory restartItemFactory = new PlayerHeadGUIItemFactory();
restartItemFactory.useSkin("e23b225ed0443c4eec7cf30a034490485904e6eb3d53ef2ab9e39c73bdf22c30");
List<String> loreLines = getLoreLines();
loreLines.add(ChatColor.GRAY + "Use this item to retry the arena");
restartItemFactory.setName(ChatColor.BLUE + "Retry arena");
restartItemFactory.setLore(loreLines);
return restartItemFactory.build();
return setRestartItemData(restartItemFactory);
}
/**
* 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>
*/
@NotNull
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();
loreLines.add(ChatColor.GRAY + "Use this item to retry the arena");
restartItemFactory.setName(ChatColor.BLUE + "Retry arena");
restartItemFactory.setLore(loreLines);
return restartItemFactory.build();
loreLines.add(ChatColor.GRAY + "(deaths and time is reset to 0)");
guiItemFactory.setName(ChatColor.BLUE + "Retry arena");
guiItemFactory.setLore(loreLines);
return guiItemFactory.build();
}
/**
@ -67,7 +80,7 @@ public abstract class ArenaGUI extends AbstractGUI {
* @return <p>A player toggle item</p>
*/
protected ItemStack getTogglePlayersItemDisabled() {
GUIItemFactory togglePlayersItemFactory = new GUIItemFactory(Material.PLAYER_HEAD);
GUIItemFactory togglePlayersItemFactory = new SimpleGUIItemFactory(Material.PLAYER_HEAD);
List<String> loreLines = getLoreLines();
loreLines.add(ChatColor.GRAY + "Use this item to disable the visibility");
loreLines.add(ChatColor.GRAY + "of other players");
@ -79,17 +92,26 @@ public abstract class ArenaGUI extends AbstractGUI {
/**
* 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>
*/
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();
togglePlayersItemFactory.useSkin("c10591e6909e6a281b371836e462d67a2c78fa0952e910f32b41a26c48c1757c");
List<String> loreLines = getLoreLines();
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();
return setTogglePlayersItemData(togglePlayersItemFactory);
}
/**
@ -98,13 +120,22 @@ public abstract class ArenaGUI extends AbstractGUI {
* @return <p>A player toggle item</p>
*/
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();
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();
itemFactory.setName(ChatColor.BLUE + "Enable Players");
itemFactory.setLore(loreLines);
return itemFactory.build();
}
/**
@ -113,10 +144,10 @@ public abstract class ArenaGUI extends AbstractGUI {
* @return <p>A give up item</p>
*/
protected ItemStack getGiveUpItem() {
GUIItemFactory giveUpItemFactory = new GUIItemFactory(Material.RESPAWN_ANCHOR);
GUIItemFactory giveUpItemFactory = new SimpleGUIItemFactory(Material.RESPAWN_ANCHOR);
List<String> loreLines = getLoreLines();
loreLines.add(ChatColor.GRAY + "Use this item to give up");
loreLines.add(ChatColor.GRAY + "and go to the last checkpoint");
loreLines.add(ChatColor.GRAY + "Use this item to give up and");
loreLines.add(ChatColor.GRAY + "go to your current checkpoint");
giveUpItemFactory.setName(ChatColor.RED + "Give up");
giveUpItemFactory.setLore(loreLines);
return giveUpItemFactory.build();
@ -128,7 +159,7 @@ public abstract class ArenaGUI extends AbstractGUI {
* @return <p>A leave item</p>
*/
protected ItemStack getLeaveItem() {
GUIItemFactory leaveItemFactory = new GUIItemFactory(Material.BARRIER);
GUIItemFactory leaveItemFactory = new SimpleGUIItemFactory(Material.BARRIER);
List<String> loreLines = getLoreLines();
loreLines.add(ChatColor.GRAY + "Use this item to leave the arena");
leaveItemFactory.setName(ChatColor.DARK_RED + "Leave");
@ -198,7 +229,7 @@ public abstract class ArenaGUI extends AbstractGUI {
PlayerVisibilityManager visibilityManager = MiniGames.getInstance().getPlayerVisibilityManager();
visibilityManager.toggleHidePlayers(playerRegistry, player);
if (MiniGames.getInstance().getPlayerVisibilityManager().isHidingPlayers(player)) {
setItem(inventorySlot, getTogglePlayersItemEnabled());
setItem(inventorySlot, getTogglePlayersItemEnabled(player));
} else {
setItem(inventorySlot, getTogglePlayersItemDisabled());
}

View File

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

View File

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

View File

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

View File

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

View File

@ -16,18 +16,18 @@ public class ParkourGUIBedrock extends ArenaGUI {
public ParkourGUIBedrock(Player player) {
super(27, "Parkour");
if (MiniGames.getInstance().getPlayerVisibilityManager().isHidingPlayers(player)) {
setItem(9, getTogglePlayersItemEnabledBedrock());
setItem(10, getTogglePlayersItemEnabled(player));
} else {
setItem(9, getTogglePlayersItemDisabled());
setItem(10, getTogglePlayersItemDisabled());
}
setItem(11, getGiveUpItem());
setItem(13, getLeaveItem());
setItem(15, getRestartItemBedrock());
setItem(12, getGiveUpItem());
setItem(14, getLeaveItem());
setItem(16, getRestartItemBedrock());
setAnyClickAction(9, getTogglePlayersAction(MiniGames.getInstance().getParkourArenaPlayerRegistry(), 9));
setAnyClickAction(11, getGiveUpAction());
setAnyClickAction(13, getLeaveAction());
setAnyClickAction(15, getRestartAction());
setAnyClickAction(10, getTogglePlayersAction(MiniGames.getInstance().getParkourArenaPlayerRegistry(), 10));
setAnyClickAction(12, getGiveUpAction());
setAnyClickAction(14, getLeaveAction());
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.PlayerHeadGUIItemFactory;
import net.knarcraft.knargui.item.SimpleGUIItemFactory;
import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.ArenaSession;
import net.knarcraft.minigames.gui.MiniGamesGUI;
@ -64,7 +65,7 @@ public final class GUIHelper {
* @return <p>The item used for opening the GUI</p>
*/
public static ItemStack getGUIOpenItemBedrock() {
GUIItemFactory factory = new GUIItemFactory(Material.BEACON);
GUIItemFactory factory = new SimpleGUIItemFactory(Material.BEACON);
factory.setName(ChatColor.AQUA + "MiniGames Menu");
ItemStack item = factory.build();
ItemMeta meta = item.getItemMeta();