diff --git a/src/main/java/net/knarcraft/minigames/MiniGames.java b/src/main/java/net/knarcraft/minigames/MiniGames.java index b3cf612..baea40d 100644 --- a/src/main/java/net/knarcraft/minigames/MiniGames.java +++ b/src/main/java/net/knarcraft/minigames/MiniGames.java @@ -310,7 +310,7 @@ public final class MiniGames extends JavaPlugin { pluginManager.registerEvents(new MoveListener(this.dropperConfiguration, this.parkourConfiguration), this); pluginManager.registerEvents(new PlayerStateChangeListener(), this); pluginManager.registerEvents(new CommandListener(), this); - pluginManager.registerEvents(new GUIListener(false), this); + pluginManager.registerEvents(new GUIListener(true), this); } /** diff --git a/src/main/java/net/knarcraft/minigames/arena/PlayerVisibilityManager.java b/src/main/java/net/knarcraft/minigames/arena/PlayerVisibilityManager.java index 69c6c97..fbd18c9 100644 --- a/src/main/java/net/knarcraft/minigames/arena/PlayerVisibilityManager.java +++ b/src/main/java/net/knarcraft/minigames/arena/PlayerVisibilityManager.java @@ -4,6 +4,7 @@ import net.knarcraft.minigames.MiniGames; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.HashSet; import java.util.Set; @@ -34,6 +35,16 @@ public class PlayerVisibilityManager { } + /** + * Gets whether the given player is currently hiding other players + * + * @param player

The player to check

+ * @return

True if currently hiding other players

+ */ + public boolean isHidingPlayers(Player player) { + return this.hidingEnabledFor.contains(player.getUniqueId()); + } + /** * Updates which players are seen as hidden * @@ -77,7 +88,10 @@ public class PlayerVisibilityManager { * @param player

The player to change the visibility for

* @param hide

Whether to hide the players or show the players

*/ - private void changeVisibilityFor(@NotNull ArenaPlayerRegistry playerRegistry, @NotNull Player player, boolean hide) { + private void changeVisibilityFor(@Nullable ArenaPlayerRegistry playerRegistry, @NotNull Player player, boolean hide) { + if (playerRegistry == null) { + return; + } for (UUID playerId : playerRegistry.getPlayingPlayers()) { Player otherPlayer = Bukkit.getPlayer(playerId); if (otherPlayer == null) { diff --git a/src/main/java/net/knarcraft/minigames/arena/dropper/DropperArenaSession.java b/src/main/java/net/knarcraft/minigames/arena/dropper/DropperArenaSession.java index 78a4911..f20457f 100644 --- a/src/main/java/net/knarcraft/minigames/arena/dropper/DropperArenaSession.java +++ b/src/main/java/net/knarcraft/minigames/arena/dropper/DropperArenaSession.java @@ -17,8 +17,6 @@ import java.util.logging.Level; */ public class DropperArenaSession extends AbstractArenaSession { - private static final ArenaGUI gui = new DropperGUI(); - private final @NotNull DropperArena arena; private final @NotNull Player player; private final @NotNull DropperArenaGameMode gameMode; @@ -102,7 +100,7 @@ public class DropperArenaSession extends AbstractArenaSession { @Override public @NotNull ArenaGUI getGUI() { - return gui; + return new DropperGUI(player); } @Override diff --git a/src/main/java/net/knarcraft/minigames/arena/parkour/ParkourArenaSession.java b/src/main/java/net/knarcraft/minigames/arena/parkour/ParkourArenaSession.java index 0bf3a4c..1a1ae73 100644 --- a/src/main/java/net/knarcraft/minigames/arena/parkour/ParkourArenaSession.java +++ b/src/main/java/net/knarcraft/minigames/arena/parkour/ParkourArenaSession.java @@ -19,8 +19,6 @@ import java.util.logging.Level; */ public class ParkourArenaSession extends AbstractArenaSession { - private static final ArenaGUI gui = new ParkourGUI(); - private final @NotNull ParkourArena arena; private final @NotNull Player player; private final @NotNull ParkourArenaGameMode gameMode; @@ -115,7 +113,7 @@ public class ParkourArenaSession extends AbstractArenaSession { @Override public @NotNull ArenaGUI getGUI() { - return gui; + return new ParkourGUI(player); } @Override diff --git a/src/main/java/net/knarcraft/minigames/command/MenuCommand.java b/src/main/java/net/knarcraft/minigames/command/MenuCommand.java index ca97c3e..9a9135e 100644 --- a/src/main/java/net/knarcraft/minigames/command/MenuCommand.java +++ b/src/main/java/net/knarcraft/minigames/command/MenuCommand.java @@ -3,6 +3,7 @@ package net.knarcraft.minigames.command; import net.knarcraft.minigames.MiniGames; import net.knarcraft.minigames.arena.ArenaSession; import net.knarcraft.minigames.config.Message; +import net.knarcraft.minigames.gui.MiniGamesGUI; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabExecutor; @@ -28,12 +29,12 @@ public class MenuCommand implements TabExecutor { ArenaSession existingSession = MiniGames.getInstance().getSession(player.getUniqueId()); if (existingSession == null) { - commandSender.sendMessage(Message.ERROR_NOT_IN_ARENA.getMessage()); + new MiniGamesGUI(player).openFor(player); return false; + } else { + existingSession.getGUI().openFor(player); + return true; } - - existingSession.getGUI().openFor(player); - return true; } @Nullable diff --git a/src/main/java/net/knarcraft/minigames/gui/ArenaGUI.java b/src/main/java/net/knarcraft/minigames/gui/ArenaGUI.java index 3d81696..fdca5c8 100644 --- a/src/main/java/net/knarcraft/minigames/gui/ArenaGUI.java +++ b/src/main/java/net/knarcraft/minigames/gui/ArenaGUI.java @@ -3,9 +3,11 @@ package net.knarcraft.minigames.gui; 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.minigames.MiniGames; import net.knarcraft.minigames.arena.ArenaPlayerRegistry; import net.knarcraft.minigames.arena.ArenaSession; +import net.knarcraft.minigames.arena.PlayerVisibilityManager; import net.md_5.bungee.api.ChatColor; import org.bukkit.Material; import org.bukkit.event.inventory.ClickType; @@ -38,16 +40,33 @@ public abstract class ArenaGUI extends AbstractGUI { * * @return

A player toggle item

*/ - protected ItemStack getTogglePlayersItem() { + protected ItemStack getTogglePlayersItemDisabled() { GUIItemFactory togglePlayersItemFactory = new GUIItemFactory(Material.PLAYER_HEAD); List loreLines = getLoreLines(); - loreLines.add(ChatColor.GRAY + "Use this item to toggle the visibility"); + loreLines.add(ChatColor.GRAY + "Use this item to disable the visibility"); loreLines.add(ChatColor.GRAY + "of other players"); - togglePlayersItemFactory.setName(ChatColor.BLUE + "Toggle Players"); + togglePlayersItemFactory.setName(ChatColor.BLUE + "Disable Players"); togglePlayersItemFactory.setLore(loreLines); return togglePlayersItemFactory.build(); } + /** + * Gets an item describing player visibility toggling + * + * @return

A player toggle item

+ */ + protected ItemStack getTogglePlayersItemEnabled() { + PlayerHeadGUIItemFactory togglePlayersItemFactory = new PlayerHeadGUIItemFactory(); + togglePlayersItemFactory.useSkin("c10591e6909e6a281b371836e462d67a2c78fa0952e910f32b41a26c48c1757c"); + List 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(); + } + + /** * Gets an item describing a leave arena action * @@ -104,8 +123,15 @@ public abstract class ArenaGUI extends AbstractGUI { * @return

The action for triggering player visibility

*/ protected GUIAction getTogglePlayersAction() { - return (player) -> MiniGames.getInstance().getPlayerVisibilityManager().toggleHidePlayers(playerRegistry, - player); + return (player) -> { + PlayerVisibilityManager visibilityManager = MiniGames.getInstance().getPlayerVisibilityManager(); + visibilityManager.toggleHidePlayers(playerRegistry, player); + if (MiniGames.getInstance().getPlayerVisibilityManager().isHidingPlayers(player)) { + setItem(0, getTogglePlayersItemEnabled()); + } else { + setItem(0, getTogglePlayersItemDisabled()); + } + }; } } diff --git a/src/main/java/net/knarcraft/minigames/gui/DropperGUI.java b/src/main/java/net/knarcraft/minigames/gui/DropperGUI.java index 78d0f12..a280166 100644 --- a/src/main/java/net/knarcraft/minigames/gui/DropperGUI.java +++ b/src/main/java/net/knarcraft/minigames/gui/DropperGUI.java @@ -1,6 +1,7 @@ package net.knarcraft.minigames.gui; import net.knarcraft.minigames.MiniGames; +import org.bukkit.entity.Player; /** * A GUI used in the dropper arena @@ -9,10 +10,16 @@ public class DropperGUI extends ArenaGUI { /** * Instantiates a new dropper gui + * + * @param player

The player the GUI is created for

*/ - public DropperGUI() { + public DropperGUI(Player player) { super(9, "Dropper", MiniGames.getInstance().getDropperArenaPlayerRegistry()); - setItem(0, getTogglePlayersItem()); + if (MiniGames.getInstance().getPlayerVisibilityManager().isHidingPlayers(player)) { + setItem(0, getTogglePlayersItemEnabled()); + } else { + setItem(0, getTogglePlayersItemDisabled()); + } setItem(2, getLeaveItem()); setAnyClickAction(0, getTogglePlayersAction()); diff --git a/src/main/java/net/knarcraft/minigames/gui/MiniGamesGUI.java b/src/main/java/net/knarcraft/minigames/gui/MiniGamesGUI.java new file mode 100644 index 0000000..7b8f34e --- /dev/null +++ b/src/main/java/net/knarcraft/minigames/gui/MiniGamesGUI.java @@ -0,0 +1,27 @@ +package net.knarcraft.minigames.gui; + +import net.knarcraft.minigames.MiniGames; +import org.bukkit.entity.Player; + +/** + * A GUI used outside arenas + */ +public class MiniGamesGUI extends ArenaGUI { + + /** + * Instantiates a new mini games gui + * + * @param player

The player the GUI is created for

+ */ + public MiniGamesGUI(Player player) { + super(9, "MiniGames", null); + if (MiniGames.getInstance().getPlayerVisibilityManager().isHidingPlayers(player)) { + setItem(0, getTogglePlayersItemEnabled()); + } else { + setItem(0, getTogglePlayersItemDisabled()); + } + + setAnyClickAction(0, getTogglePlayersAction()); + } + +} diff --git a/src/main/java/net/knarcraft/minigames/gui/ParkourGUI.java b/src/main/java/net/knarcraft/minigames/gui/ParkourGUI.java index 760ad97..ac6d4d0 100644 --- a/src/main/java/net/knarcraft/minigames/gui/ParkourGUI.java +++ b/src/main/java/net/knarcraft/minigames/gui/ParkourGUI.java @@ -7,6 +7,7 @@ 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; @@ -16,9 +17,18 @@ import java.util.List; */ public class ParkourGUI extends ArenaGUI { - public ParkourGUI() { + /** + * Instantiates a new parkour gui + * + * @param player

The player the GUI is created for

+ */ + public ParkourGUI(Player player) { super(9, "Parkour", MiniGames.getInstance().getParkourArenaPlayerRegistry()); - setItem(0, getTogglePlayersItem()); + if (MiniGames.getInstance().getPlayerVisibilityManager().isHidingPlayers(player)) { + setItem(0, getTogglePlayersItemEnabled()); + } else { + setItem(0, getTogglePlayersItemDisabled()); + } setItem(2, getGiveUpItem()); setItem(4, getLeaveItem());