Implements #27 among other things

It was found that the Spigot API's methods for cancelling player collisions won't work without changing the scoreboard. Because of that, the normal option has been disabled. The invisibility option has also been removed, as that's a bad idea if players can still push each-other.
The toggle player option which is implemented in this commit does disable player collision, so that's the only working way right now.

A potential ConcurrentModificationException has been fixed.
The parkourCheckpoint command has been removed, as the functionality is now available through the API.
This commit is contained in:
2023-05-10 15:14:28 +02:00
parent 00ac0582f4
commit 7848a0a028
23 changed files with 193 additions and 194 deletions

View File

@ -4,6 +4,7 @@ import net.knarcraft.knargui.AbstractGUI;
import net.knarcraft.knargui.GUIAction;
import net.knarcraft.knargui.item.GUIItemFactory;
import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.ArenaPlayerRegistry;
import net.knarcraft.minigames.arena.ArenaSession;
import net.md_5.bungee.api.ChatColor;
import org.bukkit.Material;
@ -18,14 +19,18 @@ import java.util.List;
*/
public abstract class ArenaGUI extends AbstractGUI {
protected final ArenaPlayerRegistry<?> playerRegistry;
/**
* Instantiates a new arena gui
*
* @param inventorySize <p>The size of the GUI's inventory</p>
* @param inventoryName <p>The name of the inventory</p>
* @param inventorySize <p>The size of the GUI's inventory</p>
* @param inventoryName <p>The name of the inventory</p>
* @param playerRegistry <p>The player registry used for this GUI</p>
*/
public ArenaGUI(int inventorySize, String inventoryName) {
public ArenaGUI(int inventorySize, String inventoryName, ArenaPlayerRegistry<?> playerRegistry) {
super(inventorySize, inventoryName, null);
this.playerRegistry = playerRegistry;
}
/**
@ -88,9 +93,19 @@ public abstract class ArenaGUI extends AbstractGUI {
return (player) -> {
ArenaSession session = MiniGames.getInstance().getSession(player.getUniqueId());
if (session != null) {
session.triggerQuit(false);
session.triggerQuit(false, true);
}
};
}
/**
* Gets the action to run when triggering the toggle players action
*
* @return <p>The action for triggering player visibility</p>
*/
protected GUIAction getTogglePlayersAction() {
return (player) -> MiniGames.getInstance().getPlayerVisibilityManager().toggleHidePlayers(playerRegistry,
player);
}
}

View File

@ -1,5 +1,7 @@
package net.knarcraft.minigames.gui;
import net.knarcraft.minigames.MiniGames;
/**
* A GUI used in the dropper arena
*/
@ -9,10 +11,11 @@ public class DropperGUI extends ArenaGUI {
* Instantiates a new dropper gui
*/
public DropperGUI() {
super(9, "Dropper");
super(9, "Dropper", MiniGames.getInstance().getDropperArenaPlayerRegistry());
setItem(0, getTogglePlayersItem());
setItem(2, getLeaveItem());
setAnyClickAction(0, getTogglePlayersAction());
setAnyClickAction(2, getLeaveAction());
}

View File

@ -17,11 +17,12 @@ import java.util.List;
public class ParkourGUI extends ArenaGUI {
public ParkourGUI() {
super(9, "Parkour");
super(9, "Parkour", MiniGames.getInstance().getParkourArenaPlayerRegistry());
setItem(0, getTogglePlayersItem());
setItem(2, getGiveUpItem());
setItem(4, getLeaveItem());
setAnyClickAction(0, getTogglePlayersAction());
setAnyClickAction(2, getGiveUpAction());
setAnyClickAction(4, getLeaveAction());
}
@ -32,7 +33,7 @@ public class ParkourGUI extends ArenaGUI {
* @return <p>A give up item</p>
*/
private ItemStack getGiveUpItem() {
GUIItemFactory giveUpItemFactory = new GUIItemFactory(Material.SKELETON_SKULL);
GUIItemFactory giveUpItemFactory = new GUIItemFactory(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");