mirror of
https://github.com/SunNetservers/MiniGames.git
synced 2025-06-25 02:34:44 +02:00
Adds a hardcore game-mode ignoring checkpoints
This commit is contained in:
@ -16,6 +16,11 @@ public enum ParkourArenaGameMode implements ConfigurationSerializable, ArenaGame
|
||||
* The default game-mode. Failing once throws the player out.
|
||||
*/
|
||||
DEFAULT,
|
||||
|
||||
/**
|
||||
* A hard-core game mode where no checkpoints are allowed
|
||||
*/
|
||||
HARDCORE,
|
||||
;
|
||||
|
||||
/**
|
||||
|
@ -43,6 +43,15 @@ public class ParkourArenaSession extends AbstractArenaSession {
|
||||
this.entryState.setArenaState();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the game-mode the player is playing in this session
|
||||
*
|
||||
* @return <p>The game-mode for this session</p>
|
||||
*/
|
||||
public @NotNull ParkourArenaGameMode getGameMode() {
|
||||
return this.gameMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the checkpoint this session's player has reached
|
||||
*
|
||||
@ -118,6 +127,7 @@ public class ParkourArenaSession extends AbstractArenaSession {
|
||||
protected String getGameModeString() {
|
||||
return switch (this.gameMode) {
|
||||
case DEFAULT -> "default";
|
||||
case HARDCORE -> "hardcore";
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ import net.knarcraft.minigames.arena.ArenaSession;
|
||||
import net.knarcraft.minigames.arena.dropper.DropperArenaGameMode;
|
||||
import net.knarcraft.minigames.arena.dropper.DropperArenaSession;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArena;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArenaGameMode;
|
||||
import net.knarcraft.minigames.arena.parkour.ParkourArenaSession;
|
||||
import net.knarcraft.minigames.config.DropperConfiguration;
|
||||
import net.knarcraft.minigames.config.Message;
|
||||
@ -76,14 +77,30 @@ public class MoveListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
// Skip checkpoint registration if playing on hardcore
|
||||
if (arenaSession.getGameMode() == ParkourArenaGameMode.HARDCORE) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if the player reached one of the checkpoints for the arena
|
||||
updateCheckpoint(arenaSession, event.getTo().getBlock(), event.getPlayer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the checkpoint of a player if reached
|
||||
*
|
||||
* @param arenaSession <p>The session of the player</p>
|
||||
* @param targetBlock <p>The block the player is moving to</p>
|
||||
* @param player <p>The player moving</p>
|
||||
*/
|
||||
private void updateCheckpoint(ParkourArenaSession arenaSession, Block targetBlock, Player player) {
|
||||
ParkourArena arena = arenaSession.getArena();
|
||||
List<Location> checkpoints = arena.getCheckpoints();
|
||||
for (Location checkpoint : checkpoints) {
|
||||
Location previousCheckpoint = arenaSession.getRegisteredCheckpoint();
|
||||
|
||||
// Skip if checkpoint has not been reached
|
||||
if (!checkpoint.getBlock().equals(event.getTo().getBlock())) {
|
||||
if (!checkpoint.getBlock().equals(targetBlock)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -103,7 +120,7 @@ public class MoveListener implements Listener {
|
||||
|
||||
// Register the checkpoint
|
||||
arenaSession.registerCheckpoint(checkpoint.clone());
|
||||
event.getPlayer().sendMessage(Message.SUCCESS_CHECKPOINT_REACHED.getMessage());
|
||||
player.sendMessage(Message.SUCCESS_CHECKPOINT_REACHED.getMessage());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -122,7 +122,9 @@ commands:
|
||||
- pjoin
|
||||
permission: minigames.join
|
||||
usage: |
|
||||
/<command> <arena>
|
||||
/<command> <arena> [mode]
|
||||
- Mode can be used to select challenge modes which can be played after beating the arena.
|
||||
- hardcore = A game-mode where checkpoints cannot be triggered
|
||||
description: Used to join a parkour arena
|
||||
parkourCreate:
|
||||
aliases:
|
||||
|
Reference in New Issue
Block a user