mirror of
				https://github.com/SunNetservers/MiniGames.git
				synced 2025-11-04 03:33:47 +01:00 
			
		
		
		
	Implements checkpoints
This commit is contained in:
		@@ -44,13 +44,13 @@ 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> \[mode]            | Joins the selected arena.                                                           |
 | 
			
		||||
| /parkourJoin                           | /pjoin   | \<arena>                    | 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                           | /pedit   | \<arena> \<option> \[value] | Gets or sets a parkour arena option.                                                |
 | 
			
		||||
| /parkourGroupSet                       | /pgset   | \<arena> \<group>           | Puts the given arena in the given group. Use "none" to remove an existing group.    |
 | 
			
		||||
| /parkourGroupList                      | /pglist  | \[group]                    | Lists groups, or the stages of a group if a group is specified.                     |
 | 
			
		||||
| /parkourGroupSwap                      | /pgswap  | \<arena1> \<arena2>         | Swaps the two arenas in the group's ordered list.                                   |
 | 
			
		||||
| [/parkourGroupSwap](#droppergroupswap) | /pgswap  | \<arena1> \<arena2>         | Swaps the two arenas in the group's ordered list.                                   |
 | 
			
		||||
 | 
			
		||||
### Command explanation
 | 
			
		||||
 | 
			
		||||
@@ -154,7 +154,7 @@ You could use `/droppergroupswap Sea Savanna` to change the order to:
 | 
			
		||||
| mustDoGroupedInSequence           | true/false | true                                 | Whether grouped dropper arenas must be played in the correct sequence                                                                                                                                 |
 | 
			
		||||
| 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. |
 | 
			
		||||
| makePlayersInvisible              | true/false | false                                | Whether players should be made invisible while playing in a dropper arena                                                                                                                             |
 | 
			
		||||
| killPlaneBlocks                   | list       | [see this](#killplaneblocks-default) | The blocks compromising parkour arenas' kill planes. Add any materials you want to use for the "bottom" of your parkour arenas.                                                                       |
 | 
			
		||||
| 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:
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -11,6 +11,7 @@ import net.knarcraft.minigames.util.PlayerTeleporter;
 | 
			
		||||
import org.bukkit.Location;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
import org.jetbrains.annotations.NotNull;
 | 
			
		||||
import org.jetbrains.annotations.Nullable;
 | 
			
		||||
 | 
			
		||||
import java.util.logging.Level;
 | 
			
		||||
 | 
			
		||||
@@ -25,6 +26,7 @@ public class ParkourArenaSession implements ArenaSession {
 | 
			
		||||
    private int deaths;
 | 
			
		||||
    private final long startTime;
 | 
			
		||||
    private final PlayerEntryState entryState;
 | 
			
		||||
    private Location reachedCheckpoint = null;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Instantiates a new parkour arena session
 | 
			
		||||
@@ -62,6 +64,24 @@ public class ParkourArenaSession implements ArenaSession {
 | 
			
		||||
        return this.entryState;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Registers the checkpoint this session's player has reached
 | 
			
		||||
     *
 | 
			
		||||
     * @param location <p>The location of the checkpoint</p>
 | 
			
		||||
     */
 | 
			
		||||
    public void registerCheckpoint(@NotNull Location location) {
 | 
			
		||||
        this.reachedCheckpoint = location;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Gets the checkpoint currently registered as the player's spawn location
 | 
			
		||||
     *
 | 
			
		||||
     * @return <p>The registered checkpoint, or null if not set</p>
 | 
			
		||||
     */
 | 
			
		||||
    public @Nullable Location getRegisteredCheckpoint() {
 | 
			
		||||
        return this.reachedCheckpoint;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Triggers a win for the player playing in this session
 | 
			
		||||
     */
 | 
			
		||||
@@ -154,7 +174,8 @@ public class ParkourArenaSession implements ArenaSession {
 | 
			
		||||
    public void triggerLoss() {
 | 
			
		||||
        this.deaths++;
 | 
			
		||||
        //Teleport the player back to the top
 | 
			
		||||
        PlayerTeleporter.teleportPlayer(this.player, this.arena.getSpawnLocation(), true, false);
 | 
			
		||||
        Location spawnLocation = this.reachedCheckpoint != null ? this.reachedCheckpoint : this.arena.getSpawnLocation();
 | 
			
		||||
        PlayerTeleporter.teleportPlayer(this.player, spawnLocation, true, false);
 | 
			
		||||
        this.entryState.setArenaState();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -59,12 +59,22 @@ public class MoveListener implements Listener {
 | 
			
		||||
     * @param arenaSession <p>The dropper session of the player triggering the event</p>
 | 
			
		||||
     */
 | 
			
		||||
    private void doParkourArenaChecks(@NotNull PlayerMoveEvent event, ParkourArenaSession arenaSession) {
 | 
			
		||||
        if (event.getTo() == null) {
 | 
			
		||||
        // Ignore movement which won't cause the player's block to change
 | 
			
		||||
        if (event.getTo() == null || event.getFrom().getBlock() == event.getTo().getBlock()) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        // Only do block type checking if the block beneath the player changes
 | 
			
		||||
        if (event.getFrom().getBlock() != event.getTo().getBlock()) {
 | 
			
		||||
            checkForSpecialBlock(arenaSession, event.getTo());
 | 
			
		||||
        if (checkForSpecialBlock(arenaSession, event.getTo())) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Check if the player reached one of the checkpoints for the arena
 | 
			
		||||
        for (Location checkpoint : arenaSession.getArena().getCheckpoints()) {
 | 
			
		||||
            if (checkpoint.getBlock().equals(event.getTo().getBlock())) {
 | 
			
		||||
                arenaSession.registerCheckpoint(checkpoint.clone());
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,9 @@ package net.knarcraft.minigames.listener;
 | 
			
		||||
 | 
			
		||||
import net.knarcraft.minigames.MiniGames;
 | 
			
		||||
import net.knarcraft.minigames.arena.ArenaSession;
 | 
			
		||||
import net.knarcraft.minigames.arena.parkour.ParkourArenaSession;
 | 
			
		||||
import org.bukkit.Bukkit;
 | 
			
		||||
import org.bukkit.Location;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
import org.bukkit.event.EventHandler;
 | 
			
		||||
import org.bukkit.event.Listener;
 | 
			
		||||
@@ -52,7 +54,8 @@ public class PlayerLeaveListener implements Listener {
 | 
			
		||||
 | 
			
		||||
    @EventHandler
 | 
			
		||||
    public void onPlayerTeleport(PlayerTeleportEvent event) {
 | 
			
		||||
        if (event.getTo() == null || event.isCancelled()) {
 | 
			
		||||
        Location targetLocation = event.getTo();
 | 
			
		||||
        if (targetLocation == null || event.isCancelled()) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -61,7 +64,12 @@ public class PlayerLeaveListener implements Listener {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (event.getTo().equals(arenaSession.getArena().getSpawnLocation())) {
 | 
			
		||||
        if (targetLocation.equals(arenaSession.getArena().getSpawnLocation())) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (arenaSession instanceof ParkourArenaSession parkourArenaSession &&
 | 
			
		||||
                targetLocation.equals(parkourArenaSession.getRegisteredCheckpoint())) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user