mirror of
https://github.com/SunNetservers/MiniGames.git
synced 2024-12-05 00:43:15 +01:00
Adds an option to enforce ordered checkpoint triggering
This commit is contained in:
parent
b0a72561f9
commit
a84e164edf
13
README.md
13
README.md
@ -149,12 +149,13 @@ You could use `/droppergroupswap Sea Savanna` to change the order to:
|
|||||||
|
|
||||||
### Parkour
|
### Parkour
|
||||||
|
|
||||||
| Name | Type | Default | Description |
|
| Name | Type | Default | Description |
|
||||||
|-----------------------------------|------------|--------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|-----------------------------------|------------|--------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
| mustDoGroupedInSequence | true/false | true | Whether grouped dropper arenas must be played in the correct sequence |
|
| enforceCheckpointOrder | true/false | false | Whether to enforce the order in which a player must reach checkpoints. Enabling this ensures that a player cannot trigger a previous checkpoint by accident. It also ensures players cannot skip a checkpoint, even if the arena layout makes it possible. |
|
||||||
| ignoreRecordsUntilGroupBeatenOnce | true/false | false | Whether records won't be registered unless the player has already beaten all arenas in a group. That means players are required to do a second play-through to register a record for a grouped arena. |
|
| mustDoGroupedInSequence | true/false | true | Whether grouped dropper arenas must be played in the correct sequence |
|
||||||
| makePlayersInvisible | true/false | false | Whether players should be made invisible while playing in a dropper arena |
|
| ignoreRecordsUntilGroupBeatenOnce | true/false | false | Whether records won't be registered unless the player has already beaten all arenas in a group. That means players are required to do a second play-through to register a record for a grouped arena. |
|
||||||
| killPlaneBlocks | list | [see this](#killplaneblocks-default) | The types of blocks compromising parkour arenas' kill planes. Add any materials you want to use for the "bottom" of your parkour arenas. +WOOL and other block tags are supported. |
|
| makePlayersInvisible | true/false | false | Whether players should be made invisible while playing in a dropper arena |
|
||||||
|
| killPlaneBlocks | list | [see this](#killplaneblocks-default) | The types of blocks compromising parkour arenas' kill planes. Add any materials you want to use for the "bottom" of your parkour arenas. +WOOL and other block tags are supported. |
|
||||||
|
|
||||||
#### blockWhitelist default:
|
#### blockWhitelist default:
|
||||||
|
|
||||||
|
@ -238,7 +238,7 @@ public final class MiniGames extends JavaPlugin {
|
|||||||
|
|
||||||
PluginManager pluginManager = getServer().getPluginManager();
|
PluginManager pluginManager = getServer().getPluginManager();
|
||||||
pluginManager.registerEvents(new DamageListener(), this);
|
pluginManager.registerEvents(new DamageListener(), this);
|
||||||
pluginManager.registerEvents(new MoveListener(this.dropperConfiguration), this);
|
pluginManager.registerEvents(new MoveListener(this.dropperConfiguration, this.parkourConfiguration), this);
|
||||||
pluginManager.registerEvents(new PlayerLeaveListener(), this);
|
pluginManager.registerEvents(new PlayerLeaveListener(), this);
|
||||||
pluginManager.registerEvents(new CommandListener(), this);
|
pluginManager.registerEvents(new CommandListener(), this);
|
||||||
|
|
||||||
|
@ -393,6 +393,10 @@ public class ParkourArena implements Arena {
|
|||||||
* @return <p>True if successfully cleared</p>
|
* @return <p>True if successfully cleared</p>
|
||||||
*/
|
*/
|
||||||
public boolean clearCheckpoints() {
|
public boolean clearCheckpoints() {
|
||||||
|
if (checkpoints.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
this.checkpoints.clear();
|
this.checkpoints.clear();
|
||||||
this.parkourArenaHandler.saveArenas();
|
this.parkourArenaHandler.saveArenas();
|
||||||
return true;
|
return true;
|
||||||
|
@ -13,6 +13,7 @@ public class ParkourConfiguration extends MiniGameConfiguration {
|
|||||||
|
|
||||||
private final static String rootNode = "parkour.";
|
private final static String rootNode = "parkour.";
|
||||||
|
|
||||||
|
private boolean enforceCheckpointOrder;
|
||||||
private boolean mustDoGroupedInSequence;
|
private boolean mustDoGroupedInSequence;
|
||||||
private boolean ignoreRecordsUntilGroupBeatenOnce;
|
private boolean ignoreRecordsUntilGroupBeatenOnce;
|
||||||
private boolean makePlayersInvisible;
|
private boolean makePlayersInvisible;
|
||||||
@ -27,6 +28,15 @@ public class ParkourConfiguration extends MiniGameConfiguration {
|
|||||||
super(configuration);
|
super(configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets whether all checkpoints must be triggered in the order they are set when configuring the parkour arena
|
||||||
|
*
|
||||||
|
* @return <p>Whether checkpoints must be triggered in order</p>
|
||||||
|
*/
|
||||||
|
public boolean enforceCheckpointOrder() {
|
||||||
|
return this.enforceCheckpointOrder;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets whether grouped arenas must be done in the set sequence
|
* Gets whether grouped arenas must be done in the set sequence
|
||||||
*
|
*
|
||||||
@ -65,6 +75,7 @@ public class ParkourConfiguration extends MiniGameConfiguration {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void load() {
|
protected void load() {
|
||||||
|
this.enforceCheckpointOrder = configuration.getBoolean(rootNode + "enforceCheckpointOrder", false);
|
||||||
this.mustDoGroupedInSequence = configuration.getBoolean(rootNode + "mustDoGroupedInSequence", true);
|
this.mustDoGroupedInSequence = configuration.getBoolean(rootNode + "mustDoGroupedInSequence", true);
|
||||||
this.ignoreRecordsUntilGroupBeatenOnce = configuration.getBoolean(rootNode + "ignoreRecordsUntilGroupBeatenOnce", false);
|
this.ignoreRecordsUntilGroupBeatenOnce = configuration.getBoolean(rootNode + "ignoreRecordsUntilGroupBeatenOnce", false);
|
||||||
this.makePlayersInvisible = configuration.getBoolean(rootNode + "makePlayersInvisible", false);
|
this.makePlayersInvisible = configuration.getBoolean(rootNode + "makePlayersInvisible", false);
|
||||||
|
@ -26,6 +26,8 @@ public class CommandListener implements Listener {
|
|||||||
List<String> allowedCommands = new ArrayList<>();
|
List<String> allowedCommands = new ArrayList<>();
|
||||||
allowedCommands.add("/miniGamesLeave");
|
allowedCommands.add("/miniGamesLeave");
|
||||||
allowedCommands.add("/mLeave");
|
allowedCommands.add("/mLeave");
|
||||||
|
allowedCommands.add("/dLeave");
|
||||||
|
allowedCommands.add("/pLeave");
|
||||||
|
|
||||||
String message = event.getMessage();
|
String message = event.getMessage();
|
||||||
if (!message.startsWith("/")) {
|
if (!message.startsWith("/")) {
|
||||||
|
@ -5,8 +5,10 @@ import net.knarcraft.minigames.arena.Arena;
|
|||||||
import net.knarcraft.minigames.arena.ArenaSession;
|
import net.knarcraft.minigames.arena.ArenaSession;
|
||||||
import net.knarcraft.minigames.arena.dropper.DropperArenaGameMode;
|
import net.knarcraft.minigames.arena.dropper.DropperArenaGameMode;
|
||||||
import net.knarcraft.minigames.arena.dropper.DropperArenaSession;
|
import net.knarcraft.minigames.arena.dropper.DropperArenaSession;
|
||||||
|
import net.knarcraft.minigames.arena.parkour.ParkourArena;
|
||||||
import net.knarcraft.minigames.arena.parkour.ParkourArenaSession;
|
import net.knarcraft.minigames.arena.parkour.ParkourArenaSession;
|
||||||
import net.knarcraft.minigames.config.DropperConfiguration;
|
import net.knarcraft.minigames.config.DropperConfiguration;
|
||||||
|
import net.knarcraft.minigames.config.ParkourConfiguration;
|
||||||
import net.knarcraft.minigames.config.SharedConfiguration;
|
import net.knarcraft.minigames.config.SharedConfiguration;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
@ -19,6 +21,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -26,15 +29,18 @@ import java.util.Set;
|
|||||||
*/
|
*/
|
||||||
public class MoveListener implements Listener {
|
public class MoveListener implements Listener {
|
||||||
|
|
||||||
private final DropperConfiguration configuration;
|
private final DropperConfiguration dropperConfiguration;
|
||||||
|
private final ParkourConfiguration parkourConfiguration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new move listener
|
* Instantiates a new move listener
|
||||||
*
|
*
|
||||||
* @param configuration <p>The configuration to use</p>
|
* @param dropperConfiguration <p>The dropper configuration to use</p>
|
||||||
|
* @param parkourConfiguration <p>The parkour configuration to use</p>
|
||||||
*/
|
*/
|
||||||
public MoveListener(DropperConfiguration configuration) {
|
public MoveListener(DropperConfiguration dropperConfiguration, ParkourConfiguration parkourConfiguration) {
|
||||||
this.configuration = configuration;
|
this.dropperConfiguration = dropperConfiguration;
|
||||||
|
this.parkourConfiguration = parkourConfiguration;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@ -70,9 +76,19 @@ public class MoveListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if the player reached one of the checkpoints for the arena
|
// Check if the player reached one of the checkpoints for the arena
|
||||||
for (Location checkpoint : arenaSession.getArena().getCheckpoints()) {
|
ParkourArena arena = arenaSession.getArena();
|
||||||
if (checkpoint.getBlock().equals(event.getTo().getBlock()) &&
|
List<Location> checkpoints = arena.getCheckpoints();
|
||||||
!checkpoint.equals(arenaSession.getRegisteredCheckpoint())) {
|
for (Location checkpoint : checkpoints) {
|
||||||
|
Location previousCheckpoint = arenaSession.getRegisteredCheckpoint();
|
||||||
|
if (checkpoint.getBlock().equals(event.getTo().getBlock()) && !checkpoint.equals(previousCheckpoint)) {
|
||||||
|
if (parkourConfiguration.enforceCheckpointOrder()) {
|
||||||
|
int checkpointIndex = checkpoints.indexOf(checkpoint);
|
||||||
|
int previousIndex = previousCheckpoint == null ? -1 : checkpoints.indexOf(previousCheckpoint);
|
||||||
|
if (checkpointIndex - previousIndex != 1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
arenaSession.registerCheckpoint(checkpoint.clone());
|
arenaSession.registerCheckpoint(checkpoint.clone());
|
||||||
event.getPlayer().sendMessage("Checkpoint reached!");
|
event.getPlayer().sendMessage("Checkpoint reached!");
|
||||||
return;
|
return;
|
||||||
@ -92,8 +108,8 @@ public class MoveListener implements Listener {
|
|||||||
}
|
}
|
||||||
// Prevent the player from flying upwards while in flight mode
|
// Prevent the player from flying upwards while in flight mode
|
||||||
if (event.getFrom().getY() < event.getTo().getY() ||
|
if (event.getFrom().getY() < event.getTo().getY() ||
|
||||||
(configuration.blockSneaking() && event.getPlayer().isSneaking()) ||
|
(dropperConfiguration.blockSneaking() && event.getPlayer().isSneaking()) ||
|
||||||
(configuration.blockSprinting() && event.getPlayer().isSprinting())) {
|
(dropperConfiguration.blockSprinting() && event.getPlayer().isSprinting())) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -189,7 +205,7 @@ public class MoveListener implements Listener {
|
|||||||
}
|
}
|
||||||
Player player = session.getPlayer();
|
Player player = session.getPlayer();
|
||||||
float horizontalVelocity = session.getArena().getPlayerHorizontalVelocity();
|
float horizontalVelocity = session.getArena().getPlayerHorizontalVelocity();
|
||||||
float secondsBetweenToggle = configuration.getRandomlyInvertedTimer();
|
float secondsBetweenToggle = dropperConfiguration.getRandomlyInvertedTimer();
|
||||||
int seconds = Calendar.getInstance().get(Calendar.SECOND);
|
int seconds = Calendar.getInstance().get(Calendar.SECOND);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
# Configuration values for mini-games
|
# Configuration values for mini-games
|
||||||
parkour:
|
parkour:
|
||||||
|
# Whether to enforce the order in which a player must reach checkpoints. Enabling this ensures that a player cannot
|
||||||
|
# trigger a previous checkpoint by accident. It also ensures players cannot skip a checkpoint, even if the arena
|
||||||
|
# layout makes it possible.
|
||||||
|
enforceCheckpointOrder: false
|
||||||
|
|
||||||
# Whether grouped dropper arenas must be played in the correct sequence
|
# Whether grouped dropper arenas must be played in the correct sequence
|
||||||
mustDoGroupedInSequence: true
|
mustDoGroupedInSequence: true
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user