Adds a hardcore game-mode ignoring checkpoints

This commit is contained in:
Kristian Knarvik 2023-04-28 15:05:36 +02:00
parent 701cdd81eb
commit e039840e89
5 changed files with 49 additions and 4 deletions

View File

@ -50,7 +50,7 @@ The only permission normal players will need is `minigames.join` which is set to
| /dropperGroupList | /dglist | \[group] | Lists groups, or the stages of a group if a group is specified. |
| [/dropperGroupSwap](#droppergroupswap) | /dgswap | \<arena1> \<arena2> | Swaps the two arenas in the group's ordered list. |
| /parkourList | /plist | | Lists available parkour arenas. |
| /parkourJoin | /pjoin | \<arena> | Joins the selected arena. |
| [/parkourJoin](#parkourjoin) | /pjoin | \<arena> \[mode] | Joins the selected arena. |
| /parkourCreate | /pcreate | \<name> | Creates a new parkour arena with the given name. The spawn is set to your location. |
| /parkourRemove | /premove | \<arena> | Removes the specified parkour arena. |
| [/parkourEdit](#parkouredit) | /pedit | \<arena> \<option> \[value] | Gets or sets a parkour arena option. |
@ -128,6 +128,17 @@ You could use `/droppergroupswap Sea Savanna` to change the order to:
### Command explanation parkour
#### /parkourJoin
This command is used for joining a dropper arena.
`/parkourjoin <arena> [mode]`
| Argument | Usage |
|----------|-----------------------------------------------------------------------------------------------------------|
| arena | The name of the arena to join. |
| mode | Additional challenge modes can be played after an arena has been cleared once. Available modes: hardcore. |
#### /parkourEdit
This command allows editing the specified property for the specified parkour arena.

View File

@ -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,
;
/**

View File

@ -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";
};
}

View File

@ -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;
}
}

View File

@ -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: