mirror of
https://github.com/SunNetservers/MiniGames.git
synced 2025-06-25 10:44:43 +02:00
Implements the group list command
This commit is contained in:
@ -23,6 +23,15 @@ public class DropperArenaHandler {
|
||||
private Map<UUID, DropperArenaGroup> arenaGroups = new HashMap<>();
|
||||
private Map<String, UUID> arenaNameLookup = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Gets a copy of all dropper groups
|
||||
*
|
||||
* @return <p>All dropper groups</p>
|
||||
*/
|
||||
public Set<DropperArenaGroup> getAllGroups() {
|
||||
return new HashSet<>(arenaGroups.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the group the given arena belongs to
|
||||
*
|
||||
|
@ -1,19 +1,93 @@
|
||||
package net.knarcraft.dropper.command;
|
||||
|
||||
import net.knarcraft.dropper.Dropper;
|
||||
import net.knarcraft.dropper.arena.DropperArena;
|
||||
import net.knarcraft.dropper.arena.DropperArenaGroup;
|
||||
import net.knarcraft.dropper.arena.DropperArenaHandler;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class GroupListCommand implements CommandExecutor {
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* The command for listing groups and the stages within
|
||||
*/
|
||||
public class GroupListCommand implements TabExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@NotNull String[] arguments) {
|
||||
// TODO: Display all groups if no argument is specified.
|
||||
// TODO: If a group is set and it exists, list all arenas in the correct order, and numbered (the order denotes
|
||||
// the order players need to complete the arenas in)
|
||||
return false;
|
||||
DropperArenaHandler arenaHandler = Dropper.getInstance().getArenaHandler();
|
||||
if (arguments.length == 0) {
|
||||
displayExistingGroups(arenaHandler, commandSender);
|
||||
return true;
|
||||
} else if (arguments.length == 1) {
|
||||
return displayOrderedArenaNames(arenaHandler, commandSender, arguments[0]);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays all currently existing dropper arena groups
|
||||
*
|
||||
* @param arenaHandler <p>The arena handler to get groups from</p>
|
||||
* @param sender <p>The command sender to display the groups to</p>
|
||||
*/
|
||||
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 <p>The arena handler to get groups from</p>
|
||||
* @param sender <p>The command sender to display the stages to</p>
|
||||
* @param groupName <p>The name of the group to display stages for</p>
|
||||
* @return <p>True if the stages were successfully displayed</p>
|
||||
*/
|
||||
private boolean displayOrderedArenaNames(@NotNull DropperArenaHandler arenaHandler, @NotNull CommandSender sender,
|
||||
@NotNull String groupName) {
|
||||
DropperArenaGroup arenaGroup = arenaHandler.getGroup(groupName);
|
||||
if (arenaGroup == null) {
|
||||
sender.sendMessage("Unable to find the specified group!");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Send a list of all stages (arenas in the group)
|
||||
StringBuilder builder = new StringBuilder(groupName).append("'s stages:").append("\n");
|
||||
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");
|
||||
}
|
||||
}
|
||||
sender.sendMessage(builder.toString());
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
||||
@NotNull String[] arguments) {
|
||||
if (arguments.length == 1) {
|
||||
List<String> groupNames = new ArrayList<>();
|
||||
for (DropperArenaGroup group : Dropper.getInstance().getArenaHandler().getAllGroups()) {
|
||||
groupNames.add(group.getGroupName());
|
||||
}
|
||||
return groupNames;
|
||||
} else {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -67,6 +67,9 @@ public class GroupSetCommand implements TabExecutor {
|
||||
List<String> possibleValues = new ArrayList<>();
|
||||
possibleValues.add("none");
|
||||
possibleValues.add("GroupName");
|
||||
for (DropperArenaGroup group : Dropper.getInstance().getArenaHandler().getAllGroups()) {
|
||||
possibleValues.add(group.getGroupName());
|
||||
}
|
||||
return possibleValues;
|
||||
} else {
|
||||
return new ArrayList<>();
|
||||
|
@ -17,4 +17,7 @@ public class GroupSwapCommand implements CommandExecutor {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Tab-completion TODO: Only give arenas with a group for the first value. Only give arenas within the same group
|
||||
// for the second value
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user