mirror of
https://github.com/SunNetservers/MiniGames.git
synced 2024-12-04 16:33:14 +01:00
Makes some GUI changes
Makes the current state of the player toggle visible. Makes it possible to toggle player visibility outside arenas.
This commit is contained in:
parent
7848a0a028
commit
d6fb9ab0b9
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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 <p>The player to check</p>
|
||||
* @return <p>True if currently hiding other players</p>
|
||||
*/
|
||||
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 <p>The player to change the visibility for</p>
|
||||
* @param hide <p>Whether to hide the players or show the players</p>
|
||||
*/
|
||||
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) {
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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 <p>A player toggle item</p>
|
||||
*/
|
||||
protected ItemStack getTogglePlayersItem() {
|
||||
protected ItemStack getTogglePlayersItemDisabled() {
|
||||
GUIItemFactory togglePlayersItemFactory = new GUIItemFactory(Material.PLAYER_HEAD);
|
||||
List<String> 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 <p>A player toggle item</p>
|
||||
*/
|
||||
protected ItemStack getTogglePlayersItemEnabled() {
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets an item describing a leave arena action
|
||||
*
|
||||
@ -104,8 +123,15 @@ public abstract class ArenaGUI extends AbstractGUI {
|
||||
* @return <p>The action for triggering player visibility</p>
|
||||
*/
|
||||
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());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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 <p>The player the GUI is created for</p>
|
||||
*/
|
||||
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());
|
||||
|
27
src/main/java/net/knarcraft/minigames/gui/MiniGamesGUI.java
Normal file
27
src/main/java/net/knarcraft/minigames/gui/MiniGamesGUI.java
Normal file
@ -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 <p>The player the GUI is created for</p>
|
||||
*/
|
||||
public MiniGamesGUI(Player player) {
|
||||
super(9, "MiniGames", null);
|
||||
if (MiniGames.getInstance().getPlayerVisibilityManager().isHidingPlayers(player)) {
|
||||
setItem(0, getTogglePlayersItemEnabled());
|
||||
} else {
|
||||
setItem(0, getTogglePlayersItemDisabled());
|
||||
}
|
||||
|
||||
setAnyClickAction(0, getTogglePlayersAction());
|
||||
}
|
||||
|
||||
}
|
@ -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 <p>The player the GUI is created for</p>
|
||||
*/
|
||||
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());
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user