From 0704e138ecc6ec7c5d4ffab6a53d9ab33e8d7280 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Mon, 8 May 2023 18:14:37 +0200 Subject: [PATCH] Adds a command for returning to checkpoint by forcing a loss #28 --- README.md | 1 + .../net/knarcraft/minigames/MiniGames.java | 2 + .../parkour/ParkourCheckpointCommand.java | 44 +++++++++++++++++++ .../minigames/listener/CommandListener.java | 3 ++ src/main/resources/plugin.yml | 38 +++++++++------- 5 files changed, 72 insertions(+), 16 deletions(-) create mode 100644 src/main/java/net/knarcraft/minigames/command/parkour/ParkourCheckpointCommand.java diff --git a/README.md b/README.md index 8817a2e..bc4a93b 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ The only permission normal players will need is `minigames.join` which is set to | /parkourGroupSet | /pgset | \ \ | 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](#droppergroupswap) | /pgswap | \ \ | Swaps the two arenas in the group's ordered list. | +| /parkourCheckpoint | /pcheck | | Triggers a teleportation to your previous checkpoint. | ### Command explanation dropper diff --git a/src/main/java/net/knarcraft/minigames/MiniGames.java b/src/main/java/net/knarcraft/minigames/MiniGames.java index c6ca215..4a8e36e 100644 --- a/src/main/java/net/knarcraft/minigames/MiniGames.java +++ b/src/main/java/net/knarcraft/minigames/MiniGames.java @@ -39,6 +39,7 @@ import net.knarcraft.minigames.command.parkour.EditParkourArenaTabCompleter; import net.knarcraft.minigames.command.parkour.JoinParkourArenaCommand; import net.knarcraft.minigames.command.parkour.JoinParkourArenaTabCompleter; import net.knarcraft.minigames.command.parkour.ListParkourArenaCommand; +import net.knarcraft.minigames.command.parkour.ParkourCheckpointCommand; import net.knarcraft.minigames.command.parkour.ParkourGroupListCommand; import net.knarcraft.minigames.command.parkour.ParkourGroupSetCommand; import net.knarcraft.minigames.command.parkour.ParkourGroupSwapCommand; @@ -267,6 +268,7 @@ public final class MiniGames extends JavaPlugin { registerCommand("parkourGroupSet", new ParkourGroupSetCommand(), null); registerCommand("parkourGroupSwap", new ParkourGroupSwapCommand(), null); registerCommand("parkourGroupList", new ParkourGroupListCommand(), null); + registerCommand("parkourCheckpoint", new ParkourCheckpointCommand(), null); if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) { this.dropperRecordExpansion = new DropperRecordExpansion(this); diff --git a/src/main/java/net/knarcraft/minigames/command/parkour/ParkourCheckpointCommand.java b/src/main/java/net/knarcraft/minigames/command/parkour/ParkourCheckpointCommand.java new file mode 100644 index 0000000..335fb02 --- /dev/null +++ b/src/main/java/net/knarcraft/minigames/command/parkour/ParkourCheckpointCommand.java @@ -0,0 +1,44 @@ +package net.knarcraft.minigames.command.parkour; + +import net.knarcraft.minigames.MiniGames; +import net.knarcraft.minigames.arena.ArenaSession; +import net.knarcraft.minigames.arena.parkour.ParkourArenaSession; +import net.knarcraft.minigames.config.Message; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.List; + +/** + * The command for returning to the previous checkpoint + */ +public class ParkourCheckpointCommand implements TabExecutor { + + @Override + public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, + @NotNull String[] strings) { + if (!(commandSender instanceof Player player)) { + commandSender.sendMessage(Message.ERROR_PLAYER_ONLY.getMessage()); + return false; + } + + ArenaSession session = MiniGames.getInstance().getSession(player.getUniqueId()); + if (session instanceof ParkourArenaSession) { + session.triggerLoss(); + } + return true; + } + + @Nullable + @Override + public List onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, + @NotNull String[] strings) { + return new ArrayList<>(); + } + +} diff --git a/src/main/java/net/knarcraft/minigames/listener/CommandListener.java b/src/main/java/net/knarcraft/minigames/listener/CommandListener.java index 112231d..44b0eed 100644 --- a/src/main/java/net/knarcraft/minigames/listener/CommandListener.java +++ b/src/main/java/net/knarcraft/minigames/listener/CommandListener.java @@ -29,6 +29,9 @@ public class CommandListener implements Listener { allowedCommands.add("/mLeave"); allowedCommands.add("/dLeave"); allowedCommands.add("/pLeave"); + allowedCommands.add("/parkourCheckpoint"); + allowedCommands.add("/pCheckpoint"); + allowedCommands.add("/pCheck"); String message = event.getMessage(); if (!message.startsWith("/")) { diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 8fbd03b..ed35ed8 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -20,13 +20,12 @@ commands: - mleave - dleave - pleave - permission: minigames.join usage: / description: Used to leave the current dropper arena dropperGroupSet: aliases: - dgset - permission: minigames.edit + permission: minigames.edit.dropper usage: | / - The group will be created if it doesn't already exist @@ -35,7 +34,7 @@ commands: dropperGroupSwap: aliases: - dgswap - permission: minigames.edit + permission: minigames.edit.dropper usage: | / - The two arenas must be in the same group @@ -43,7 +42,7 @@ commands: dropperGroupList: aliases: - dglist - permission: minigames.edit + permission: minigames.edit.dropper usage: | / [group] - Existing groups will be listed if used without an argument @@ -52,13 +51,13 @@ commands: dropperList: aliases: - dlist - permission: minigames.join + permission: minigames.join.dropper usage: / description: Used to list all current dropper arenas dropperJoin: aliases: - djoin - permission: minigames.join + permission: minigames.join.dropper usage: | / [mode] - Mode can be used to select challenge modes which can be played after beating the arena. @@ -68,7 +67,7 @@ commands: dropperCreate: aliases: - dcreate - permission: minigames.create + permission: minigames.create.dropper usage: | / [new value] - Valid properties: name, spawnLocation, exitLocation, verticalVelocity, horizontalVelocity, winBlockType @@ -76,13 +75,13 @@ commands: dropperEdit: aliases: - dedit - permission: minigames.edit + permission: minigames.edit.dropper usage: / (Details not finalized) description: Used to edit an existing dropper arena dropperRemove: aliases: - dremove - permission: minigames.remove + permission: minigames.remove.dropper usage: / description: Used to remove an existing dropper arena parkourGroupSet: @@ -97,7 +96,7 @@ commands: parkourGroupSwap: aliases: - pgswap - permission: minigames.edit + permission: minigames.edit.parkour usage: | / - The two arenas must be in the same group @@ -105,7 +104,7 @@ commands: parkourGroupList: aliases: - pglist - permission: minigames.edit + permission: minigames.edit.parkour usage: | / [group] - Existing groups will be listed if used without an argument @@ -114,13 +113,13 @@ commands: parkourList: aliases: - plist - permission: minigames.join + permission: minigames.join.parkour usage: / description: Used to list all current parkour arenas parkourJoin: aliases: - pjoin - permission: minigames.join + permission: minigames.join.parkour usage: | / [mode] - Mode can be used to select challenge modes which can be played after beating the arena. @@ -129,7 +128,7 @@ commands: parkourCreate: aliases: - pcreate - permission: minigames.create + permission: minigames.create.parkour usage: | / [new value] - Valid properties: name, spawnLocation, exitLocation, winBlockType, winLocation, checkpointAdd, checkpointClear, killPlaneBlocks @@ -137,15 +136,22 @@ commands: parkourEdit: aliases: - pedit - permission: minigames.edit + permission: minigames.edit.parkour usage: / (Details not finalized) description: Used to edit an existing parkour arena parkourRemove: aliases: - dremove - permission: minigames.remove + permission: minigames.remove.parkour usage: / description: Used to remove an existing parkour arena + parkourCheckpoint: + aliases: + - pcheckpoint + - pcheck + permission: minigames.join.parkour + usage: / + description: Used to teleport to the previous checkpoint while in a parkour arena permissions: minigames.*: description: Gives all permissions