mirror of
https://github.com/PaperMC/Velocity.git
synced 2026-02-17 14:37:43 +01:00
Bump to 2.0.0-SNAPSHOT, remove deprecated text API and toml4j
This commit is contained in:
@@ -18,9 +18,6 @@ import com.velocitypowered.api.proxy.server.ServerInfo;
|
||||
import com.velocitypowered.api.util.Favicon;
|
||||
import com.velocitypowered.api.util.GameProfile;
|
||||
import com.velocitypowered.api.util.ProxyVersion;
|
||||
import com.velocitypowered.api.util.bossbar.BossBar;
|
||||
import com.velocitypowered.api.util.bossbar.BossBarColor;
|
||||
import com.velocitypowered.api.util.bossbar.BossBarOverlay;
|
||||
import com.velocitypowered.proxy.command.VelocityCommandManager;
|
||||
import com.velocitypowered.proxy.command.builtin.GlistCommand;
|
||||
import com.velocitypowered.proxy.command.builtin.ServerCommand;
|
||||
@@ -42,7 +39,6 @@ import com.velocitypowered.proxy.util.AddressUtil;
|
||||
import com.velocitypowered.proxy.util.EncryptionUtils;
|
||||
import com.velocitypowered.proxy.util.VelocityChannelRegistrar;
|
||||
import com.velocitypowered.proxy.util.bossbar.AdventureBossBarManager;
|
||||
import com.velocitypowered.proxy.util.bossbar.VelocityBossBar;
|
||||
import com.velocitypowered.proxy.util.ratelimit.Ratelimiter;
|
||||
import com.velocitypowered.proxy.util.ratelimit.Ratelimiters;
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
@@ -77,8 +73,6 @@ import java.util.stream.Collectors;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.audience.ForwardingAudience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.TranslatableComponent;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.asynchttpclient.AsyncHttpClient;
|
||||
@@ -166,15 +160,6 @@ public class VelocityServer implements ProxyServer, ForwardingAudience {
|
||||
return new ProxyVersion(implName, implVendor, implVersion);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull BossBar createBossBar(
|
||||
net.kyori.text.@NonNull Component title,
|
||||
@NonNull BossBarColor color,
|
||||
@NonNull BossBarOverlay overlay,
|
||||
float progress) {
|
||||
return new VelocityBossBar(title, color, overlay, progress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VelocityCommandManager getCommandManager() {
|
||||
return commandManager;
|
||||
@@ -557,15 +542,6 @@ public class VelocityServer implements ProxyServer, ForwardingAudience {
|
||||
return Optional.ofNullable(connectionsByUuid.get(uuid));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void broadcast(net.kyori.text.Component component) {
|
||||
Preconditions.checkNotNull(component, "component");
|
||||
Chat chat = Chat.createClientbound(component);
|
||||
for (ConnectedPlayer player : connectionsByUuid.values()) {
|
||||
player.getConnection().write(chat);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Player> matchPlayer(String partialName) {
|
||||
Objects.requireNonNull(partialName);
|
||||
|
||||
@@ -32,7 +32,6 @@ import java.util.UUID;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.legacytext3.LegacyText3ComponentSerializer;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
@@ -237,16 +236,6 @@ public class VelocityConfiguration implements ProxyConfig {
|
||||
return query.shouldQueryShowPlugins();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the proxy's MOTD.
|
||||
*
|
||||
* @return the MOTD
|
||||
*/
|
||||
@Override
|
||||
public net.kyori.text.Component getMotdComponent() {
|
||||
return LegacyText3ComponentSerializer.get().serialize(this.getMotd());
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.kyori.adventure.text.Component getMotd() {
|
||||
if (motdAsComponent == null) {
|
||||
|
||||
@@ -27,11 +27,7 @@ import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
|
||||
import com.velocitypowered.api.proxy.player.PlayerSettings;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import com.velocitypowered.api.util.GameProfile;
|
||||
import com.velocitypowered.api.util.MessagePosition;
|
||||
import com.velocitypowered.api.util.ModInfo;
|
||||
import com.velocitypowered.api.util.title.TextTitle;
|
||||
import com.velocitypowered.api.util.title.Title;
|
||||
import com.velocitypowered.api.util.title.Titles;
|
||||
import com.velocitypowered.proxy.VelocityServer;
|
||||
import com.velocitypowered.proxy.config.VelocityConfiguration;
|
||||
import com.velocitypowered.proxy.connection.MinecraftConnection;
|
||||
@@ -229,40 +225,6 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
return connection.getProtocolVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(net.kyori.text.Component component, MessagePosition position) {
|
||||
Preconditions.checkNotNull(component, "component");
|
||||
Preconditions.checkNotNull(position, "position");
|
||||
|
||||
byte pos = (byte) position.ordinal();
|
||||
String json;
|
||||
if (position == MessagePosition.ACTION_BAR) {
|
||||
if (getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_11) >= 0) {
|
||||
// We can use the title packet instead.
|
||||
TitlePacket pkt = new TitlePacket();
|
||||
pkt.setAction(TitlePacket.SET_ACTION_BAR);
|
||||
pkt.setComponent(net.kyori.text.serializer.gson.GsonComponentSerializer.INSTANCE
|
||||
.serialize(component));
|
||||
connection.write(pkt);
|
||||
return;
|
||||
} else {
|
||||
// Due to issues with action bar packets, we'll need to convert the text message into a
|
||||
// legacy message and then inject the legacy text into a component... yuck!
|
||||
JsonObject object = new JsonObject();
|
||||
object.addProperty("text", net.kyori.text.serializer.legacy
|
||||
.LegacyComponentSerializer.legacy().serialize(component));
|
||||
json = object.toString();
|
||||
}
|
||||
} else {
|
||||
json = net.kyori.text.serializer.gson.GsonComponentSerializer.INSTANCE.serialize(component);
|
||||
}
|
||||
|
||||
Chat chat = new Chat();
|
||||
chat.setType(pos);
|
||||
chat.setMessage(json);
|
||||
connection.write(chat);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(@NonNull Identity identity, @NonNull Component message) {
|
||||
connection.write(Chat.createClientbound(identity, message, this.getProtocolVersion()));
|
||||
@@ -369,16 +331,6 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
this.profile = profile.withProperties(Preconditions.checkNotNull(properties));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHeaderAndFooter(net.kyori.text.Component header, net.kyori.text.Component footer) {
|
||||
tabList.setHeaderAndFooter(header, footer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearHeaderAndFooter() {
|
||||
tabList.clearHeaderAndFooter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VelocityTabList getTabList() {
|
||||
return tabList;
|
||||
@@ -393,26 +345,6 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnect(net.kyori.text.Component reason) {
|
||||
if (connection.eventLoop().inEventLoop()) {
|
||||
disconnect0(reason, false);
|
||||
} else {
|
||||
connection.eventLoop().execute(() -> disconnect0(reason, false));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnects the player from the proxy.
|
||||
* @param reason the reason for disconnecting the player
|
||||
* @param duringLogin whether the disconnect happened during login
|
||||
*/
|
||||
public void disconnect0(net.kyori.text.Component reason, boolean duringLogin) {
|
||||
logger.info("{} has disconnected: {}", this,
|
||||
net.kyori.text.serializer.legacy.LegacyComponentSerializer.legacy().serialize(reason));
|
||||
connection.closeWith(Disconnect.create(reason));
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnects the player from the proxy.
|
||||
* @param reason the reason for disconnecting the player
|
||||
@@ -424,54 +356,6 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
connection.closeWith(Disconnect.create(reason, this.getProtocolVersion()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTitle(Title title) {
|
||||
Preconditions.checkNotNull(title, "title");
|
||||
|
||||
ProtocolVersion protocolVersion = connection.getProtocolVersion();
|
||||
if (title.equals(Titles.reset())) {
|
||||
connection.write(TitlePacket.resetForProtocolVersion(protocolVersion));
|
||||
} else if (title.equals(Titles.hide())) {
|
||||
connection.write(TitlePacket.hideForProtocolVersion(protocolVersion));
|
||||
} else if (title instanceof TextTitle) {
|
||||
TextTitle tt = (TextTitle) title;
|
||||
|
||||
if (tt.isResetBeforeSend()) {
|
||||
connection.delayedWrite(TitlePacket.resetForProtocolVersion(protocolVersion));
|
||||
}
|
||||
|
||||
Optional<net.kyori.text.Component> titleText = tt.getTitle();
|
||||
if (titleText.isPresent()) {
|
||||
TitlePacket titlePkt = new TitlePacket();
|
||||
titlePkt.setAction(TitlePacket.SET_TITLE);
|
||||
titlePkt.setComponent(net.kyori.text.serializer.gson.GsonComponentSerializer.INSTANCE
|
||||
.serialize(titleText.get()));
|
||||
connection.delayedWrite(titlePkt);
|
||||
}
|
||||
|
||||
Optional<net.kyori.text.Component> subtitleText = tt.getSubtitle();
|
||||
if (subtitleText.isPresent()) {
|
||||
TitlePacket titlePkt = new TitlePacket();
|
||||
titlePkt.setAction(TitlePacket.SET_SUBTITLE);
|
||||
titlePkt.setComponent(net.kyori.text.serializer.gson.GsonComponentSerializer.INSTANCE
|
||||
.serialize(subtitleText.get()));
|
||||
connection.delayedWrite(titlePkt);
|
||||
}
|
||||
|
||||
if (tt.areTimesSet()) {
|
||||
TitlePacket timesPkt = TitlePacket.timesForProtocolVersion(protocolVersion);
|
||||
timesPkt.setFadeIn(tt.getFadeIn());
|
||||
timesPkt.setStay(tt.getStay());
|
||||
timesPkt.setFadeOut(tt.getFadeOut());
|
||||
connection.delayedWrite(timesPkt);
|
||||
}
|
||||
connection.flush();
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unknown title class " + title.getClass().getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public @Nullable VelocityServerConnection getConnectedServer() {
|
||||
return connectedServer;
|
||||
}
|
||||
@@ -610,7 +494,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
|
||||
if (event.getResult() instanceof DisconnectPlayer) {
|
||||
DisconnectPlayer res = (DisconnectPlayer) event.getResult();
|
||||
disconnect(res.getReasonComponent());
|
||||
disconnect(res.getReason());
|
||||
} else if (event.getResult() instanceof RedirectPlayer) {
|
||||
RedirectPlayer res = (RedirectPlayer) event.getResult();
|
||||
createConnectionRequest(res.getServer())
|
||||
@@ -628,10 +512,10 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
case CONNECTION_IN_PROGRESS:
|
||||
// Fatal case
|
||||
case CONNECTION_CANCELLED:
|
||||
disconnect(status.getReasonComponent().orElse(res.getMessageComponent()));
|
||||
disconnect(status.getReason().orElse(res.getMessage()));
|
||||
break;
|
||||
case SERVER_DISCONNECTED:
|
||||
Component reason = status.getReasonComponent()
|
||||
Component reason = status.getReason()
|
||||
.orElse(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR);
|
||||
handleConnectionException(res.getServer(), Disconnect.create(reason,
|
||||
getProtocolVersion()), ((Impl) status).isSafe());
|
||||
@@ -648,9 +532,9 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
} else if (event.getResult() instanceof Notify) {
|
||||
Notify res = (Notify) event.getResult();
|
||||
if (event.kickedDuringServerConnect() && previouslyConnected) {
|
||||
sendMessage(Identity.nil(), res.getMessageComponent());
|
||||
sendMessage(Identity.nil(), res.getMessage());
|
||||
} else {
|
||||
disconnect(res.getMessageComponent());
|
||||
disconnect(res.getMessage());
|
||||
}
|
||||
} else {
|
||||
// In case someone gets creative, assume we want to disconnect the player.
|
||||
@@ -997,7 +881,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
|
||||
// Ignored; the plugin probably already handled this.
|
||||
break;
|
||||
case SERVER_DISCONNECTED:
|
||||
Component reason = status.getReasonComponent()
|
||||
Component reason = status.getReason()
|
||||
.orElse(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR);
|
||||
handleConnectionException(toConnect, Disconnect.create(reason,
|
||||
getProtocolVersion()), status.isSafe());
|
||||
|
||||
@@ -166,7 +166,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
||||
}
|
||||
|
||||
PreLoginComponentResult result = event.getResult();
|
||||
Optional<Component> disconnectReason = result.getReasonComponent();
|
||||
Optional<Component> disconnectReason = result.getReason();
|
||||
if (disconnectReason.isPresent()) {
|
||||
// The component is guaranteed to be provided if the connection was denied.
|
||||
mcConnection.closeWith(Disconnect.create(disconnectReason.get(),
|
||||
@@ -260,7 +260,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
Optional<Component> reason = event.getResult().getReasonComponent();
|
||||
Optional<Component> reason = event.getResult().getReason();
|
||||
if (reason.isPresent()) {
|
||||
player.disconnect0(reason.get(), true);
|
||||
} else {
|
||||
|
||||
@@ -123,7 +123,7 @@ public class StatusSessionHandler implements MinecraftSessionHandler {
|
||||
return new ServerPing(
|
||||
fallback.getVersion(),
|
||||
fallback.getPlayers().orElse(null),
|
||||
response.getDescriptionComponent(),
|
||||
response.getDescription(),
|
||||
fallback.getFavicon().orElse(null),
|
||||
response.getModinfo().orElse(null)
|
||||
);
|
||||
|
||||
@@ -8,7 +8,6 @@ import java.util.Optional;
|
||||
import javax.annotation.Nullable;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.legacytext3.LegacyText3ComponentSerializer;
|
||||
|
||||
public class ConnectionRequestResults {
|
||||
|
||||
@@ -73,12 +72,7 @@ public class ConnectionRequestResults {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<net.kyori.text.Component> getReason() {
|
||||
return Optional.ofNullable(component).map(LegacyText3ComponentSerializer.get()::serialize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Component> getReasonComponent() {
|
||||
public Optional<Component> getReason() {
|
||||
return Optional.ofNullable(component);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,8 +10,7 @@ import com.velocitypowered.proxy.VelocityServer;
|
||||
import java.util.List;
|
||||
import net.kyori.adventure.identity.Identity;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.text.TextComponent;
|
||||
import net.kyori.text.format.TextColor;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.minecrell.terminalconsole.SimpleTerminalConsole;
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@@ -33,12 +32,6 @@ public final class VelocityConsole extends SimpleTerminalConsole implements Cons
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(net.kyori.text.Component component) {
|
||||
logger.info(net.kyori.text.serializer.legacy.LegacyComponentSerializer.legacy()
|
||||
.serialize(component));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(@NonNull Identity identity, @NonNull Component message) {
|
||||
logger.info(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection()
|
||||
@@ -95,7 +88,7 @@ public final class VelocityConsole extends SimpleTerminalConsole implements Cons
|
||||
protected void runCommand(String command) {
|
||||
try {
|
||||
if (!this.server.getCommandManager().execute(this, command)) {
|
||||
sendMessage(TextComponent.of("Command not found.", TextColor.RED));
|
||||
sendMessage(Component.text("Command not found.", NamedTextColor.RED));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("An error occurred while running this command.", e);
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.kyori.adventure.identity.Identity;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.util.UUID;
|
||||
@@ -99,24 +100,12 @@ public class Chat implements MinecraftPacket {
|
||||
return handler.handle(this);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static Chat createClientbound(net.kyori.text.Component component) {
|
||||
return createClientbound(component, CHAT_TYPE, EMPTY_SENDER);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static Chat createClientbound(net.kyori.text.Component component, byte type, UUID sender) {
|
||||
Preconditions.checkNotNull(component, "component");
|
||||
return new Chat(net.kyori.text.serializer.gson.GsonComponentSerializer.INSTANCE
|
||||
.serialize(component), type, sender);
|
||||
}
|
||||
|
||||
public static Chat createClientbound(Identity identity,
|
||||
net.kyori.adventure.text.Component component, ProtocolVersion version) {
|
||||
Component component, ProtocolVersion version) {
|
||||
return createClientbound(component, CHAT_TYPE, identity.uuid(), version);
|
||||
}
|
||||
|
||||
public static Chat createClientbound(net.kyori.adventure.text.Component component, byte type,
|
||||
public static Chat createClientbound(Component component, byte type,
|
||||
UUID sender, ProtocolVersion version) {
|
||||
Preconditions.checkNotNull(component, "component");
|
||||
return new Chat(ProtocolUtils.getJsonChatSerializer(version).serialize(component), type,
|
||||
|
||||
@@ -6,8 +6,7 @@ import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.kyori.text.Component;
|
||||
import net.kyori.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class Disconnect implements MinecraftPacket {
|
||||
@@ -57,14 +56,7 @@ public class Disconnect implements MinecraftPacket {
|
||||
return handler.handle(this);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static Disconnect create(Component component) {
|
||||
Preconditions.checkNotNull(component, "component");
|
||||
return new Disconnect(GsonComponentSerializer.INSTANCE.serialize(component));
|
||||
}
|
||||
|
||||
public static Disconnect create(net.kyori.adventure.text.Component component,
|
||||
ProtocolVersion version) {
|
||||
public static Disconnect create(Component component, ProtocolVersion version) {
|
||||
Preconditions.checkNotNull(component, "component");
|
||||
return new Disconnect(ProtocolUtils.getJsonChatSerializer(version).serialize(component));
|
||||
}
|
||||
|
||||
@@ -51,13 +51,6 @@ public class HeaderAndFooter implements MinecraftPacket {
|
||||
return handler.handle(this);
|
||||
}
|
||||
|
||||
public static HeaderAndFooter create(net.kyori.text.Component header,
|
||||
net.kyori.text.Component footer) {
|
||||
return new HeaderAndFooter(
|
||||
net.kyori.text.serializer.gson.GsonComponentSerializer.INSTANCE.serialize(header),
|
||||
net.kyori.text.serializer.gson.GsonComponentSerializer.INSTANCE.serialize(footer));
|
||||
}
|
||||
|
||||
public static HeaderAndFooter create(net.kyori.adventure.text.Component header,
|
||||
net.kyori.adventure.text.Component footer, ProtocolVersion protocolVersion) {
|
||||
GsonComponentSerializer serializer = ProtocolUtils.getJsonChatSerializer(protocolVersion);
|
||||
|
||||
@@ -38,7 +38,7 @@ public class LegacyDisconnect {
|
||||
// MOTD.
|
||||
return new LegacyDisconnect(String.join(LEGACY_COLOR_CODE,
|
||||
cleanSectionSymbol(getFirstLine(PlainComponentSerializer.plain().serialize(
|
||||
response.getDescriptionComponent()))),
|
||||
response.getDescription()))),
|
||||
Integer.toString(players.getOnline()),
|
||||
Integer.toString(players.getMax())));
|
||||
case MINECRAFT_1_4:
|
||||
@@ -49,7 +49,7 @@ public class LegacyDisconnect {
|
||||
Integer.toString(response.getVersion().getProtocol()),
|
||||
response.getVersion().getName(),
|
||||
getFirstLine(LegacyComponentSerializer.legacySection().serialize(response
|
||||
.getDescriptionComponent())),
|
||||
.getDescription())),
|
||||
Integer.toString(players.getOnline()),
|
||||
Integer.toString(players.getMax())
|
||||
));
|
||||
|
||||
@@ -179,7 +179,7 @@ public class PlayerListItem implements MinecraftPacket {
|
||||
.setProperties(entry.getProfile().getProperties())
|
||||
.setLatency(entry.getLatency())
|
||||
.setGameMode(entry.getGameMode())
|
||||
.setDisplayName(entry.getDisplayNameComponent().orElse(null));
|
||||
.setDisplayName(entry.getDisplayName().orElse(null));
|
||||
}
|
||||
|
||||
public @Nullable UUID getUuid() {
|
||||
|
||||
@@ -10,8 +10,7 @@ import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import net.kyori.text.Component;
|
||||
import net.kyori.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class TabCompleteResponse implements MinecraftPacket {
|
||||
@@ -68,8 +67,8 @@ public class TabCompleteResponse implements MinecraftPacket {
|
||||
int offersAvailable = ProtocolUtils.readVarInt(buf);
|
||||
for (int i = 0; i < offersAvailable; i++) {
|
||||
String offer = ProtocolUtils.readString(buf);
|
||||
Component tooltip = buf.readBoolean() ? GsonComponentSerializer.INSTANCE.deserialize(
|
||||
ProtocolUtils.readString(buf)) : null;
|
||||
Component tooltip = buf.readBoolean() ? ProtocolUtils.getJsonChatSerializer(version)
|
||||
.deserialize(ProtocolUtils.readString(buf)) : null;
|
||||
offers.add(new Offer(offer, tooltip));
|
||||
}
|
||||
} else {
|
||||
@@ -91,7 +90,8 @@ public class TabCompleteResponse implements MinecraftPacket {
|
||||
ProtocolUtils.writeString(buf, offer.text);
|
||||
buf.writeBoolean(offer.tooltip != null);
|
||||
if (offer.tooltip != null) {
|
||||
ProtocolUtils.writeString(buf, GsonComponentSerializer.INSTANCE.serialize(offer.tooltip));
|
||||
ProtocolUtils.writeString(buf, ProtocolUtils.getJsonChatSerializer(version)
|
||||
.serialize(offer.tooltip));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -15,7 +15,6 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import net.kyori.text.Component;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class VelocityTabList implements TabList {
|
||||
@@ -27,13 +26,6 @@ public class VelocityTabList implements TabList {
|
||||
this.connection = connection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHeaderAndFooter(Component header, Component footer) {
|
||||
Preconditions.checkNotNull(header, "header");
|
||||
Preconditions.checkNotNull(footer, "footer");
|
||||
connection.write(HeaderAndFooter.create(header, footer));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHeaderAndFooter(net.kyori.adventure.text.Component header,
|
||||
net.kyori.adventure.text.Component footer) {
|
||||
|
||||
@@ -5,8 +5,7 @@ import com.velocitypowered.api.proxy.player.TabListEntry;
|
||||
import com.velocitypowered.api.util.GameProfile;
|
||||
import com.velocitypowered.proxy.protocol.packet.PlayerListItem;
|
||||
import java.util.Optional;
|
||||
import net.kyori.adventure.text.serializer.legacytext3.LegacyText3ComponentSerializer;
|
||||
import net.kyori.text.Component;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class VelocityTabListEntry implements TabListEntry {
|
||||
@@ -38,22 +37,9 @@ public class VelocityTabListEntry implements TabListEntry {
|
||||
|
||||
@Override
|
||||
public Optional<Component> getDisplayName() {
|
||||
return Optional.ofNullable(displayName).map(LegacyText3ComponentSerializer.get()::serialize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<net.kyori.adventure.text.Component> getDisplayNameComponent() {
|
||||
return Optional.ofNullable(displayName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TabListEntry setDisplayName(@Nullable Component displayName) {
|
||||
if (displayName == null) {
|
||||
return this.setDisplayName((net.kyori.adventure.text.Component) null);
|
||||
}
|
||||
return this.setDisplayName(LegacyText3ComponentSerializer.get().deserialize(displayName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TabListEntry setDisplayName(net.kyori.adventure.text.@Nullable Component displayName) {
|
||||
this.displayName = displayName;
|
||||
|
||||
@@ -12,12 +12,6 @@ public class VelocityTabListEntryLegacy extends VelocityTabListEntry {
|
||||
super(tabList, profile, displayName, latency, gameMode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TabListEntry setDisplayName(net.kyori.text.@Nullable Component displayName) {
|
||||
getTabList().removeEntry(getProfile().getId()); // We have to remove first if updating
|
||||
return super.setDisplayName(displayName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TabListEntry setDisplayName(@Nullable Component displayName) {
|
||||
getTabList().removeEntry(getProfile().getId()); // We have to remove first if updating
|
||||
|
||||
@@ -22,10 +22,6 @@ public class VelocityTabListLegacy extends VelocityTabList {
|
||||
super(connection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHeaderAndFooter(net.kyori.text.Component header, net.kyori.text.Component footer) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHeaderAndFooter(Component header, Component footer) {
|
||||
}
|
||||
|
||||
@@ -1,276 +0,0 @@
|
||||
package com.velocitypowered.proxy.util.bossbar;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.util.bossbar.BossBarColor;
|
||||
import com.velocitypowered.api.util.bossbar.BossBarFlag;
|
||||
import com.velocitypowered.api.util.bossbar.BossBarOverlay;
|
||||
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
|
||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||
import com.velocitypowered.proxy.protocol.packet.BossBar;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import net.kyori.text.Component;
|
||||
import net.kyori.text.serializer.gson.GsonComponentSerializer;
|
||||
|
||||
public class VelocityBossBar implements com.velocitypowered.api.util.bossbar.BossBar {
|
||||
|
||||
private final List<Player> players;
|
||||
private final Set<BossBarFlag> flags;
|
||||
private final UUID uuid;
|
||||
private boolean visible;
|
||||
private Component title;
|
||||
private float percent;
|
||||
private BossBarColor color;
|
||||
private BossBarOverlay overlay;
|
||||
|
||||
/**
|
||||
* Creates a new boss bar.
|
||||
* @param title the title for the bar
|
||||
* @param color the color of the bar
|
||||
* @param overlay the overlay to use
|
||||
* @param percent the percent of the bar
|
||||
*/
|
||||
public VelocityBossBar(
|
||||
Component title, BossBarColor color, BossBarOverlay overlay, float percent) {
|
||||
this.title = checkNotNull(title, "title");
|
||||
this.color = checkNotNull(color, "color");
|
||||
this.overlay = checkNotNull(overlay, "overlay");
|
||||
this.percent = percent;
|
||||
checkPercent(percent);
|
||||
this.uuid = UUID.randomUUID();
|
||||
visible = true;
|
||||
players = new ArrayList<>();
|
||||
flags = EnumSet.noneOf(BossBarFlag.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPlayers(Iterable<Player> players) {
|
||||
checkNotNull(players, "players");
|
||||
for (Player player : players) {
|
||||
addPlayer(player);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPlayer(Player player) {
|
||||
checkNotNull(player, "player");
|
||||
if (!players.contains(player)) {
|
||||
players.add(player);
|
||||
}
|
||||
if (player.isActive() && visible) {
|
||||
sendPacket(player, addPacket());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removePlayer(Player player) {
|
||||
checkNotNull(player, "player");
|
||||
players.remove(player);
|
||||
if (player.isActive()) {
|
||||
sendPacket(player, removePacket());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removePlayers(Iterable<Player> players) {
|
||||
checkNotNull(players, "players");
|
||||
for (Player player : players) {
|
||||
removePlayer(player);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAllPlayers() {
|
||||
removePlayers(ImmutableList.copyOf(players));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTitle(Component title) {
|
||||
this.title = checkNotNull(title, "title");
|
||||
if (visible) {
|
||||
BossBar bar = new BossBar();
|
||||
bar.setUuid(uuid);
|
||||
bar.setAction(BossBar.UPDATE_NAME);
|
||||
bar.setName(GsonComponentSerializer.INSTANCE.serialize(title));
|
||||
sendToAffected(bar);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getPercent() {
|
||||
return percent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPercent(float percent) {
|
||||
checkPercent(percent);
|
||||
this.percent = percent;
|
||||
if (visible) {
|
||||
BossBar bar = new BossBar();
|
||||
bar.setUuid(uuid);
|
||||
bar.setAction(BossBar.UPDATE_PERCENT);
|
||||
bar.setPercent(percent);
|
||||
sendToAffected(bar);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkPercent(final float percent) {
|
||||
if (percent < 0f || percent > 1f) {
|
||||
throw new IllegalArgumentException("Percent must be between 0 and 1");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<Player> getPlayers() {
|
||||
return ImmutableList.copyOf(players);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BossBarColor getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColor(BossBarColor color) {
|
||||
this.color = checkNotNull(color, "color");
|
||||
if (visible) {
|
||||
sendDivisions(color, overlay);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BossBarOverlay getOverlay() {
|
||||
return overlay;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOverlay(BossBarOverlay overlay) {
|
||||
this.overlay = checkNotNull(overlay, "overlay");
|
||||
if (visible) {
|
||||
sendDivisions(color, overlay);
|
||||
}
|
||||
}
|
||||
|
||||
private void sendDivisions(BossBarColor color, BossBarOverlay overlay) {
|
||||
BossBar bar = new BossBar();
|
||||
bar.setUuid(uuid);
|
||||
bar.setAction(BossBar.UPDATE_STYLE);
|
||||
bar.setColor(color.ordinal());
|
||||
bar.setOverlay(overlay.ordinal());
|
||||
sendToAffected(bar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVisible() {
|
||||
return visible;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVisible(boolean visible) {
|
||||
boolean previous = this.visible;
|
||||
if (previous && !visible) {
|
||||
// The bar is being hidden
|
||||
sendToAffected(removePacket());
|
||||
} else if (!previous && visible) {
|
||||
// The bar is being shown
|
||||
sendToAffected(addPacket());
|
||||
}
|
||||
this.visible = visible;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<BossBarFlag> getFlags() {
|
||||
return ImmutableList.copyOf(flags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFlags(BossBarFlag... flags) {
|
||||
if (this.flags.addAll(Arrays.asList(flags)) && visible) {
|
||||
sendToAffected(updateFlags());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFlag(BossBarFlag flag) {
|
||||
checkNotNull(flag, "flag");
|
||||
if (this.flags.remove(flag) && visible) {
|
||||
sendToAffected(updateFlags());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFlags(BossBarFlag... flags) {
|
||||
if (this.flags.removeAll(Arrays.asList(flags)) && visible) {
|
||||
sendToAffected(updateFlags());
|
||||
}
|
||||
}
|
||||
|
||||
private short serializeFlags() {
|
||||
short flagMask = 0x0;
|
||||
if (flags.contains(BossBarFlag.DARKEN_SCREEN)) {
|
||||
flagMask |= 0x1;
|
||||
}
|
||||
if (flags.contains(BossBarFlag.PLAY_BOSS_MUSIC)) {
|
||||
flagMask |= 0x2;
|
||||
}
|
||||
if (flags.contains(BossBarFlag.CREATE_WORLD_FOG)) {
|
||||
flagMask |= 0x4;
|
||||
}
|
||||
return flagMask;
|
||||
}
|
||||
|
||||
private BossBar addPacket() {
|
||||
BossBar bossBar = new BossBar();
|
||||
bossBar.setUuid(uuid);
|
||||
bossBar.setAction(BossBar.ADD);
|
||||
bossBar.setName(GsonComponentSerializer.INSTANCE.serialize(title));
|
||||
bossBar.setColor(color.ordinal());
|
||||
bossBar.setOverlay(overlay.ordinal());
|
||||
bossBar.setPercent(percent);
|
||||
bossBar.setFlags(serializeFlags());
|
||||
return bossBar;
|
||||
}
|
||||
|
||||
private BossBar removePacket() {
|
||||
BossBar bossBar = new BossBar();
|
||||
bossBar.setUuid(uuid);
|
||||
bossBar.setAction(BossBar.REMOVE);
|
||||
return bossBar;
|
||||
}
|
||||
|
||||
private BossBar updateFlags() {
|
||||
BossBar bossBar = new BossBar();
|
||||
bossBar.setUuid(uuid);
|
||||
bossBar.setAction(BossBar.UPDATE_PROPERTIES);
|
||||
bossBar.setFlags(serializeFlags());
|
||||
return bossBar;
|
||||
}
|
||||
|
||||
private void sendToAffected(MinecraftPacket packet) {
|
||||
for (Player player : players) {
|
||||
if (player.isActive() && player.getProtocolVersion().getProtocol()
|
||||
>= ProtocolVersion.MINECRAFT_1_9.getProtocol()) {
|
||||
sendPacket(player, packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void sendPacket(Player player, MinecraftPacket packet) {
|
||||
ConnectedPlayer connected = (ConnectedPlayer) player;
|
||||
connected.getConnection().write(packet);
|
||||
}
|
||||
}
|
||||
@@ -2,17 +2,11 @@ package com.velocitypowered.proxy.command;
|
||||
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.permission.Tristate;
|
||||
import net.kyori.text.Component;
|
||||
|
||||
public class MockCommandSource implements CommandSource {
|
||||
|
||||
public static final CommandSource INSTANCE = new MockCommandSource();
|
||||
|
||||
@Override
|
||||
public void sendMessage(final Component component) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tristate getPermissionValue(final String permission) {
|
||||
return Tristate.UNDEFINED;
|
||||
|
||||
Reference in New Issue
Block a user