Make the guild help command menu more configurable

Add clicking on guild help commands for further information
This commit is contained in:
Taah 2022-05-08 17:52:08 -07:00
parent a919627aba
commit 7a7471da05
11 changed files with 74 additions and 18 deletions

View File

@ -56,9 +56,8 @@ public class Guilds extends PlexModule
this.getPlex().setChatHandler(new ChatHandlerImpl()); this.getPlex().setChatHandler(new ChatHandlerImpl());
this.addDefaultMessage("guildsHelpCommand", "<gradient:gold:yellow>======</gradient>Guild Menu<gradient:gold:yellow>======</gradient><newline>\n" + this.addDefaultMessage("guildsHelpCommand", "<gradient:gold:yellow>======</gradient>Guild Menu<gradient:gold:yellow>======</gradient><newline><newline>{0}", "0 - The commands list");
"<newline><gold>/guild <gray>Returns this menu\n" + this.addDefaultMessage("guildsCommandDisplay", "<gold>{0} <yellow>{1}", "0 - The command name", "1 - The command description");
"<newline><gold>/guild help");
this.addDefaultMessage("guildCommandNotFound", "<red>'<gold>{0}</gold>'<red> is not a valid sub command!", "0 - The sub command"); this.addDefaultMessage("guildCommandNotFound", "<red>'<gold>{0}</gold>'<red> is not a valid sub command!", "0 - The sub command");
this.addDefaultMessage("guildNotFound", "<red>You're currently not a part of a guild!"); this.addDefaultMessage("guildNotFound", "<red>You're currently not a part of a guild!");
this.addDefaultMessage("alreadyInGuild", "<red>You're currently in a guild. Please do <gold>/guild leave<red> if you're a member, or if you're an owner with members, <gold>/guild promote <player><red> then <gold>/guild leave<red>, or just an owner, <gold>/guild disband<red>."); this.addDefaultMessage("alreadyInGuild", "<red>You're currently in a guild. Please do <gold>/guild leave<red> if you're a member, or if you're an owner with members, <gold>/guild promote <player><red> then <gold>/guild leave<red>, or just an owner, <gold>/guild disband<red>.");

View File

@ -8,8 +8,9 @@ import dev.plex.command.source.RequiredCommandSource;
import dev.plex.command.sub.*; import dev.plex.command.sub.*;
import dev.plex.rank.enums.Rank; import dev.plex.rank.enums.Rank;
import dev.plex.util.GuildUtil; import dev.plex.util.GuildUtil;
import dev.plex.util.PlexLog;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent;
import org.apache.commons.lang.StringUtils;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender; import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -50,7 +51,26 @@ public class GuildCommand extends PlexCommand
{ {
if (args.length == 0) if (args.length == 0)
{ {
return messageComponent("guildsHelpCommand"); return getSubs();
}
if (args[0].equalsIgnoreCase("help"))
{
if (args.length < 2)
{
return usage("/guild help <subcommand>");
}
PlexCommand subCommand = getSubCommand(args[1]);
if (subCommand == null)
{
return messageComponent("guildCommandNotFound", args[1]);
}
CommandPermissions permissions = subCommand.getClass().getDeclaredAnnotation(CommandPermissions.class);
return mmString("<gradient:gold:yellow>========<newline>").append(mmString("<gold>Command Name: <yellow>" + subCommand.getName())).append(Component.newline())
.append(mmString("<gold>Command Aliases: <yellow>" + StringUtils.join(subCommand.getAliases(), ", "))).append(Component.newline())
.append(mmString("<gold>Description: <yellow>" + subCommand.getDescription())).append(Component.newline())
.append(mmString("<gold>Permission: <yellow>" + permissions.permission())).append(Component.newline())
.append(mmString("<gold>Required Rank: <yellow>" + permissions.level().name())).append(Component.newline())
.append(mmString("<gold>Required Source: <yellow>" + permissions.source().name()));
} }
PlexCommand subCommand = getSubCommand(args[0]); PlexCommand subCommand = getSubCommand(args[0]);
if (subCommand == null) if (subCommand == null)
@ -126,4 +146,19 @@ public class GuildCommand extends PlexCommand
} }
return ImmutableList.of(); return ImmutableList.of();
} }
public Component getSubs()
{
Component commands = Component.empty();
for (int i = 0; i < this.subCommands.size(); i++)
{
commands = commands.append(messageComponent("guildsCommandDisplay", "/guild " + this.subCommands.get(i).getName(), this.subCommands.get(i).getDescription()).clickEvent(ClickEvent.suggestCommand("/guild help " + this.subCommands.get(i).getName())));
if (i < this.subCommands.size() - 1)
{
commands = commands.append(Component.newline());
}
}
return messageComponent("guildsHelpCommand", commands);
}
} }

View File

