feat(cmd): added about sub-command
This commit is contained in:
parent
e18ecfde1a
commit
8e32264087
3 changed files with 49 additions and 6 deletions
|
@ -2,18 +2,52 @@ package xyz.ineanto.nicko.command;
|
|||
|
||||
import io.papermc.paper.command.brigadier.BasicCommand;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
import xyz.ineanto.nicko.Nicko;
|
||||
import xyz.ineanto.nicko.config.Configuration;
|
||||
import xyz.ineanto.nicko.gui.HomeGUI;
|
||||
import xyz.ineanto.nicko.language.Language;
|
||||
import xyz.ineanto.nicko.language.PlayerLanguage;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public class NickoCommand implements BasicCommand {
|
||||
@Override
|
||||
public void execute(CommandSourceStack stack, String[] strings) {
|
||||
public void execute(CommandSourceStack stack, String[] args) {
|
||||
final Entity executor = stack.getExecutor();
|
||||
final Player player = (Player) executor;
|
||||
final PlayerLanguage playerLanguage = new PlayerLanguage(player);
|
||||
|
||||
if (player == null) { return; }
|
||||
|
||||
if (args.length >= 1 && args[0].equalsIgnoreCase("about")) {
|
||||
final Component firstAboutMessage = MiniMessage.miniMessage().deserialize(
|
||||
"<prefix> <gray>v<version></gray>",
|
||||
Placeholder.component("prefix", playerLanguage.getPrefixComponent()),
|
||||
Placeholder.unparsed("version", Nicko.getInstance().getPluginMeta().getVersion())
|
||||
);
|
||||
|
||||
final Component secondAboutMessage = MiniMessage.miniMessage().deserialize(
|
||||
"<gradient:#01a97c:#8ffd54>Configuration</gradient> <gray>v<configversion></gray>, <gradient:#01a97c:#8ffd54>I18N</gradient> <gray>v<i18nversion></gray>",
|
||||
Placeholder.component("prefix", playerLanguage.getPrefixComponent()),
|
||||
Placeholder.unparsed("configversion", Configuration.VERSION.toString()),
|
||||
Placeholder.unparsed("i18nversion", Language.VERSION.toString())
|
||||
|
||||
);
|
||||
|
||||
player.sendMessage(firstAboutMessage);
|
||||
player.sendMessage(secondAboutMessage);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
new HomeGUI(player).open();
|
||||
}
|
||||
|
@ -23,6 +57,11 @@ public class NickoCommand implements BasicCommand {
|
|||
return sender instanceof Player && sender.isOp() || sender.hasPermission(permission());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> suggest(CommandSourceStack commandSourceStack, String[] args) {
|
||||
return List.of("about");
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String permission() {
|
||||
return "nicko.use";
|
||||
|
|
|
@ -144,10 +144,18 @@ public class PlayerLanguage {
|
|||
}
|
||||
}
|
||||
|
||||
public Component getPrefixComponent() {
|
||||
return MiniMessage.miniMessage().deserialize(readString(LanguageKey.PREFIX));
|
||||
}
|
||||
|
||||
private String readString(String key) {
|
||||
return yamlConfig.getString(key);
|
||||
}
|
||||
|
||||
private String getPrefix() {
|
||||
return LegacyComponentSerializer.legacySection().serialize(getPrefixComponent());
|
||||
}
|
||||
|
||||
private String readStringWithMiniMessage(String key) {
|
||||
return LegacyComponentSerializer.legacySection().serialize(MiniMessage.miniMessage().deserialize(readString(key)));
|
||||
}
|
||||
|
@ -156,10 +164,6 @@ public class PlayerLanguage {
|
|||
return yamlConfig.getStringList(key);
|
||||
}
|
||||
|
||||
private String getPrefix() {
|
||||
return readStringWithMiniMessage(LanguageKey.PREFIX);
|
||||
}
|
||||
|
||||
private String getWhoosh() {
|
||||
return readStringWithMiniMessage(LanguageKey.WHOOSH);
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ public record Version(int major, int minor, int patch) implements Comparable<Ver
|
|||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
public @NotNull String toString() {
|
||||
return major + "." + minor + "." + patch;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue