Performs a lot of changes. Mostly implements #3

Properly and persistently stores which players have beaten which arenas
Adds a hopefully fully functional DropperArenaGroup class
Stores arena groups in the arena handler
Adds a lookup map to improve performance of getting arena by name
Adds saving and loading of groups
Adds all necessary checks for whether players have beaten the required dropper arenas before joining
Removes stage from arenas
Adds a test to make sure changing the order of arenas in a group works as intended
This commit is contained in:
2023-03-29 00:55:19 +02:00
parent 51237cb11a
commit 21425f73a1
12 changed files with 524 additions and 68 deletions

View File

@ -25,7 +25,7 @@ public class CreateArenaCommand implements CommandExecutor {
if (arguments.length < 1) {
return false;
}
DropperArena existingArena = Dropper.getInstance().getArenaHandler().getArena(arguments[0]);
if (existingArena != null) {
commandSender.sendMessage("There already exists a dropper arena with that name!");

View File

@ -2,6 +2,7 @@ package net.knarcraft.dropper.command;
import net.knarcraft.dropper.Dropper;
import net.knarcraft.dropper.arena.DropperArena;
import net.knarcraft.dropper.arena.DropperArenaGroup;
import net.knarcraft.dropper.arena.DropperArenaPlayerRegistry;
import net.knarcraft.dropper.arena.DropperArenaSession;
import net.knarcraft.dropper.property.ArenaGameMode;
@ -69,7 +70,17 @@ public class JoinArenaCommand implements CommandExecutor {
gameMode = ArenaGameMode.DEFAULT;
}
//TODO: Check if the arena has been beaten if the non-default game-mode has been chosen
// Make sure the player has beaten the necessary levels
DropperArenaGroup arenaGroup = Dropper.getInstance().getArenaHandler().getGroup(specifiedArena.getArenaId());
if (arenaGroup != null && !doGroupChecks(specifiedArena, arenaGroup, gameMode, player)) {
return false;
}
// Make sure the player has beaten the arena once before playing a challenge mode
if (gameMode != ArenaGameMode.DEFAULT && specifiedArena.getData().hasNotCompleted(player)) {
player.sendMessage("You must complete this arena in normal mode before starting a challenge!");
return false;
}
// Register the player's session
DropperArenaSession newSession = new DropperArenaSession(specifiedArena, player, gameMode);
@ -90,4 +101,30 @@ public class JoinArenaCommand implements CommandExecutor {
}
}
/**
* Performs necessary check for the given arena's group
*
* @param dropperArena <p>The arena the player is trying to join</p>
* @param arenaGroup <p>The arena group the arena belongs to</p>
* @param arenaGameMode <p>The game-mode the player selected</p>
* @param player <p>The the player trying to join the arena</p>
* @return <p>False if any checks failed</p>
*/
private boolean doGroupChecks(@NotNull DropperArena dropperArena, @NotNull DropperArenaGroup arenaGroup,
@NotNull ArenaGameMode arenaGameMode, @NotNull Player player) {
if (arenaGameMode == ArenaGameMode.DEFAULT) {
if (!arenaGroup.canPlay(player, dropperArena.getArenaId())) {
player.sendMessage("You have not yet beaten the previous arena!");
return false;
}
} else {
if (arenaGroup.hasBeatenAll(player)) {
player.sendMessage("You have not yet beaten all arenas in this group!");
return false;
}
}
return true;
}
}