Support all component-like and literal tooltips and errors (#1600)
This commit is contained in:
@@ -35,7 +35,6 @@ import com.velocitypowered.api.command.CommandManager;
|
||||
import com.velocitypowered.api.command.CommandMeta;
|
||||
import com.velocitypowered.api.command.CommandResult;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.command.VelocityBrigadierMessage;
|
||||
import com.velocitypowered.api.event.command.CommandExecuteEvent;
|
||||
import com.velocitypowered.api.event.command.PostCommandInvocationEvent;
|
||||
import com.velocitypowered.api.plugin.PluginManager;
|
||||
@@ -59,6 +58,7 @@ import java.util.concurrent.locks.ReadWriteLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
import java.util.stream.Collectors;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.checkerframework.checker.lock.qual.GuardedBy;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
@@ -242,8 +242,8 @@ public class VelocityCommandManager implements CommandManager {
|
||||
CommandSyntaxException.BUILT_IN_EXCEPTIONS.dispatcherUnknownCommand());
|
||||
if (isSyntaxError) {
|
||||
final Message message = e.getRawMessage();
|
||||
if (message instanceof VelocityBrigadierMessage velocityMessage) {
|
||||
source.sendMessage(velocityMessage.asComponent().applyFallbackStyle(NamedTextColor.RED));
|
||||
if (message instanceof ComponentLike componentLike) {
|
||||
source.sendMessage(componentLike.asComponent().applyFallbackStyle(NamedTextColor.RED));
|
||||
} else {
|
||||
source.sendMessage(Component.text(e.getMessage(), NamedTextColor.RED));
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import static com.velocitypowered.proxy.protocol.util.PluginMessageUtil.construc
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.mojang.brigadier.suggestion.Suggestion;
|
||||
import com.velocitypowered.api.command.VelocityBrigadierMessage;
|
||||
import com.velocitypowered.api.event.connection.PluginMessageEvent;
|
||||
import com.velocitypowered.api.event.player.CookieReceiveEvent;
|
||||
import com.velocitypowered.api.event.player.PlayerChannelRegisterEvent;
|
||||
@@ -87,6 +86,7 @@ import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -698,10 +698,10 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
||||
for (Suggestion suggestion : suggestions.getList()) {
|
||||
String offer = suggestion.getText();
|
||||
ComponentHolder tooltip = null;
|
||||
if (suggestion.getTooltip() != null
|
||||
&& suggestion.getTooltip() instanceof VelocityBrigadierMessage) {
|
||||
tooltip = new ComponentHolder(player.getProtocolVersion(),
|
||||
((VelocityBrigadierMessage) suggestion.getTooltip()).asComponent());
|
||||
if (suggestion.getTooltip() instanceof ComponentLike componentLike) {
|
||||
tooltip = new ComponentHolder(player.getProtocolVersion(), componentLike.asComponent());
|
||||
} else if (suggestion.getTooltip() != null) {
|
||||
tooltip = new ComponentHolder(player.getProtocolVersion(), Component.text(suggestion.getTooltip().getString()));
|
||||
}
|
||||
offers.add(new Offer(offer, tooltip));
|
||||
}
|
||||
@@ -765,10 +765,10 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
||||
offer = offer.substring(command.length());
|
||||
}
|
||||
ComponentHolder tooltip = null;
|
||||
if (suggestion.getTooltip() != null
|
||||
&& suggestion.getTooltip() instanceof VelocityBrigadierMessage) {
|
||||
tooltip = new ComponentHolder(player.getProtocolVersion(),
|
||||
((VelocityBrigadierMessage) suggestion.getTooltip()).asComponent());
|
||||
if (suggestion.getTooltip() instanceof ComponentLike componentLike) {
|
||||
tooltip = new ComponentHolder(player.getProtocolVersion(), componentLike.asComponent());
|
||||
} else if (suggestion.getTooltip() != null) {
|
||||
tooltip = new ComponentHolder(player.getProtocolVersion(), Component.text(suggestion.getTooltip().getString()));
|
||||
}
|
||||
response.getOffers().add(new Offer(offer, tooltip));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user