Implements the group list command

This commit is contained in:
Kristian Knarvik 2023-03-31 17:35:25 +02:00
parent 888b20bb93
commit dfdf04a0ee
5 changed files with 152 additions and 28 deletions

View File

@ -8,42 +8,45 @@ To modify
## Permissions
| Node | Description |
|----------------|---------------------------------------------------|
| dropper.admin | Gives all permissions |
| dropper.join | Allows a player to participate in dropper arenas |
| dropper.create | Allows a player to create a new dropper arena |
| dropper.edit | Allows a player to edit an existing dropper arena |
| dropper.remove | Allows a player to remove a dropper arena |
| Node | Description |
|----------------|----------------------------------------------------|
| dropper.admin | Gives all permissions. |
| dropper.join | Allows a player to participate in dropper arenas. |
| dropper.create | Allows a player to create a new dropper arena. |
| dropper.edit | Allows a player to edit an existing dropper arena. |
| dropper.remove | Allows a player to remove a dropper arena. |
## Commands
| Command | Arguments | Description |
|------------------------------|-----------------------------|-------------------------------------------------|
| /dropperlist | | Lists available dropper arenas |
| [/dropperjoin](#dropperjoin) | \<arena> \[mode] | Joins the selected arena |
| /dropperleave | | Leaves the current dropper arena |
| /droppercreate | \<name> | Creates a new dropper arena with the given name |
| /dropperremove | \<arena> | Removes the specified dropper arena |
| [/dropperedit](#dropperedit) | \<arena> \<option> \[value] | Gets or sets a dropper arena option |
| /dropperreload | | Reloads all data from disk |
| Command | Alias | Arguments | Description |
|-----------------------------------------|----------|-----------------------------|-------------------------------------------------------------------------------------|
| /dropperList | /dlist | | Lists available dropper arenas. |
| [/dropperJoin](#/dropperJoin) | /djoin | \<arena> \[mode] | Joins the selected arena. |
| /dropperLeave | /dleave | | Leaves the current dropper arena. |
| /dropperCreate | /dcreate | \<name> | Creates a new dropper arena with the given name. The spawn is set to your location. |
| /dropperRemove | /dremove | \<arena> | Removes the specified dropper arena. |
| [/dropperEdit](#/dropperEdit) | /dedit | \<arena> \<option> \[value] | Gets or sets a dropper arena option. |
| /dropperReload | /dreload | | Reloads all data from disk. |
| [/dropperGroupSet](#/dropperGroupSet) | /dgset | \<arena> \<group> | Puts the given arena in the given group. Use "none" to remove an existing group. |
| /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. |
## Command explanation
### /dropperjoin
### /dropperJoin
This command is used for joining a dropper arena.
`/droppejoin <arena> [mode]`
`/dropperjoin <arena> [mode]`
| Argument | Usage |
|----------|----------------------------------------------------------------------------------------------------------------------|
| arena | The name of the arena to join. |
| mode | Additional challenge modes can be played after an arena has been cleared once. Available modes: inverted and random. |
### /dropperedit
### /dropperEdit
This command allows editing the specified property for the specified dropper arena
This command allows editing the specified property for the specified dropper arena.
`/dropperedit <arena> <option> [value]`
@ -53,7 +56,7 @@ This command allows editing the specified property for the specified dropper are
| option | The option to display or change. |
| value | The new value of the selected option. |
These are all the options that can be changed for an arena
These are all the options that can be changed for an arena.
| Option | Details |
|--------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
@ -62,4 +65,36 @@ These are all the options that can be changed for an arena
| exitLocation | The location players will be sent to when exiting the arena. If not set, the player will be sent to where they joined from. Valid values are the same as for spawnLocation. |
| verticalVelocity | The vertical velocity set for players in the arena (basically their falling speed). It must be greater than 0, but max 75. `12.565` and other decimals are allowed. |
| horizontalVelocity | The horizontal velocity (technically fly speed) set for players in the arena. It must be between 0 and 1, and cannot be 0. Decimals are allowed. |
| winBlockType | The type of block players must hit to win the arena. It can be any material as long as it's a block, and not a type of air. |
| winBlockType | The type of block players must hit to win the arena. It can be any material as long as it's a block, and not a type of air. |
### /dropperGroupSet
This command is used to set the group of an arena
`/droppergroupset <arena> <group>`
Dropper groups are created and removed as necessary. If you specify a group named "potato", that group is created, and
will be used again if you specify the "potato" group for another arena. You use "none" or "null" to remove an arena from
its group. If the group has no arenas, it will be automatically removed. If the arena already is in a group, it will be
moved to the new group.
### /dropperGroupSwap
This command is used for changing the order of arenas within a group.
`/droppergroupswap <arena1> <arena2>`
Groups define an order the arenas within that group has to be completed in. Use `/droppergrouplist group` to see the
actual order of the group. So, assuming your arenas in the group looked something like:
1. Forest
2. Sea
3. Nether
4. Savanna
You could use `/droppergroupswap Sea Savanna` to change the order to:
1. Forest
2. Savanna
3. Nether
4. Sea

View File

@ -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
*

View File

@ -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<>();
}
}
}

View File

@ -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<>();

View File

@ -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
}