mirror of
https://github.com/plexusorg/Module-Guilds.git
synced 2024-11-23 12:35:00 +00:00
Make the guild help command menu more configurable
Add clicking on guild help commands for further information
This commit is contained in:
parent
a919627aba
commit
7a7471da05
@ -56,9 +56,8 @@ public class Guilds extends PlexModule
|
||||
this.getPlex().setChatHandler(new ChatHandlerImpl());
|
||||
|
||||
|
||||
this.addDefaultMessage("guildsHelpCommand", "<gradient:gold:yellow>======</gradient>Guild Menu<gradient:gold:yellow>======</gradient><newline>\n" +
|
||||
"<newline><gold>/guild <gray>Returns this menu\n" +
|
||||
"<newline><gold>/guild help");
|
||||
this.addDefaultMessage("guildsHelpCommand", "<gradient:gold:yellow>======</gradient>Guild Menu<gradient:gold:yellow>======</gradient><newline><newline>{0}", "0 - The commands list");
|
||||
this.addDefaultMessage("guildsCommandDisplay", "<gold>{0} <yellow>{1}", "0 - The command name", "1 - The command description");
|
||||
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("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>.");
|
||||
|
@ -8,8 +8,9 @@ import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.command.sub.*;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.GuildUtil;
|
||||
import dev.plex.util.PlexLog;
|
||||
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.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -50,7 +51,26 @@ public class GuildCommand extends PlexCommand
|
||||
{
|
||||
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]);
|
||||
if (subCommand == null)
|
||||
@ -126,4 +146,19 @@ public class GuildCommand extends PlexCommand
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
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")
|
||||
public class ChatSubCommand extends PlexCommand
|
||||
{
|
||||
|
@ -14,7 +14,7 @@ import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
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")
|
||||
public class CreateSubCommand extends PlexCommand
|
||||
{
|
||||
|
@ -13,7 +13,7 @@ import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
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")
|
||||
public class HomeSubCommand extends PlexCommand
|
||||
{
|
||||
|
@ -17,7 +17,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
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")
|
||||
public class InfoSubCommand extends PlexCommand
|
||||
{
|
||||
|
@ -19,7 +19,7 @@ import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
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")
|
||||
public class PrefixSubCommand extends PlexCommand
|
||||
{
|
||||
|
@ -13,7 +13,7 @@ import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
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")
|
||||
public class SetHomeSubCommand extends PlexCommand
|
||||
{
|
||||
|
@ -18,7 +18,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.Locale;
|
||||
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")
|
||||
public class SetWarpSubCommand extends PlexCommand
|
||||
{
|
||||
|
@ -1,22 +1,25 @@
|
||||
package dev.plex.command.sub;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import dev.plex.Guilds;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.guild.Guild;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
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")
|
||||
public class WarpListSubCommand extends PlexCommand
|
||||
{
|
||||
@ -24,14 +27,33 @@ public class WarpListSubCommand extends PlexCommand
|
||||
{
|
||||
super(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Component execute(@NotNull CommandSender commandSender, @Nullable Player player, @NotNull String[] args)
|
||||
{
|
||||
assert player != null;
|
||||
Guilds.get().getGuildHolder().getGuild(player.getUniqueId()).ifPresentOrElse(guild -> {
|
||||
Set<String> warps = guild.getWarps().keySet();
|
||||
send(player, mmString("<gold>Warps (" + warps.size() + "): " + StringUtils.join(warps, ", ")));
|
||||
Guilds.get().getGuildHolder().getGuild(player.getUniqueId()).ifPresentOrElse(guild ->
|
||||
{
|
||||
send(player, getWarps(guild));
|
||||
}, () -> send(player, messageComponent("guildNotFound")));
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
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")
|
||||
public class WarpSubCommand extends PlexCommand
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user