@ -19,7 +19,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.Objects; import java.util.Objects;
@CommandParameters(name = "chat", usage = "/guild <command> [message]") @CommandParameters(name = "chat", usage = "/guild <command> [message]", description = "Toggles guild chat or sends a guild chat message")
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.chat") @CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.chat")
public class ChatSubCommand extends PlexCommand public class ChatSubCommand extends PlexCommand
{ {

View File

@ -14,7 +14,7 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@CommandParameters(name = "create", aliases = "make", usage = "/guild <command> <name>") @CommandParameters(name = "create", aliases = "make", usage = "/guild <command> <name>", description = "Creates a guild with a specified name")
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.create") @CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.create")
public class CreateSubCommand extends PlexCommand public class CreateSubCommand extends PlexCommand
{ {

View File

@ -13,7 +13,7 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@CommandParameters(name = "home", aliases = "spawn", usage = "/guild <command>") @CommandParameters(name = "home", aliases = "spawn", usage = "/guild <command>", description = "Teleports to the guild home")
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.home") @CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.home")
public class HomeSubCommand extends PlexCommand public class HomeSubCommand extends PlexCommand
{ {

View File

@ -17,7 +17,7 @@ import org.jetbrains.annotations.Nullable;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@CommandParameters(name = "info", aliases = "information", usage = "/guild <command>") @CommandParameters(name = "info", aliases = "information", usage = "/guild <command>", description = "Shows the guild's information")
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.info") @CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.info")
public class InfoSubCommand extends PlexCommand public class InfoSubCommand extends PlexCommand
{ {

View File

@ -19,7 +19,7 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@CommandParameters(name = "prefix", aliases = "tag,settag,setprefix", usage = "/guild <command> <prefix>") @CommandParameters(name = "prefix", aliases = "tag,settag,setprefix", usage = "/guild <command> <prefix>", description = "Sets the guild's default prefix")
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.prefix") @CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.prefix")
public class PrefixSubCommand extends PlexCommand public class PrefixSubCommand extends PlexCommand
{ {

View File

@ -13,7 +13,7 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@CommandParameters(name = "sethome", aliases = "setspawn", usage = "/guild <command>") @CommandParameters(name = "sethome", aliases = "setspawn", usage = "/guild <command>", description = "Sets the guild's home")
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.sethome") @CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.sethome")
public class SetHomeSubCommand extends PlexCommand public class SetHomeSubCommand extends PlexCommand
{ {

View File

@ -18,7 +18,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.Locale; import java.util.Locale;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@CommandParameters(name = "setwarp", aliases = "makewarp,createwarp", usage = "/guild <command> <name>") @CommandParameters(name = "setwarp", aliases = "makewarp,createwarp", usage = "/guild <command> <name>", description = "Creates a new warp at player's location with a specified name")
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.setwarp") @CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.setwarp")
public class SetWarpSubCommand extends PlexCommand public class SetWarpSubCommand extends PlexCommand
{ {

View File

@ -1,22 +1,25 @@
package dev.plex.command.sub; package dev.plex.command.sub;
import com.google.common.collect.Lists;
import dev.plex.Guilds; import dev.plex.Guilds;
import dev.plex.command.PlexCommand; import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions; import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource; import dev.plex.command.source.RequiredCommandSource;
import dev.plex.guild.Guild;
import dev.plex.rank.enums.Rank; import dev.plex.rank.enums.Rank;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Set; import java.util.Set;
@CommandParameters(name = "warps", aliases = "listwarps", usage = "/guild <command>") @CommandParameters(name = "warps", aliases = "listwarps", usage = "/guild <command>", description = "Displays a clickable list of warps")
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.warps") @CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.warps")
public class WarpListSubCommand extends PlexCommand public class WarpListSubCommand extends PlexCommand
{ {
@ -24,14 +27,33 @@ public class WarpListSubCommand extends PlexCommand
{ {
super(false); super(false);
} }
@Override @Override
protected Component execute(@NotNull CommandSender commandSender, @Nullable Player player, @NotNull String[] args) protected Component execute(@NotNull CommandSender commandSender, @Nullable Player player, @NotNull String[] args)
{ {
assert player != null; assert player != null;
Guilds.get().getGuildHolder().getGuild(player.getUniqueId()).ifPresentOrElse(guild -> { Guilds.get().getGuildHolder().getGuild(player.getUniqueId()).ifPresentOrElse(guild ->
Set<String> warps = guild.getWarps().keySet(); {
send(player, mmString("<gold>Warps (" + warps.size() + "): " + StringUtils.join(warps, ", "))); send(player, getWarps(guild));
}, () -> send(player, messageComponent("guildNotFound"))); }, () -> send(player, messageComponent("guildNotFound")));
return null; return null;
} }
public Component getWarps(Guild guild)
{
Set<String> warps = guild.getWarps().keySet();
List<Component> components = Lists.newArrayList();
warps.forEach(s -> components.add(mmString("<click:suggest_command:/guild warp " + s + ">" + s)));
Component parent = mmString("<gold>Warps (" + warps.size() + "): ");
for (int i = 0; i < components.size(); i++)
{
parent = parent.append(components.get(i));
if (i < components.size() - 1)
{
parent = parent.append(mmString(", "));
}
}
return parent;
}
} }

View File

@ -14,7 +14,7 @@ import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@CommandParameters(name = "warp", aliases = "goto", usage = "/guild <command> <name>") @CommandParameters(name = "warp", aliases = "goto", usage = "/guild <command> <name>", description = "Warps to a specified guild warp")
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.warp") @CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.warp")
public class WarpSubCommand extends PlexCommand public class WarpSubCommand extends PlexCommand
{ {