mirror of
https://github.com/SunNetservers/MiniGames.git
synced 2025-01-31 08:49:34 +01:00
Improves output of arena group listing
This commit is contained in:
parent
8574dfebbb
commit
d124c0948b
4
pom.xml
4
pom.xml
@ -124,13 +124,13 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.knarcraft</groupId>
|
<groupId>net.knarcraft</groupId>
|
||||||
<artifactId>knarlib</artifactId>
|
<artifactId>knarlib</artifactId>
|
||||||
<version>1.2.3-SNAPSHOT</version>
|
<version>1.2.5</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.MilkBowl</groupId>
|
<groupId>com.github.MilkBowl</groupId>
|
||||||
<artifactId>VaultAPI</artifactId>
|
<artifactId>VaultAPI</artifactId>
|
||||||
<version>1.7</version>
|
<version>1.7.1</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -0,0 +1,92 @@
|
|||||||
|
package net.knarcraft.minigames.command;
|
||||||
|
|
||||||
|
import net.knarcraft.knarlib.formatting.StringFormatter;
|
||||||
|
import net.knarcraft.minigames.MiniGames;
|
||||||
|
import net.knarcraft.minigames.arena.Arena;
|
||||||
|
import net.knarcraft.minigames.arena.ArenaGroup;
|
||||||
|
import net.knarcraft.minigames.arena.ArenaHandler;
|
||||||
|
import net.knarcraft.minigames.config.MiniGameMessage;
|
||||||
|
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;
|
||||||
|
|
||||||
|
public abstract class GroupListCommand<K extends ArenaHandler<L, M>, L extends Arena, M extends ArenaGroup<L, M>> implements TabExecutor {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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>
|
||||||
|
*/
|
||||||
|
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 <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>
|
||||||
|
*/
|
||||||
|
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 <p>All available groups</p>
|
||||||
|
*/
|
||||||
|
protected abstract Set<M> getGroups();
|
||||||
|
|
||||||
|
@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 (M group : getGroups()) {
|
||||||
|
groupNames.add(group.getGroupName());
|
||||||
|
}
|
||||||
|
return filterMatchingContains(groupNames, arguments[0]);
|
||||||
|
} else {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,27 +1,20 @@
|
|||||||
package net.knarcraft.minigames.command.dropper;
|
package net.knarcraft.minigames.command.dropper;
|
||||||
|
|
||||||
import net.knarcraft.knarlib.formatting.StringFormatter;
|
|
||||||
import net.knarcraft.minigames.MiniGames;
|
import net.knarcraft.minigames.MiniGames;
|
||||||
import net.knarcraft.minigames.arena.dropper.DropperArena;
|
import net.knarcraft.minigames.arena.dropper.DropperArena;
|
||||||
import net.knarcraft.minigames.arena.dropper.DropperArenaGroup;
|
import net.knarcraft.minigames.arena.dropper.DropperArenaGroup;
|
||||||
import net.knarcraft.minigames.arena.dropper.DropperArenaHandler;
|
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.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.TabExecutor;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.Set;
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import static net.knarcraft.knarlib.util.TabCompletionHelper.filterMatchingContains;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The command for listing groups and the stages within
|
* The command for listing groups and the stages within
|
||||||
*/
|
*/
|
||||||
public class DropperGroupListCommand implements TabExecutor {
|
public class DropperGroupListCommand extends GroupListCommand<DropperArenaHandler, DropperArena, DropperArenaGroup> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
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 <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);
|
|
||||||
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
|
@Override
|
||||||
public List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
protected Set<DropperArenaGroup> getGroups() {
|
||||||
@NotNull String[] arguments) {
|
return MiniGames.getInstance().getDropperArenaHandler().getAllGroups();
|
||||||
if (arguments.length == 1) {
|
|
||||||
List<String> groupNames = new ArrayList<>();
|
|
||||||
for (DropperArenaGroup group : MiniGames.getInstance().getDropperArenaHandler().getAllGroups()) {
|
|
||||||
groupNames.add(group.getGroupName());
|
|
||||||
}
|
|
||||||
return filterMatchingContains(groupNames, arguments[0]);
|
|
||||||
} else {
|
|
||||||
return new ArrayList<>();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,28 +1,20 @@
|
|||||||
package net.knarcraft.minigames.command.parkour;
|
package net.knarcraft.minigames.command.parkour;
|
||||||
|
|
||||||
import net.knarcraft.knarlib.formatting.StringFormatter;
|
|
||||||
import net.knarcraft.minigames.MiniGames;
|
import net.knarcraft.minigames.MiniGames;
|
||||||
import net.knarcraft.minigames.arena.parkour.ParkourArena;
|
import net.knarcraft.minigames.arena.parkour.ParkourArena;
|
||||||
import net.knarcraft.minigames.arena.parkour.ParkourArenaGroup;
|
import net.knarcraft.minigames.arena.parkour.ParkourArenaGroup;
|
||||||
import net.knarcraft.minigames.arena.parkour.ParkourArenaHandler;
|
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.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.TabExecutor;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
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.Set;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import static net.knarcraft.knarlib.util.TabCompletionHelper.filterMatchingContains;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The command for listing groups and the stages within
|
* The command for listing groups and the stages within
|
||||||
*/
|
*/
|
||||||
public class ParkourGroupListCommand implements TabExecutor {
|
public class ParkourGroupListCommand extends GroupListCommand<ParkourArenaHandler, ParkourArena, ParkourArenaGroup> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
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 <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 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 <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 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
|
@Override
|
||||||
public List<String> onTabComplete(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s,
|
protected Set<ParkourArenaGroup> getGroups() {
|
||||||
@NotNull String[] arguments) {
|
return MiniGames.getInstance().getParkourArenaHandler().getAllGroups();
|
||||||
if (arguments.length == 1) {
|
|
||||||
List<String> groupNames = new ArrayList<>();
|
|
||||||
Set<ParkourArenaGroup> arenaGroups = MiniGames.getInstance().getParkourArenaHandler().getAllGroups();
|
|
||||||
for (ParkourArenaGroup group : arenaGroups) {
|
|
||||||
groupNames.add(group.getGroupName());
|
|
||||||
}
|
|
||||||
return filterMatchingContains(groupNames, arguments[0]);
|
|
||||||
} else {
|
|
||||||
return new ArrayList<>();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -298,6 +298,11 @@ public enum MiniGameMessage implements TranslatableMessage {
|
|||||||
* The message displayed when arena rewards have been cleared
|
* The message displayed when arena rewards have been cleared
|
||||||
*/
|
*/
|
||||||
SUCCESS_REWARDS_CLEARED,
|
SUCCESS_REWARDS_CLEARED,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The message displayed when listing arena groups
|
||||||
|
*/
|
||||||
|
SUCCESS_GROUPS,
|
||||||
;
|
;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -43,6 +43,7 @@ en:
|
|||||||
SUCCESS_DROPPER_ARENAS_LIST: "Dropper arenas:&r"
|
SUCCESS_DROPPER_ARENAS_LIST: "Dropper arenas:&r"
|
||||||
SUCCESS_PARKOUR_ARENAS_LIST: "Parkour arenas:&r"
|
SUCCESS_PARKOUR_ARENAS_LIST: "Parkour arenas:&r"
|
||||||
SUCCESS_CHECKPOINT_REACHED: "Checkpoint reached!"
|
SUCCESS_CHECKPOINT_REACHED: "Checkpoint reached!"
|
||||||
|
SUCCESS_GROUPS: "Arena groups:&r"
|
||||||
SUCCESS_GROUP_STAGES: "{group}'s stages:&r"
|
SUCCESS_GROUP_STAGES: "{group}'s stages:&r"
|
||||||
SUCCESS_RECORD_ACHIEVED: "You just set a {recordInfo} on the {gameMode} game-mode!"
|
SUCCESS_RECORD_ACHIEVED: "You just set a {recordInfo} on the {gameMode} game-mode!"
|
||||||
RECORD_ACHIEVED_GLOBAL: "new {recordType} record"
|
RECORD_ACHIEVED_GLOBAL: "new {recordType} record"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user