> implements TabExecutor {
+
+ /**
+ * Displays all currently existing dropper arena groups
+ *
+ * @param arenaHandler The arena handler to get groups from
+ * @param sender The command sender to display the groups to
+ */
+ protected void displayExistingGroups(@NotNull K arenaHandler, @NotNull CommandSender sender) {
+ StringFormatter stringFormatter = MiniGames.getInstance().getStringFormatter();
+ StringBuilder builder = new StringBuilder(stringFormatter.getUnformattedMessage(
+ MiniGameMessage.SUCCESS_GROUPS)).append("\n");
+ arenaHandler.getAllGroups().stream().sorted().forEachOrdered((group) ->
+ builder.append("- ").append(group.getGroupName()).append("\n"));
+ stringFormatter.displaySuccessMessage(sender, builder.toString());
+ }
+
+ /**
+ * Displays the ordered stages in a specified group to the specified command sender
+ *
+ * @param arenaHandler The arena handler to get groups from
+ * @param sender The command sender to display the stages to
+ * @param groupName The name of the group to display stages for
+ * @return True if the stages were successfully displayed
+ */
+ protected boolean displayOrderedArenaNames(@NotNull K arenaHandler, @NotNull CommandSender sender,
+ @NotNull String groupName) {
+ StringFormatter stringFormatter = MiniGames.getInstance().getStringFormatter();
+ M arenaGroup = arenaHandler.getGroup(groupName);
+ if (arenaGroup == null) {
+ stringFormatter.displayErrorMessage(sender, MiniGameMessage.ERROR_GROUP_NOT_FOUND);
+ return false;
+ }
+
+ // Send a list of all stages (arenas in the group)
+ StringBuilder builder = new StringBuilder(stringFormatter.replacePlaceholder(
+ MiniGameMessage.SUCCESS_GROUP_STAGES, "{group}", groupName));
+ int counter = 1;
+ for (UUID arenaId : arenaGroup.getArenas()) {
+ L arena = arenaHandler.getArena(arenaId);
+ if (arena != null) {
+ builder.append("\n").append(counter++).append(". ").append(arena.getArenaName());
+ }
+ }
+ stringFormatter.displaySuccessMessage(sender, builder.toString());
+ return true;
+ }
+
+ /**
+ * Gets all available groups
+ *
+ * @return All available groups
+ */
+ protected abstract Set getGroups();
+
+ @Nullable
+ @Override
+ public List onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
+ @NotNull String[] arguments) {
+ if (arguments.length == 1) {
+ List groupNames = new ArrayList<>();
+ for (M group : getGroups()) {
+ groupNames.add(group.getGroupName());
+ }
+ return filterMatchingContains(groupNames, arguments[0]);
+ } else {
+ return new ArrayList<>();
+ }
+ }
+
+}
diff --git a/src/main/java/net/knarcraft/minigames/command/dropper/DropperGroupListCommand.java b/src/main/java/net/knarcraft/minigames/command/dropper/DropperGroupListCommand.java
index 7435921..ad7abb4 100644
--- a/src/main/java/net/knarcraft/minigames/command/dropper/DropperGroupListCommand.java
+++ b/src/main/java/net/knarcraft/minigames/command/dropper/DropperGroupListCommand.java
@@ -1,27 +1,20 @@
package net.knarcraft.minigames.command.dropper;
-import net.knarcraft.knarlib.formatting.StringFormatter;
import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.dropper.DropperArena;
import net.knarcraft.minigames.arena.dropper.DropperArenaGroup;
import net.knarcraft.minigames.arena.dropper.DropperArenaHandler;
-import net.knarcraft.minigames.config.MiniGameMessage;
+import net.knarcraft.minigames.command.GroupListCommand;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
-import org.bukkit.command.TabExecutor;
import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.UUID;
-
-import static net.knarcraft.knarlib.util.TabCompletionHelper.filterMatchingContains;
+import java.util.Set;
/**
* The command for listing groups and the stages within
*/
-public class DropperGroupListCommand implements TabExecutor {
+public class DropperGroupListCommand extends GroupListCommand {
@Override
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
@@ -37,63 +30,9 @@ public class DropperGroupListCommand implements TabExecutor {
}
}
- /**
- * Displays all currently existing dropper arena groups
- *
- * @param arenaHandler The arena handler to get groups from
- * @param sender The command sender to display the groups to
- */
- private void displayExistingGroups(@NotNull DropperArenaHandler arenaHandler, @NotNull CommandSender sender) {
- StringBuilder builder = new StringBuilder("Dropper arena groups:").append("\n");
- arenaHandler.getAllGroups().stream().sorted().forEachOrdered((group) ->
- builder.append(group.getGroupName()).append("\n"));
- sender.sendMessage(builder.toString());
- }
-
- /**
- * Displays the ordered stages in a specified group to the specified command sender
- *
- * @param arenaHandler The arena handler to get groups from
- * @param sender The command sender to display the stages to
- * @param groupName The name of the group to display stages for
- * @return True if the stages were successfully displayed
- */
- private boolean displayOrderedArenaNames(@NotNull DropperArenaHandler arenaHandler, @NotNull CommandSender sender,
- @NotNull String groupName) {
- DropperArenaGroup arenaGroup = arenaHandler.getGroup(groupName);
- StringFormatter stringFormatter = MiniGames.getInstance().getStringFormatter();
- if (arenaGroup == null) {
- stringFormatter.displayErrorMessage(sender, MiniGameMessage.ERROR_GROUP_NOT_FOUND);
- return false;
- }
-
- // Send a list of all stages (arenas in the group)
- StringBuilder builder = new StringBuilder(stringFormatter.replacePlaceholder(
- MiniGameMessage.SUCCESS_GROUP_STAGES, "{group}", groupName));
- int counter = 1;
- for (UUID arenaId : arenaGroup.getArenas()) {
- DropperArena arena = arenaHandler.getArena(arenaId);
- if (arena != null) {
- builder.append(counter++).append(". ").append(arena.getArenaName()).append("\n");
- }
- }
- stringFormatter.displaySuccessMessage(sender, builder.toString());
- return true;
- }
-
- @Nullable
@Override
- public List onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
- @NotNull String[] arguments) {
- if (arguments.length == 1) {
- List groupNames = new ArrayList<>();
- for (DropperArenaGroup group : MiniGames.getInstance().getDropperArenaHandler().getAllGroups()) {
- groupNames.add(group.getGroupName());
- }
- return filterMatchingContains(groupNames, arguments[0]);
- } else {
- return new ArrayList<>();
- }
+ protected Set getGroups() {
+ return MiniGames.getInstance().getDropperArenaHandler().getAllGroups();
}
}
diff --git a/src/main/java/net/knarcraft/minigames/command/parkour/ParkourGroupListCommand.java b/src/main/java/net/knarcraft/minigames/command/parkour/ParkourGroupListCommand.java
index 2101887..4f2ea94 100644
--- a/src/main/java/net/knarcraft/minigames/command/parkour/ParkourGroupListCommand.java
+++ b/src/main/java/net/knarcraft/minigames/command/parkour/ParkourGroupListCommand.java
@@ -1,28 +1,20 @@
package net.knarcraft.minigames.command.parkour;
-import net.knarcraft.knarlib.formatting.StringFormatter;
import net.knarcraft.minigames.MiniGames;
import net.knarcraft.minigames.arena.parkour.ParkourArena;
import net.knarcraft.minigames.arena.parkour.ParkourArenaGroup;
import net.knarcraft.minigames.arena.parkour.ParkourArenaHandler;
-import net.knarcraft.minigames.config.MiniGameMessage;
+import net.knarcraft.minigames.command.GroupListCommand;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
-import org.bukkit.command.TabExecutor;
import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-import java.util.ArrayList;
-import java.util.List;
import java.util.Set;
-import java.util.UUID;
-
-import static net.knarcraft.knarlib.util.TabCompletionHelper.filterMatchingContains;
/**
* The command for listing groups and the stages within
*/
-public class ParkourGroupListCommand implements TabExecutor {
+public class ParkourGroupListCommand extends GroupListCommand {
@Override
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
@@ -38,64 +30,9 @@ public class ParkourGroupListCommand implements TabExecutor {
}
}
- /**
- * Displays all currently existing parkour arena groups
- *
- * @param arenaHandler The arena handler to get groups from
- * @param sender The command sender to display the groups to
- */
- private void displayExistingGroups(@NotNull ParkourArenaHandler arenaHandler, @NotNull CommandSender sender) {
- StringBuilder builder = new StringBuilder("Parkour arena groups:").append("\n");
- arenaHandler.getAllGroups().stream().sorted().forEachOrdered((group) ->
- builder.append(group.getGroupName()).append("\n"));
- sender.sendMessage(builder.toString());
- }
-
- /**
- * Displays the ordered stages in a specified group to the specified command sender
- *
- * @param arenaHandler The arena handler to get groups from
- * @param sender The command sender to display the stages to
- * @param groupName The name of the group to display stages for
- * @return True if the stages were successfully displayed
- */
- private boolean displayOrderedArenaNames(@NotNull ParkourArenaHandler arenaHandler, @NotNull CommandSender sender,
- @NotNull String groupName) {
- StringFormatter stringFormatter = MiniGames.getInstance().getStringFormatter();
- ParkourArenaGroup arenaGroup = arenaHandler.getGroup(groupName);
- if (arenaGroup == null) {
- stringFormatter.displayErrorMessage(sender, MiniGameMessage.ERROR_GROUP_NOT_FOUND);
- return false;
- }
-
- // Send a list of all stages (arenas in the group)
- StringBuilder builder = new StringBuilder(stringFormatter.replacePlaceholder(
- MiniGameMessage.SUCCESS_GROUP_STAGES, "{group}", groupName));
- int counter = 1;
- for (UUID arenaId : arenaGroup.getArenas()) {
- ParkourArena arena = arenaHandler.getArena(arenaId);
- if (arena != null) {
- builder.append("\n").append(counter++).append(". ").append(arena.getArenaName());
- }
- }
- stringFormatter.displaySuccessMessage(sender, builder.toString());
- return true;
- }
-
- @Nullable
@Override
- public List onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
- @NotNull String[] arguments) {
- if (arguments.length == 1) {
- List groupNames = new ArrayList<>();
- Set arenaGroups = MiniGames.getInstance().getParkourArenaHandler().getAllGroups();
- for (ParkourArenaGroup group : arenaGroups) {
- groupNames.add(group.getGroupName());
- }
- return filterMatchingContains(groupNames, arguments[0]);
- } else {
- return new ArrayList<>();
- }
+ protected Set getGroups() {
+ return MiniGames.getInstance().getParkourArenaHandler().getAllGroups();
}
}
diff --git a/src/main/java/net/knarcraft/minigames/config/MiniGameMessage.java b/src/main/java/net/knarcraft/minigames/config/MiniGameMessage.java
index dc4f322..5748ea7 100644
--- a/src/main/java/net/knarcraft/minigames/config/MiniGameMessage.java
+++ b/src/main/java/net/knarcraft/minigames/config/MiniGameMessage.java
@@ -298,6 +298,11 @@ public enum MiniGameMessage implements TranslatableMessage {
* The message displayed when arena rewards have been cleared
*/
SUCCESS_REWARDS_CLEARED,
+
+ /**
+ * The message displayed when listing arena groups
+ */
+ SUCCESS_GROUPS,
;
@Override
diff --git a/src/main/resources/strings.yml b/src/main/resources/strings.yml
index 93bd9cf..e755f98 100644
--- a/src/main/resources/strings.yml
+++ b/src/main/resources/strings.yml
@@ -43,6 +43,7 @@ en:
SUCCESS_DROPPER_ARENAS_LIST: "Dropper arenas:&r"
SUCCESS_PARKOUR_ARENAS_LIST: "Parkour arenas:&r"
SUCCESS_CHECKPOINT_REACHED: "Checkpoint reached!"
+ SUCCESS_GROUPS: "Arena groups:&r"
SUCCESS_GROUP_STAGES: "{group}'s stages:&r"
SUCCESS_RECORD_ACHIEVED: "You just set a {recordInfo} on the {gameMode} game-mode!"
RECORD_ACHIEVED_GLOBAL: "new {recordType} record"