The size of the GUI's inventory
- * @param inventoryNameThe name of the inventory
- * @param playerRegistryThe player registry used for this GUI
+ * @param inventorySizeThe size of the GUI's inventory
+ * @param inventoryNameThe name of the inventory
*/ - public ArenaGUI(int inventorySize, String inventoryName, ArenaPlayerRegistry> playerRegistry) { + public ArenaGUI(int inventorySize, String inventoryName) { super(inventorySize, inventoryName, null); - this.playerRegistry = playerRegistry; + } + + /** + * Gets an item describing a retry arena action + * + * @returnAn arena restart item
+ */ + protected ItemStack getRestartItem() { + PlayerHeadGUIItemFactory restartItemFactory = new PlayerHeadGUIItemFactory(); + restartItemFactory.useSkin("e23b225ed0443c4eec7cf30a034490485904e6eb3d53ef2ab9e39c73bdf22c30"); + ListThe leave action
*/ - protected GUIAction getLeaveAction() { + public static GUIAction getLeaveAction() { return (player) -> { ArenaSession session = MiniGames.getInstance().getSession(player.getUniqueId()); if (session != null) { @@ -117,12 +128,27 @@ public abstract class ArenaGUI extends AbstractGUI { }; } + /** + * Gets the action to run when triggering the restart action + * + * @returnThe action for triggering a session restart
+ */ + public static GUIAction getRestartAction() { + return (player -> { + ArenaSession session = MiniGames.getInstance().getSession(player.getUniqueId()); + if (session != null) { + session.reset(); + } + }); + } + /** * Gets the action to run when triggering the toggle players action * + * @param playerRegistryThe registry containing relevant players
* @returnThe action for triggering player visibility
*/ - protected GUIAction getTogglePlayersAction() { + public GUIAction getTogglePlayersAction(ArenaPlayerRegistry> playerRegistry) { return (player) -> { PlayerVisibilityManager visibilityManager = MiniGames.getInstance().getPlayerVisibilityManager(); visibilityManager.toggleHidePlayers(playerRegistry, player); diff --git a/src/main/java/net/knarcraft/minigames/gui/DropperGUI.java b/src/main/java/net/knarcraft/minigames/gui/DropperGUI.java index a280166..acf2324 100644 --- a/src/main/java/net/knarcraft/minigames/gui/DropperGUI.java +++ b/src/main/java/net/knarcraft/minigames/gui/DropperGUI.java @@ -14,16 +14,18 @@ public class DropperGUI extends ArenaGUI { * @param playerThe player the GUI is created for
*/ public DropperGUI(Player player) { - super(9, "Dropper", MiniGames.getInstance().getDropperArenaPlayerRegistry()); + super(9, "Dropper"); if (MiniGames.getInstance().getPlayerVisibilityManager().isHidingPlayers(player)) { setItem(0, getTogglePlayersItemEnabled()); } else { setItem(0, getTogglePlayersItemDisabled()); } setItem(2, getLeaveItem()); + setItem(4, getRestartItem()); - setAnyClickAction(0, getTogglePlayersAction()); + setAnyClickAction(0, getTogglePlayersAction(MiniGames.getInstance().getDropperArenaPlayerRegistry())); setAnyClickAction(2, getLeaveAction()); + setAnyClickAction(4, getRestartAction()); } } diff --git a/src/main/java/net/knarcraft/minigames/gui/MiniGamesGUI.java b/src/main/java/net/knarcraft/minigames/gui/MiniGamesGUI.java index 7b8f34e..4dca1f4 100644 --- a/src/main/java/net/knarcraft/minigames/gui/MiniGamesGUI.java +++ b/src/main/java/net/knarcraft/minigames/gui/MiniGamesGUI.java @@ -14,14 +14,14 @@ public class MiniGamesGUI extends ArenaGUI { * @param playerThe player the GUI is created for
*/ public MiniGamesGUI(Player player) { - super(9, "MiniGames", null); + super(9, "MiniGames"); if (MiniGames.getInstance().getPlayerVisibilityManager().isHidingPlayers(player)) { setItem(0, getTogglePlayersItemEnabled()); } else { setItem(0, getTogglePlayersItemDisabled()); } - setAnyClickAction(0, getTogglePlayersAction()); + setAnyClickAction(0, getTogglePlayersAction(null)); } } diff --git a/src/main/java/net/knarcraft/minigames/gui/ParkourGUI.java b/src/main/java/net/knarcraft/minigames/gui/ParkourGUI.java index ac6d4d0..1783cc3 100644 --- a/src/main/java/net/knarcraft/minigames/gui/ParkourGUI.java +++ b/src/main/java/net/knarcraft/minigames/gui/ParkourGUI.java @@ -23,7 +23,7 @@ public class ParkourGUI extends ArenaGUI { * @param playerThe player the GUI is created for
*/ public ParkourGUI(Player player) { - super(9, "Parkour", MiniGames.getInstance().getParkourArenaPlayerRegistry()); + super(9, "Parkour"); if (MiniGames.getInstance().getPlayerVisibilityManager().isHidingPlayers(player)) { setItem(0, getTogglePlayersItemEnabled()); } else { @@ -31,10 +31,12 @@ public class ParkourGUI extends ArenaGUI { } setItem(2, getGiveUpItem()); setItem(4, getLeaveItem()); + setItem(6, getRestartItem()); - setAnyClickAction(0, getTogglePlayersAction()); + setAnyClickAction(0, getTogglePlayersAction(MiniGames.getInstance().getParkourArenaPlayerRegistry())); setAnyClickAction(2, getGiveUpAction()); setAnyClickAction(4, getLeaveAction()); + setAnyClickAction(6, getRestartAction()); } /** @@ -57,7 +59,7 @@ public class ParkourGUI extends ArenaGUI { * * @returnThe give up action
*/ - private GUIAction getGiveUpAction() { + public static GUIAction getGiveUpAction() { return (player) -> { ArenaSession session = MiniGames.getInstance().getSession(player.getUniqueId()); if (session instanceof ParkourArenaSession) { diff --git a/src/main/java/net/knarcraft/minigames/listener/InteractListener.java b/src/main/java/net/knarcraft/minigames/listener/InteractListener.java index f476b68..fe96318 100644 --- a/src/main/java/net/knarcraft/minigames/listener/InteractListener.java +++ b/src/main/java/net/knarcraft/minigames/listener/InteractListener.java @@ -1,6 +1,8 @@ package net.knarcraft.minigames.listener; import net.knarcraft.minigames.MiniGames; +import net.knarcraft.minigames.gui.ArenaGUI; +import net.knarcraft.minigames.gui.ParkourGUI; import net.knarcraft.minigames.property.PersistentDataKey; import net.knarcraft.minigames.util.GUIHelper; import org.bukkit.NamespacedKey; @@ -33,6 +35,20 @@ public class InteractListener implements Listener { if (persistentData != null && persistentData == PersistentDataKey.MENU_ITEM.getDataValue()) { event.setCancelled(true); GUIHelper.openGUI(event.getPlayer()); + return; + } + + persistentData = meta.getPersistentDataContainer().get(new NamespacedKey(MiniGames.getInstance(), + PersistentDataKey.LEAVE_ITEM.getKeyName()), PersistentDataType.INTEGER); + if (persistentData != null) { + event.setCancelled(true); + if (persistentData == PersistentDataKey.LEAVE_ITEM.getDataValue()) { + ArenaGUI.getLeaveAction().run(event.getPlayer()); + } else if (persistentData == PersistentDataKey.GIVE_UP_ITEM.getDataValue()) { + ParkourGUI.getGiveUpAction().run(event.getPlayer()); + } else if (persistentData == PersistentDataKey.TOGGLE_PLAYERS_ITEM.getDataValue()) { + //TODO: Figure out how in the world this should be done, as the existing code cannot be re-used + } } } diff --git a/src/main/java/net/knarcraft/minigames/placeholder/RecordExpansion.java b/src/main/java/net/knarcraft/minigames/placeholder/RecordExpansion.java index 9dca66c..93a0822 100644 --- a/src/main/java/net/knarcraft/minigames/placeholder/RecordExpansion.java +++ b/src/main/java/net/knarcraft/minigames/placeholder/RecordExpansion.java @@ -1,6 +1,7 @@ package net.knarcraft.minigames.placeholder; import me.clip.placeholderapi.expansion.PlaceholderExpansion; +import net.knarcraft.minigames.MiniGames; import net.knarcraft.minigames.arena.Arena; import net.knarcraft.minigames.arena.ArenaGameMode; import net.knarcraft.minigames.arena.ArenaGroup; @@ -26,6 +27,7 @@ import java.util.Objects; import java.util.Set; import java.util.UUID; import java.util.function.Supplier; +import java.util.logging.Level; /** * A placeholder expansion for parkour record placeholders @@ -71,7 +73,14 @@ public abstract class RecordExpansion extends PlaceholderExpansion { ArenaGameMode gameMode = parseGameMode(parts[2]); SelectionType selectionType = SelectionType.getFromString(parts[3]); String identifier = parts[4]; - int recordNumber = Integer.parseInt(parts[5]) - 1; + int recordNumber; + try { + recordNumber = Integer.parseInt(parts[5]) - 1; + } catch (NumberFormatException exception) { + MiniGames.log(Level.WARNING, "Invalid placeholder given. " + parts[5] + + " supplied instead of record placement."); + return parameters; + } InfoType infoType = InfoType.getFromString(parts[6]); if (recordType == null || infoType == null) { diff --git a/src/main/java/net/knarcraft/minigames/property/PersistentDataKey.java b/src/main/java/net/knarcraft/minigames/property/PersistentDataKey.java index 2965f89..a3343ab 100644 --- a/src/main/java/net/knarcraft/minigames/property/PersistentDataKey.java +++ b/src/main/java/net/knarcraft/minigames/property/PersistentDataKey.java @@ -6,6 +6,9 @@ package net.knarcraft.minigames.property; public enum PersistentDataKey { MENU_ITEM("MiniGamesMenu", 1799804), + LEAVE_ITEM("MiniGamesAction", 1799871), + GIVE_UP_ITEM("MiniGamesAction", 1799872), + TOGGLE_PLAYERS_ITEM("MiniGamesAction", 1799873), ; private final String keyName;