diff --git a/pom.xml b/pom.xml
index 718c374..45f5002 100644
--- a/pom.xml
+++ b/pom.xml
@@ -90,6 +90,10 @@
An arena restart item
+ */ + protected ItemStack getRestartItemBedrock() { + GUIItemFactory restartItemFactory = new GUIItemFactory(Material.MAGENTA_GLAZED_TERRACOTTA); + ListA player toggle item
+ */ + protected ItemStack getTogglePlayersItemEnabledBedrock() { + GUIItemFactory togglePlayersItemFactory = new GUIItemFactory(Material.SKELETON_SKULL); + ListA give up item
+ */ + protected ItemStack getGiveUpItem() { + GUIItemFactory giveUpItemFactory = new GUIItemFactory(Material.RESPAWN_ANCHOR); + ListThe registry containing relevant players
+ * @param inventorySlotThe inventory slot to replace when toggling
* @returnThe action for triggering player visibility
*/ - public GUIAction getTogglePlayersAction(ArenaPlayerRegistry> playerRegistry) { + public GUIAction getTogglePlayersAction(ArenaPlayerRegistry> playerRegistry, int inventorySlot) { return (player) -> { PlayerVisibilityManager visibilityManager = MiniGames.getInstance().getPlayerVisibilityManager(); visibilityManager.toggleHidePlayers(playerRegistry, player); if (MiniGames.getInstance().getPlayerVisibilityManager().isHidingPlayers(player)) { - setItem(0, getTogglePlayersItemEnabled()); + setItem(inventorySlot, getTogglePlayersItemEnabled()); } else { - setItem(0, getTogglePlayersItemDisabled()); + setItem(inventorySlot, getTogglePlayersItemDisabled()); + } + }; + } + + /** + * Gets the action to run when triggering the give up item + * + * @returnThe give up action
+ */ + public static GUIAction getGiveUpAction() { + return (player) -> { + ArenaSession session = MiniGames.getInstance().getSession(player.getUniqueId()); + if (session instanceof ParkourArenaSession) { + session.triggerLoss(); } }; } diff --git a/src/main/java/net/knarcraft/minigames/gui/DropperGUI.java b/src/main/java/net/knarcraft/minigames/gui/DropperGUI.java index acf2324..68422ff 100644 --- a/src/main/java/net/knarcraft/minigames/gui/DropperGUI.java +++ b/src/main/java/net/knarcraft/minigames/gui/DropperGUI.java @@ -23,7 +23,7 @@ public class DropperGUI extends ArenaGUI { setItem(2, getLeaveItem()); setItem(4, getRestartItem()); - setAnyClickAction(0, getTogglePlayersAction(MiniGames.getInstance().getDropperArenaPlayerRegistry())); + setAnyClickAction(0, getTogglePlayersAction(MiniGames.getInstance().getDropperArenaPlayerRegistry(), 0)); setAnyClickAction(2, getLeaveAction()); setAnyClickAction(4, getRestartAction()); } diff --git a/src/main/java/net/knarcraft/minigames/gui/DropperGUIBedrock.java b/src/main/java/net/knarcraft/minigames/gui/DropperGUIBedrock.java new file mode 100644 index 0000000..68ffbf6 --- /dev/null +++ b/src/main/java/net/knarcraft/minigames/gui/DropperGUIBedrock.java @@ -0,0 +1,31 @@ +package net.knarcraft.minigames.gui; + +import net.knarcraft.minigames.MiniGames; +import org.bukkit.entity.Player; + +/** + * A GUI used in the dropper arena, altered for Bedrock players + */ +public class DropperGUIBedrock extends ArenaGUI { + + /** + * Instantiates a new dropper gui + * + * @param playerThe player the GUI is created for
+ */ + public DropperGUIBedrock(Player player) { + super(27, "Dropper"); + if (MiniGames.getInstance().getPlayerVisibilityManager().isHidingPlayers(player)) { + setItem(9, getTogglePlayersItemEnabledBedrock()); + } else { + setItem(9, getTogglePlayersItemDisabled()); + } + setItem(11, getLeaveItem()); + setItem(13, getRestartItemBedrock()); + + setAnyClickAction(9, getTogglePlayersAction(MiniGames.getInstance().getDropperArenaPlayerRegistry(), 9)); + setAnyClickAction(11, getLeaveAction()); + setAnyClickAction(13, getRestartAction()); + } + +} diff --git a/src/main/java/net/knarcraft/minigames/gui/MiniGamesGUI.java b/src/main/java/net/knarcraft/minigames/gui/MiniGamesGUI.java index 4dca1f4..c12ef6c 100644 --- a/src/main/java/net/knarcraft/minigames/gui/MiniGamesGUI.java +++ b/src/main/java/net/knarcraft/minigames/gui/MiniGamesGUI.java @@ -21,7 +21,7 @@ public class MiniGamesGUI extends ArenaGUI { setItem(0, getTogglePlayersItemDisabled()); } - setAnyClickAction(0, getTogglePlayersAction(null)); + setAnyClickAction(0, getTogglePlayersAction(null, 0)); } } diff --git a/src/main/java/net/knarcraft/minigames/gui/ParkourGUI.java b/src/main/java/net/knarcraft/minigames/gui/ParkourGUI.java index 1783cc3..6b1d8dc 100644 --- a/src/main/java/net/knarcraft/minigames/gui/ParkourGUI.java +++ b/src/main/java/net/knarcraft/minigames/gui/ParkourGUI.java @@ -1,16 +1,7 @@ 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 @@ -33,39 +24,10 @@ public class ParkourGUI extends ArenaGUI { setItem(4, getLeaveItem()); setItem(6, getRestartItem()); - setAnyClickAction(0, getTogglePlayersAction(MiniGames.getInstance().getParkourArenaPlayerRegistry())); + setAnyClickAction(0, getTogglePlayersAction(MiniGames.getInstance().getParkourArenaPlayerRegistry(), 0)); setAnyClickAction(2, getGiveUpAction()); setAnyClickAction(4, getLeaveAction()); setAnyClickAction(6, getRestartAction()); } - /** - * Gets an item describing a give up action - * - * @returnA give up item
- */ - private ItemStack getGiveUpItem() { - GUIItemFactory giveUpItemFactory = new GUIItemFactory(Material.RESPAWN_ANCHOR); - ListThe give up action
- */ - public static GUIAction getGiveUpAction() { - return (player) -> { - ArenaSession session = MiniGames.getInstance().getSession(player.getUniqueId()); - if (session instanceof ParkourArenaSession) { - session.triggerLoss(); - } - }; - } - } diff --git a/src/main/java/net/knarcraft/minigames/gui/ParkourGUIBedrock.java b/src/main/java/net/knarcraft/minigames/gui/ParkourGUIBedrock.java new file mode 100644 index 0000000..b23de48 --- /dev/null +++ b/src/main/java/net/knarcraft/minigames/gui/ParkourGUIBedrock.java @@ -0,0 +1,33 @@ +package net.knarcraft.minigames.gui; + +import net.knarcraft.minigames.MiniGames; +import org.bukkit.entity.Player; + +/** + * A GUI used in the parkour arena, altered for Bedrock players + */ +public class ParkourGUIBedrock extends ArenaGUI { + + /** + * Instantiates a new parkour gui + * + * @param playerThe player the GUI is created for
+ */ + public ParkourGUIBedrock(Player player) { + super(27, "Parkour"); + if (MiniGames.getInstance().getPlayerVisibilityManager().isHidingPlayers(player)) { + setItem(9, getTogglePlayersItemEnabledBedrock()); + } else { + setItem(9, getTogglePlayersItemDisabled()); + } + setItem(11, getGiveUpItem()); + setItem(13, getLeaveItem()); + setItem(15, getRestartItemBedrock()); + + setAnyClickAction(9, getTogglePlayersAction(MiniGames.getInstance().getParkourArenaPlayerRegistry(), 9)); + setAnyClickAction(11, getGiveUpAction()); + setAnyClickAction(13, getLeaveAction()); + setAnyClickAction(15, getRestartAction()); + } + +} diff --git a/src/main/java/net/knarcraft/minigames/util/GUIHelper.java b/src/main/java/net/knarcraft/minigames/util/GUIHelper.java index 90e4ecc..fa68e73 100644 --- a/src/main/java/net/knarcraft/minigames/util/GUIHelper.java +++ b/src/main/java/net/knarcraft/minigames/util/GUIHelper.java @@ -1,16 +1,19 @@ package net.knarcraft.minigames.util; +import net.knarcraft.knargui.item.GUIItemFactory; import net.knarcraft.knargui.item.PlayerHeadGUIItemFactory; import net.knarcraft.minigames.MiniGames; import net.knarcraft.minigames.arena.ArenaSession; import net.knarcraft.minigames.gui.MiniGamesGUI; import net.knarcraft.minigames.property.PersistentDataKey; import org.bukkit.ChatColor; +import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.persistence.PersistentDataType; +import org.jetbrains.annotations.NotNull; /** * A helper class for the in-arena GUI @@ -21,12 +24,26 @@ public final class GUIHelper { } + /** + * Gets the GUI open item to give to the specified player + * + * @param playerThe player to give a GUI opening item
+ * @returnThe item to give
+ */ + public static ItemStack getGUIOpenItem(@NotNull Player player) { + if (GeyserHelper.isGeyserPlayer(player)) { + return getGUIOpenItemBedrock(); + } else { + return getGUIOpenItemJava(); + } + } + /** * Gets the item used for opening the mini-games menu * * @returnThe item used for opening the GUI
*/ - public static ItemStack getGUIOpenItem() { + public static ItemStack getGUIOpenItemJava() { PlayerHeadGUIItemFactory factory = new PlayerHeadGUIItemFactory(); factory.useSkin("3fdab40434ed5d01f58c45ca0c9fada4662e1772ff43e2974979440a5cfe15c9"); factory.setName(ChatColor.AQUA + "§ MiniGames Menu §"); @@ -41,6 +58,25 @@ public final class GUIHelper { return item; } + /** + * Gets the item used for opening the mini-games menu + * + * @returnThe item used for opening the GUI
+ */ + public static ItemStack getGUIOpenItemBedrock() { + GUIItemFactory factory = new GUIItemFactory(Material.BEACON); + factory.setName(ChatColor.AQUA + "MiniGames Menu"); + ItemStack item = factory.build(); + ItemMeta meta = item.getItemMeta(); + if (meta != null) { + meta.getPersistentDataContainer().set(new NamespacedKey(MiniGames.getInstance(), + PersistentDataKey.MENU_ITEM.getKeyName()), + PersistentDataType.INTEGER, PersistentDataKey.MENU_ITEM.getDataValue()); + } + item.setItemMeta(meta); + return item; + } + /** * Opens the correct GUI for the given player * diff --git a/src/main/java/net/knarcraft/minigames/util/GeyserHelper.java b/src/main/java/net/knarcraft/minigames/util/GeyserHelper.java new file mode 100644 index 0000000..3c79f27 --- /dev/null +++ b/src/main/java/net/knarcraft/minigames/util/GeyserHelper.java @@ -0,0 +1,53 @@ +package net.knarcraft.minigames.util; + +import org.bukkit.entity.Player; +import org.geysermc.floodgate.api.FloodgateApi; +import org.geysermc.geyser.api.GeyserApi; +import org.jetbrains.annotations.NotNull; + +/** + * A helper class for dealing with geyser/floodgate players + */ +public final class GeyserHelper { + + private static boolean hasGeyser = true; + private static boolean hasFloodgate = true; + + private GeyserHelper() { + + } + + /** + * Checks whether the given player is connected through Geyser + * + * @param playerThe player to check
+ * @returnTrue if the player is connected through Geyser
+ */ + public static boolean isGeyserPlayer(@NotNull Player player) { + // Prevent unnecessary checking for non-geyser and floodgate servers + if (!hasGeyser && !hasFloodgate) { + return false; + } + + // Use Geyser API to get connection status + if (hasGeyser) { + try { + return GeyserApi.api().connectionByUuid(player.getUniqueId()) != null; + } catch (NoClassDefFoundError error1) { + hasGeyser = false; + } + } + + // Use Floodgate API to get connection status + if (hasFloodgate) { + try { + return FloodgateApi.getInstance().isFloodgatePlayer(player.getUniqueId()); + } catch (NoClassDefFoundError error2) { + hasFloodgate = false; + } + } + + return false; + } + +} diff --git a/src/main/resources/strings.yml b/src/main/resources/strings.yml index 958e0a6..93bd9cf 100644 --- a/src/main/resources/strings.yml +++ b/src/main/resources/strings.yml @@ -29,6 +29,7 @@ en: ERROR_INVALID_COMMAND_STRING: "You specified an invalid command. Make sure you don't add a slash in front of the command definition." ERROR_REWARD_TYPE_INVALID: "You have specified an invalid reward type" ERROR_REWARD_CONDITION_INVALID: "You have specified an invalid reward condition" + ERROR_GEYSER_DROPPER: "Because of version differences, droppers don't work properly using the Bedrock client. Please use Minecraft Java Edition instead." SUCCESS_ARENA_GROUP_UPDATED: "The arena's group has been updated" SUCCESS_PLUGIN_RELOADED: "Plugin reloaded!" SUCCESS_ARENA_CREATED: "The arena was successfully created!"