forked from Upstream/Velocitab
refactor: improve /velocitab
command messages
This commit is contained in:
parent
1f54cf7ba4
commit
c13d30b29a
@ -36,11 +36,14 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public final class VelocitabCommand {
|
public final class VelocitabCommand {
|
||||||
|
|
||||||
private static final TextColor MAIN_COLOR = TextColor.color(0x00FB9A);
|
private static final TextColor MAIN_COLOR = TextColor.color(0x00FB9A);
|
||||||
|
private static final TextColor ERROR_COLOR = TextColor.color(0xFF7E5E);
|
||||||
|
|
||||||
private final AboutMenu aboutMenu;
|
private final AboutMenu aboutMenu;
|
||||||
private final Velocitab plugin;
|
private final Velocitab plugin;
|
||||||
|
|
||||||
public VelocitabCommand(final @NotNull Velocitab plugin) {
|
public VelocitabCommand(@NotNull Velocitab plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.aboutMenu = AboutMenu.builder()
|
this.aboutMenu = AboutMenu.builder()
|
||||||
.title(Component.text("Velocitab"))
|
.title(Component.text("Velocitab"))
|
||||||
@ -76,46 +79,42 @@ public final class VelocitabCommand {
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
.then(LiteralArgumentBuilder.<CommandSource>literal("name")
|
.then(LiteralArgumentBuilder.<CommandSource>literal("name")
|
||||||
.requires(src -> src.hasPermission("velocitab.command.name"))
|
.requires(src -> hasPermission(src, "name"))
|
||||||
.then(RequiredArgumentBuilder.<CommandSource, String>argument("name", StringArgumentType.greedyString())
|
.then(RequiredArgumentBuilder.<CommandSource, String>argument("name", StringArgumentType.greedyString())
|
||||||
|
.requires(src -> src instanceof Player)
|
||||||
.executes(ctx -> {
|
.executes(ctx -> {
|
||||||
if (!(ctx.getSource() instanceof Player player)) {
|
final Player player = (Player) ctx.getSource();
|
||||||
ctx.getSource().sendMessage(Component.text("You must be a player to use this command!", MAIN_COLOR));
|
final String name = StringArgumentType.getString(ctx, "name");
|
||||||
return Command.SINGLE_SUCCESS;
|
final Optional<TabPlayer> tabPlayer = plugin.getTabList().getTabPlayer(player);
|
||||||
}
|
|
||||||
|
|
||||||
String name = StringArgumentType.getString(ctx, "name");
|
|
||||||
Optional<TabPlayer> tabPlayer = plugin.getTabList().getTabPlayer(player);
|
|
||||||
|
|
||||||
if (tabPlayer.isEmpty()) {
|
if (tabPlayer.isEmpty()) {
|
||||||
ctx.getSource().sendMessage(Component.text("You must in a correct server!", MAIN_COLOR));
|
ctx.getSource().sendMessage(Component
|
||||||
|
.text("You can't update your TAB name from an untracked server!", ERROR_COLOR));
|
||||||
return Command.SINGLE_SUCCESS;
|
return Command.SINGLE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
tabPlayer.get().setCustomName(name);
|
tabPlayer.get().setCustomName(name);
|
||||||
plugin.getTabList().updatePlayerDisplayName(tabPlayer.get());
|
plugin.getTabList().updatePlayerDisplayName(tabPlayer.get());
|
||||||
|
|
||||||
ctx.getSource().sendMessage(Component.text("Your name has been updated!", MAIN_COLOR));
|
ctx.getSource().sendMessage(Component
|
||||||
|
.text("Your TAB name has been updated!", MAIN_COLOR));
|
||||||
return Command.SINGLE_SUCCESS;
|
return Command.SINGLE_SUCCESS;
|
||||||
})
|
})
|
||||||
).executes(ctx -> {
|
)
|
||||||
if (!(ctx.getSource() instanceof Player player)) {
|
.requires(src -> src instanceof Player)
|
||||||
ctx.getSource().sendMessage(Component.text("You must be a player to use this command!", MAIN_COLOR));
|
.executes(ctx -> {
|
||||||
return Command.SINGLE_SUCCESS;
|
final Player player = (Player) ctx.getSource();
|
||||||
}
|
final Optional<TabPlayer> tabPlayer = plugin.getTabList().getTabPlayer(player);
|
||||||
|
|
||||||
Optional<TabPlayer> tabPlayer = plugin.getTabList().getTabPlayer(player);
|
|
||||||
|
|
||||||
if (tabPlayer.isEmpty()) {
|
if (tabPlayer.isEmpty()) {
|
||||||
ctx.getSource().sendMessage(Component.text("You must in a correct server!", MAIN_COLOR));
|
ctx.getSource().sendMessage(Component
|
||||||
|
.text("You can't reset your TAB name from an untracked server!", ERROR_COLOR));
|
||||||
return Command.SINGLE_SUCCESS;
|
return Command.SINGLE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If no custom name is applied, ask for argument
|
// If no custom name is applied, ask for argument
|
||||||
String customName = tabPlayer.get().getCustomName().orElse("");
|
String customName = tabPlayer.get().getCustomName().orElse("");
|
||||||
if (customName.isEmpty() || customName.equals(player.getUsername())) {
|
if (customName.isEmpty() || customName.equals(player.getUsername())) {
|
||||||
ctx.getSource().sendMessage(Component.text("You must specify a name!", MAIN_COLOR));
|
ctx.getSource().sendMessage(Component
|
||||||
|
.text("You aren't using a custom name in TAB!", ERROR_COLOR));
|
||||||
return Command.SINGLE_SUCCESS;
|
return Command.SINGLE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,28 +125,27 @@ public final class VelocitabCommand {
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
.then(LiteralArgumentBuilder.<CommandSource>literal("reload")
|
.then(LiteralArgumentBuilder.<CommandSource>literal("reload")
|
||||||
.requires(src -> src.hasPermission("velocitab.command.reload"))
|
.requires(src -> hasPermission(src, "reload"))
|
||||||
.executes(ctx -> {
|
.executes(ctx -> {
|
||||||
plugin.loadConfigs();
|
plugin.loadConfigs();
|
||||||
plugin.getTabList().reloadUpdate();
|
plugin.getTabList().reloadUpdate();
|
||||||
ctx.getSource().sendMessage(Component.text(
|
ctx.getSource().sendMessage(Component.text("Velocitab has been reloaded!",
|
||||||
"Velocitab has been reloaded!",
|
|
||||||
MAIN_COLOR));
|
MAIN_COLOR));
|
||||||
return Command.SINGLE_SUCCESS;
|
return Command.SINGLE_SUCCESS;
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
.then(LiteralArgumentBuilder.<CommandSource>literal("update")
|
.then(LiteralArgumentBuilder.<CommandSource>literal("update")
|
||||||
.requires(src -> src.hasPermission("velocitab.command.update"))
|
.requires(src -> hasPermission(src, "update"))
|
||||||
.executes(ctx -> {
|
.executes(ctx -> {
|
||||||
plugin.getUpdateChecker().check().thenAccept(checked -> {
|
plugin.getUpdateChecker().check().thenAccept(checked -> {
|
||||||
if (checked.isUpToDate()) {
|
if (checked.isUpToDate()) {
|
||||||
ctx.getSource().sendMessage(Component
|
ctx.getSource().sendMessage(Component.text("Velocitab is up to date! (Running v%s)"
|
||||||
.text("Velocitab is up to date! (Running v" + plugin.getVersion() + ")", MAIN_COLOR));
|
.formatted(plugin.getVersion()), MAIN_COLOR));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ctx.getSource().sendMessage(Component
|
ctx.getSource().sendMessage(Component
|
||||||
.text("An update for velocitab is available. " +
|
.text("An update for Velocitab is available. Please update to %s"
|
||||||
"Please update to " + checked.getLatestVersion(), MAIN_COLOR));
|
.formatted(checked.getLatestVersion()), MAIN_COLOR));
|
||||||
});
|
});
|
||||||
return Command.SINGLE_SUCCESS;
|
return Command.SINGLE_SUCCESS;
|
||||||
})
|
})
|
||||||
@ -156,7 +154,12 @@ public final class VelocitabCommand {
|
|||||||
return new BrigadierCommand(builder);
|
return new BrigadierCommand(builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean hasPermission(@NotNull CommandSource source, @NotNull String command) {
|
||||||
|
return source.hasPermission(String.join("velocitab", "command", command));
|
||||||
|
}
|
||||||
|
|
||||||
private void sendAboutInfo(@NotNull CommandSource source) {
|
private void sendAboutInfo(@NotNull CommandSource source) {
|
||||||
source.sendMessage(aboutMenu.toComponent());
|
source.sendMessage(aboutMenu.toComponent());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user