mirror of
https://github.com/PaperMC/Velocity.git
synced 2026-02-17 06:27:42 +01:00
Cache execution of the builtin Info subcommand
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
|
||||
package com.velocitypowered.proxy.command.builtin;
|
||||
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mojang.brigadier.Command;
|
||||
@@ -53,6 +54,7 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
@@ -82,7 +84,7 @@ public final class VelocityCommand {
|
||||
.executes(new Heap())
|
||||
.build();
|
||||
final LiteralCommandNode<CommandSource> info = BrigadierCommand.literalArgumentBuilder("info")
|
||||
.requires(source -> source.getPermissionValue("velocity.command.info") == Tristate.TRUE)
|
||||
.requires(source -> source.getPermissionValue("velocity.command.info") != Tristate.FALSE)
|
||||
.executes(new Info(server))
|
||||
.build();
|
||||
final LiteralCommandNode<CommandSource> plugins = BrigadierCommand
|
||||
@@ -146,15 +148,14 @@ public final class VelocityCommand {
|
||||
}
|
||||
}
|
||||
|
||||
private record Info(ProxyServer server) implements Command<CommandSource> {
|
||||
|
||||
private static final class Info implements Command<CommandSource> {
|
||||
private static final TextColor VELOCITY_COLOR = TextColor.color(0x09add3);
|
||||
private final Supplier<Component> infoSupplier;
|
||||
|
||||
@Override
|
||||
public int run(final CommandContext<CommandSource> context) {
|
||||
final CommandSource source = context.getSource();
|
||||
private Info(ProxyServer server) {
|
||||
final ProxyVersion version = server.getVersion();
|
||||
|
||||
this.infoSupplier = Suppliers.memoize(() -> {
|
||||
final TextComponent.Builder infoBuilder = Component.text();
|
||||
final Component velocity = Component.text()
|
||||
.content(version.getName() + " ")
|
||||
.decoration(TextDecoration.BOLD, true)
|
||||
@@ -168,9 +169,9 @@ public final class VelocityCommand {
|
||||
Component.text(version.getVendor()),
|
||||
Component.text(version.getName()),
|
||||
Component.text(LocalDate.now().getYear()));
|
||||
source.sendMessage(velocity);
|
||||
source.sendMessage(copyright);
|
||||
|
||||
infoBuilder.append(velocity)
|
||||
.appendNewline()
|
||||
.append(copyright);
|
||||
if (version.getName().equals("Velocity")) {
|
||||
final TextComponent embellishment = Component.text()
|
||||
.append(Component.text()
|
||||
@@ -188,8 +189,18 @@ public final class VelocityCommand {
|
||||
"https://github.com/PaperMC/Velocity"))
|
||||
.build())
|
||||
.build();
|
||||
source.sendMessage(embellishment);
|
||||
infoBuilder.appendNewline().append(embellishment);
|
||||
}
|
||||
|
||||
return infoBuilder.build();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int run(final CommandContext<CommandSource> context) {
|
||||
final CommandSource source = context.getSource();
|
||||
source.sendMessage(infoSupplier.get());
|
||||
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user