Initial commit of adventure-adapted Velocity API.

This commit is contained in:
Andrew Steinborn
2020-06-28 21:23:01 -04:00
parent 7fd76962f2
commit 2e7a598916
53 changed files with 728 additions and 184 deletions

View File

@@ -18,10 +18,18 @@ sourceSets {
dependencies {
compile 'com.google.code.gson:gson:2.8.5'
compile "com.google.guava:guava:${guavaVersion}"
// DEPRECATED: Will be removed in Velocity 2.0.0
compile "net.kyori:text-api:${textVersion}"
compile "net.kyori:text-serializer-gson:${textVersion}"
compile "net.kyori:text-serializer-legacy:${textVersion}"
compile "net.kyori:text-serializer-plain:${textVersion}"
compile "net.kyori:adventure-api:${adventureVersion}"
compile "net.kyori:adventure-text-serializer-gson:${adventureVersion}"
compile "net.kyori:adventure-text-serializer-legacy:${adventureVersion}"
compile "net.kyori:adventure-text-serializer-plain:${adventureVersion}"
compile 'com.moandjiezana.toml:toml4j:0.7.2'
compile "org.slf4j:slf4j-api:${slf4jVersion}"
compile 'com.google.inject:guice:4.2.3'

View File

@@ -1,17 +1,20 @@
package com.velocitypowered.api.command;
import com.velocitypowered.api.permission.PermissionSubject;
import net.kyori.text.Component;
import com.velocitypowered.api.proxy.ProxyAudience;
import net.kyori.adventure.text.Component;
/**
* Represents something that can be used to run a {@link Command}.
*/
public interface CommandSource extends PermissionSubject {
public interface CommandSource extends PermissionSubject, ProxyAudience {
/**
* Sends the specified {@code component} to the invoker.
*
* @param component the text component to send
* @deprecated Use {@link #sendMessage(Component)} instead
*/
void sendMessage(Component component);
@Deprecated
void sendMessage(net.kyori.text.Component component);
}

View File

@@ -1,9 +1,10 @@
package com.velocitypowered.api.event;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.util.AdventureCompat;
import java.util.Optional;
import net.kyori.text.Component;
import net.kyori.text.serializer.plain.PlainComponentSerializer;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
@@ -92,7 +93,11 @@ public interface ResultedEvent<R extends ResultedEvent.Result> {
return status;
}
public Optional<Component> getReason() {
public Optional<net.kyori.text.Component> getReason() {
return Optional.ofNullable(reason).map(AdventureCompat::asOriginalTextComponent);
}
public Optional<Component> getReasonComponent() {
return Optional.ofNullable(reason);
}
@@ -115,5 +120,11 @@ public interface ResultedEvent<R extends ResultedEvent.Result> {
Preconditions.checkNotNull(reason, "reason");
return new ComponentResult(false, reason);
}
@Deprecated
public static ComponentResult denied(net.kyori.text.Component reason) {
Preconditions.checkNotNull(reason, "reason");
return new ComponentResult(false, AdventureCompat.asAdventureComponent(reason));
}
}
}

View File

@@ -3,8 +3,8 @@ package com.velocitypowered.api.event.connection;
import com.google.common.base.Preconditions;
import com.velocitypowered.api.event.ResultedEvent;
import com.velocitypowered.api.proxy.InboundConnection;
import com.velocitypowered.api.util.AdventureCompat;
import java.util.Optional;
import net.kyori.text.Component;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -71,9 +71,10 @@ public final class PreLoginEvent implements ResultedEvent<PreLoginEvent.PreLogin
Result.FORCE_OFFLINE, null);
private final Result result;
private final @Nullable Component reason;
private final net.kyori.adventure.text.Component reason;
private PreLoginComponentResult(Result result, @Nullable Component reason) {
private PreLoginComponentResult(Result result,
net.kyori.adventure.text.@Nullable Component reason) {
this.result = result;
this.reason = reason;
}
@@ -83,7 +84,12 @@ public final class PreLoginEvent implements ResultedEvent<PreLoginEvent.PreLogin
return result != Result.DISALLOWED;
}
public Optional<Component> getReason() {
@Deprecated
public Optional<net.kyori.text.Component> getReason() {
return Optional.ofNullable(reason).map(AdventureCompat::asOriginalTextComponent);
}
public Optional<net.kyori.adventure.text.Component> getReasonComponent() {
return Optional.ofNullable(reason);
}
@@ -143,9 +149,23 @@ public final class PreLoginEvent implements ResultedEvent<PreLoginEvent.PreLogin
* Denies the login with the specified reason.
*
* @param reason the reason for disallowing the connection
* @deprecated Use {@link #denied(net.kyori.adventure.text.Component)}
* @return a new result
*/
public static PreLoginComponentResult denied(Component reason) {
@Deprecated
public static PreLoginComponentResult denied(net.kyori.text.Component reason) {
Preconditions.checkNotNull(reason, "reason");
return new PreLoginComponentResult(Result.DISALLOWED,
AdventureCompat.asAdventureComponent(reason));
}
/**
* Denies the login with the specified reason.
*
* @param reason the reason for disallowing the connection
* @return a new result
*/
public static PreLoginComponentResult denied(net.kyori.adventure.text.Component reason) {
Preconditions.checkNotNull(reason, "reason");
return new PreLoginComponentResult(Result.DISALLOWED, reason);
}

View File

@@ -4,6 +4,7 @@ import com.google.common.base.Preconditions;
import com.velocitypowered.api.event.ResultedEvent;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.server.RegisteredServer;
import com.velocitypowered.api.util.AdventureCompat;
import java.util.Optional;
import net.kyori.text.Component;
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -20,7 +21,7 @@ public final class KickedFromServerEvent implements
private final Player player;
private final RegisteredServer server;
private final @Nullable Component originalReason;
private final net.kyori.adventure.text.Component originalReason;
private final boolean duringServerConnect;
private ServerKickResult result;
@@ -34,11 +35,7 @@ public final class KickedFromServerEvent implements
*/
public KickedFromServerEvent(Player player, RegisteredServer server,
@Nullable Component originalReason, boolean duringServerConnect, Component fancyReason) {
this.player = Preconditions.checkNotNull(player, "player");
this.server = Preconditions.checkNotNull(server, "server");
this.originalReason = originalReason;
this.duringServerConnect = duringServerConnect;
this.result = new Notify(fancyReason);
this(player, server, originalReason, duringServerConnect, Notify.create(fancyReason));
}
/**
@@ -53,6 +50,21 @@ public final class KickedFromServerEvent implements
RegisteredServer server,
@Nullable Component originalReason, boolean duringServerConnect,
ServerKickResult result) {
this(player, server, AdventureCompat.asAdventureComponent(originalReason), duringServerConnect,
result);
}
/**
* Creates a {@code KickedFromServerEvent} instance.
* @param player the player affected
* @param server the server the player disconnected from
* @param originalReason the reason for being kicked, optional
* @param duringServerConnect whether or not the player was kicked during the connection process
* @param result the initial result
*/
public KickedFromServerEvent(Player player, RegisteredServer server,
net.kyori.adventure.text.Component originalReason,
boolean duringServerConnect, ServerKickResult result) {
this.player = Preconditions.checkNotNull(player, "player");
this.server = Preconditions.checkNotNull(server, "server");
this.originalReason = originalReason;
@@ -78,7 +90,17 @@ public final class KickedFromServerEvent implements
return server;
}
/**
* Gets the reason the server kicked the player from the server.
* @return the server kicked the player from the server
* @deprecated Use {@link #getServerKickReason()} instead
*/
@Deprecated
public Optional<Component> getOriginalReason() {
return Optional.ofNullable(originalReason).map(AdventureCompat::asOriginalTextComponent);
}
public Optional<net.kyori.adventure.text.Component> getServerKickReason() {
return Optional.ofNullable(originalReason);
}
@@ -115,9 +137,9 @@ public final class KickedFromServerEvent implements
*/
public static final class DisconnectPlayer implements ServerKickResult {
private final Component component;
private final net.kyori.adventure.text.Component component;
private DisconnectPlayer(Component component) {
private DisconnectPlayer(net.kyori.adventure.text.Component component) {
this.component = Preconditions.checkNotNull(component, "component");
}
@@ -126,7 +148,12 @@ public final class KickedFromServerEvent implements
return true;
}
@Deprecated
public Component getReason() {
return AdventureCompat.asOriginalTextComponent(component);
}
public net.kyori.adventure.text.Component getReasonComponent() {
return component;
}
@@ -135,8 +162,20 @@ public final class KickedFromServerEvent implements
*
* @param reason the reason to use when disconnecting the player
* @return the disconnect result
* @deprecated Use {@link #create(net.kyori.adventure.text.Component)} instead
*/
@Deprecated
public static DisconnectPlayer create(Component reason) {
return new DisconnectPlayer(AdventureCompat.asAdventureComponent(reason));
}
/**
* Creates a new {@link DisconnectPlayer} with the specified reason.
*
* @param reason the reason to use when disconnecting the player
* @return the disconnect result
*/
public static DisconnectPlayer create(net.kyori.adventure.text.Component reason) {
return new DisconnectPlayer(reason);
}
}
@@ -147,10 +186,10 @@ public final class KickedFromServerEvent implements
*/
public static final class RedirectPlayer implements ServerKickResult {
private final Component message;
private final net.kyori.adventure.text.Component message;
private final RegisteredServer server;
private RedirectPlayer(RegisteredServer server, @Nullable Component message) {
private RedirectPlayer(RegisteredServer server, net.kyori.adventure.text.Component message) {
this.server = Preconditions.checkNotNull(server, "server");
this.message = message;
}
@@ -164,8 +203,12 @@ public final class KickedFromServerEvent implements
return server;
}
@Nullable
@Deprecated
public Component getMessage() {
return AdventureCompat.asOriginalTextComponent(message);
}
public net.kyori.adventure.text.Component getMessageComponent() {
return message;
}
@@ -174,13 +217,29 @@ public final class KickedFromServerEvent implements
*
* @param server the server to send the player to
* @return the redirect result
* @deprecated Use {@link #create(RegisteredServer, net.kyori.adventure.text.Component)}
*/
public static RedirectPlayer create(RegisteredServer server, @Nullable Component message) {
@Deprecated
public static RedirectPlayer create(RegisteredServer server, net.kyori.text.Component message) {
if (message == null) {
return new RedirectPlayer(server, null);
}
return new RedirectPlayer(server, AdventureCompat.asAdventureComponent(message));
}
/**
* Creates a new redirect result to forward the player to the specified {@code server}.
*
* @param server the server to send the player to
* @return the redirect result
*/
public static RedirectPlayer create(RegisteredServer server,
net.kyori.adventure.text.Component message) {
return new RedirectPlayer(server, message);
}
public static ServerKickResult create(RegisteredServer server) {
return create(server, null);
return new RedirectPlayer(server, null);
}
}
@@ -191,9 +250,10 @@ public final class KickedFromServerEvent implements
*/
public static final class Notify implements ServerKickResult {
private final Component message;
private final net.kyori.adventure.text.Component message;
private Notify(Component message) {
@Deprecated
private Notify(net.kyori.adventure.text.Component message) {
this.message = Preconditions.checkNotNull(message, "message");
}
@@ -202,7 +262,13 @@ public final class KickedFromServerEvent implements
return false;
}
@Deprecated
public Component getMessage() {
return AdventureCompat.asOriginalTextComponent(message);
}
@Deprecated
public net.kyori.adventure.text.Component getMessageComponent() {
return message;
}
@@ -211,8 +277,20 @@ public final class KickedFromServerEvent implements
*
* @param message the server to send the player to
* @return the redirect result
* @deprecated Use {@link #create(net.kyori.adventure.text.Component)} instead
*/
@Deprecated
public static Notify create(Component message) {
return new Notify(AdventureCompat.asAdventureComponent(message));
}
/**
* Notifies the player with the specified message but does nothing else.
*
* @param message the server to send the player to
* @return the redirect result
*/
public static Notify create(net.kyori.adventure.text.Component message) {
return new Notify(message);
}
}

View File

@@ -67,9 +67,18 @@ public interface ConnectionRequestBuilder {
* Returns an (optional) textual reason for the failure to connect to the server.
*
* @return the reason why the user could not connect to the server
* @deprecated Use {@link #getReasonComponent()} instead
*/
@Deprecated
Optional<Component> getReason();
/**
* Returns an (optional) textual reason for the failure to connect to the server.
*
* @return the reason why the user could not connect to the server
*/
Optional<net.kyori.adventure.text.Component> getReasonComponent();
/**
* Returns the server we actually tried to connect to.
*

View File

@@ -14,7 +14,7 @@ import com.velocitypowered.api.util.title.Title;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import net.kyori.text.Component;
import net.kyori.adventure.text.Component;
/**
* Represents a player who is connected to the proxy.
@@ -76,9 +76,11 @@ public interface Player extends CommandSource, InboundConnection, ChannelMessage
* Sends a chat message to the player's client.
*
* @param component the chat message to send
* @deprecated Use {@link #sendMessage(net.kyori.adventure.text.Component)}
*/
@Deprecated
@Override
default void sendMessage(Component component) {
default void sendMessage(net.kyori.text.Component component) {
sendMessage(component, MessagePosition.CHAT);
}
@@ -87,8 +89,11 @@ public interface Player extends CommandSource, InboundConnection, ChannelMessage
*
* @param component the chat message to send
* @param position the position for the message
* @deprecated Use @deprecated Use {@link #sendMessage(net.kyori.adventure.text.Component)} or
* {@link #sendActionBar(net.kyori.adventure.text.Component)}
*/
void sendMessage(Component component, MessagePosition position);
@Deprecated
void sendMessage(net.kyori.text.Component component, MessagePosition position);
/**
* Creates a new connection request so that the player can connect to another server.
@@ -127,7 +132,7 @@ public interface Player extends CommandSource, InboundConnection, ChannelMessage
* @deprecated Use {@link TabList#setHeaderAndFooter(Component, Component)}.
*/
@Deprecated
void setHeaderAndFooter(Component header, Component footer);
void setHeaderAndFooter(net.kyori.text.Component header, net.kyori.text.Component footer);
/**
* Clears the tab list header and footer for the player.
@@ -149,14 +154,26 @@ public interface Player extends CommandSource, InboundConnection, ChannelMessage
* other {@link Player} methods will become undefined.
*
* @param reason component with the reason
* @deprecated Use {@link #disconnect(Component)} instead
*/
void disconnect(Component reason);
@Deprecated
void disconnect(net.kyori.text.Component reason);
/**
* Disconnects the player with the specified reason. Once this method is called, further calls to
* other {@link Player} methods will become undefined.
*
* @param reason component with the reason
*/
void disconnect(net.kyori.adventure.text.Component reason);
/**
* Sends the specified title to the client.
*
* @param title the title to send
* @deprecated Use {@link #showTitle(net.kyori.adventure.title.Title)} and {@link #resetTitle()}
*/
@Deprecated
void sendTitle(Title title);
/**

View File

@@ -0,0 +1,71 @@
package com.velocitypowered.api.proxy;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.bossbar.BossBar;
import net.kyori.adventure.inventory.Book;
import net.kyori.adventure.sound.Sound;
import net.kyori.adventure.sound.SoundStop;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.title.Title;
import org.checkerframework.checker.nullness.qual.NonNull;
/**
* Indicates an {@link Audience} that is on the proxy. This interface contains no-op default methods
* that are used to bridge compatibility issues with the new adventure API. This interface will go
* away in Velocity 2.0.0.
*/
public interface ProxyAudience extends Audience {
@Override
void sendMessage(@NonNull Component message);
@Override
default void sendActionBar(@NonNull Component message) {
}
@Override
default void showTitle(@NonNull Title title) {
}
@Override
default void clearTitle() {
}
@Override
default void resetTitle() {
}
@Override
default void showBossBar(@NonNull BossBar bar) {
}
@Override
default void hideBossBar(@NonNull BossBar bar) {
}
@Override
default void playSound(@NonNull Sound sound) {
}
@Override
default void playSound(@NonNull Sound sound, double x, double y, double z) {
}
@Override
default void stopSound(@NonNull SoundStop stop) {
}
@Override
default void openBook(@NonNull Book book) {
}
}

View File

@@ -17,13 +17,13 @@ import java.net.InetSocketAddress;
import java.util.Collection;
import java.util.Optional;
import java.util.UUID;
import net.kyori.text.Component;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.NonNull;
/**
* Provides an interface to a Minecraft server proxy.
*/
public interface ProxyServer {
public interface ProxyServer extends ProxyAudience {
/**
* Retrieves the player currently connected to this proxy by their Minecraft username. The search
@@ -46,8 +46,10 @@ public interface ProxyServer {
* Broadcasts a message to all players currently online.
*
* @param component the message to send
* @deprecated Use {@link #sendMessage(Component)} instead
*/
void broadcast(Component component);
@Deprecated
void broadcast(net.kyori.text.Component component);
/**
* Retrieves all players currently connected to this proxy. This call may or may not be a snapshot
@@ -186,8 +188,10 @@ public interface ProxyServer {
* @param overlay boss bar overlay
* @param progress boss bar progress
* @return a completely new and fresh boss bar
* @deprecated Use {@link net.kyori.adventure.bossbar.BossBar} instead
*/
@Deprecated
@NonNull
BossBar createBossBar(@NonNull Component title, @NonNull BossBarColor color,
BossBar createBossBar(net.kyori.text.Component title, @NonNull BossBarColor color,
@NonNull BossBarOverlay overlay, float progress);
}

View File

@@ -5,7 +5,6 @@ import com.velocitypowered.api.util.Favicon;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import net.kyori.text.Component;
/**
* Exposes certain proxy configuration information that plugins may use.
@@ -44,8 +43,17 @@ public interface ProxyConfig {
* Get the MOTD component shown in the tab list.
*
* @return the motd component
* @deprecated Use {@link #getMotd()} instead
*/
Component getMotdComponent();
@Deprecated
net.kyori.text.Component getMotdComponent();
/**
* Get the MOTD component shown in the tab list.
*
* @return the motd component
*/
net.kyori.adventure.text.Component getMotd();
/**
* Get the maximum players shown in the tab list.

View File

@@ -5,7 +5,7 @@ import com.velocitypowered.api.util.GameProfile;
import java.util.Collection;
import java.util.Optional;
import java.util.UUID;
import net.kyori.text.Component;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
@@ -13,6 +13,16 @@ import org.checkerframework.checker.nullness.qual.Nullable;
*/
public interface TabList {
/**
* Sets the tab list header and footer for the player.
*
* @param header the header component
* @param footer the footer component
* @deprecated Use {@link #setHeaderAndFooter(Component, Component)} instead
*/
@Deprecated
void setHeaderAndFooter(net.kyori.text.Component header, net.kyori.text.Component footer);
/**
* Sets the tab list header and footer for the player.
*

View File

@@ -1,8 +1,9 @@
package com.velocitypowered.api.proxy.player;
import com.velocitypowered.api.util.AdventureCompat;
import com.velocitypowered.api.util.GameProfile;
import java.util.Optional;
import net.kyori.text.Component;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
@@ -27,12 +28,35 @@ public interface TabListEntry {
GameProfile getProfile();
/**
* Returns {@link Optional} text {@link Component}, which if present is the text displayed for
* {@code this} entry in the {@link TabList}, otherwise {@link GameProfile#getName()} is shown.
* Returns {@link Optional} text {@link net.kyori.text.Component}, which if present is the text
* displayed for {@code this} entry in the {@link TabList}, otherwise
* {@link GameProfile#getName()} is shown.
*
* @return {@link Optional} text {@link net.kyori.text.Component} of name displayed in the tab
* list
*
* @return {@link Optional} text {@link Component} of name displayed in the tab list
*/
Optional<Component> getDisplayName();
Optional<net.kyori.text.Component> getDisplayName();
/**
* Returns {@link Optional} text {@link net.kyori.text.Component}, which if present is the text
* displayed for {@code this} entry in the {@link TabList}, otherwise
* {@link GameProfile#getName()} is shown.
*
* @return {@link Optional} text {@link net.kyori.text.Component} of name displayed in the tab
* list
*/
Optional<Component> getDisplayNameComponent();
/**
* Sets the text {@link net.kyori.text.Component} to be displayed for {@code this}
* {@link TabListEntry}. If {@code null}, {@link GameProfile#getName()} will be shown.
*
* @param displayName to show in the {@link TabList} for {@code this} entry
* @return {@code this}, for chaining
* @deprecated Use {@link #setDisplayName(Component)} instead
*/
TabListEntry setDisplayName(net.kyori.text.Component displayName);
/**
* Sets the text {@link Component} to be displayed for {@code this} {@link TabListEntry}. If
@@ -149,6 +173,19 @@ public interface TabListEntry {
* @param displayName to set
* @return {@code this}, for chaining
* @see TabListEntry#getDisplayName()
* @deprecated Use {@link #displayName(Component)} instead
*/
@Deprecated
public Builder displayName(net.kyori.text.Component displayName) {
return displayName(AdventureCompat.asAdventureComponent(displayName));
}
/**
* Sets the displayed name of the {@link TabListEntry}.
*
* @param displayName to set
* @return {@code this}, for chaining
* @see TabListEntry#getDisplayNameComponent() ()
*/
public Builder displayName(@Nullable Component displayName) {
this.displayName = displayName;

View File

@@ -49,7 +49,7 @@ public final class QueryResponse {
/**
* Get hostname which will be used to reply to the query. By default it is {@link
* ProxyConfig#getMotdComponent()} in plain text without colour codes.
* ProxyConfig#getMotd()} in plain text without colour codes.
*
* @return hostname
*/

View File

@@ -1,14 +1,17 @@
package com.velocitypowered.api.proxy.server;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyAudience;
import com.velocitypowered.api.proxy.messages.ChannelMessageSink;
import java.util.Collection;
import java.util.concurrent.CompletableFuture;
/**
* Represents a server that has been registered with the proxy.
* Represents a server that has been registered with the proxy. The {@code Audience} associated with
* a {@code RegisteredServer} represent all players on the server connected to this proxy and do not
* interact with the server in any way.
*/
public interface RegisteredServer extends ChannelMessageSink {
public interface RegisteredServer extends ChannelMessageSink, ProxyAudience {
/**
* Returns the {@link ServerInfo} for this server.

View File

@@ -3,6 +3,7 @@ package com.velocitypowered.api.proxy.server;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.velocitypowered.api.util.AdventureCompat;
import com.velocitypowered.api.util.Favicon;
import com.velocitypowered.api.util.ModInfo;
import java.util.ArrayList;
@@ -12,7 +13,6 @@ import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import net.kyori.text.Component;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
@@ -22,12 +22,19 @@ public final class ServerPing {
private final Version version;
private final @Nullable Players players;
private final Component description;
private final net.kyori.adventure.text.Component description;
private final @Nullable Favicon favicon;
private final @Nullable ModInfo modinfo;
public ServerPing(Version version, @Nullable Players players, Component description,
@Nullable Favicon favicon) {
@Deprecated
public ServerPing(Version version, @Nullable Players players,
net.kyori.text.Component description, @Nullable Favicon favicon) {
this(version, players, AdventureCompat.asAdventureComponent(description), favicon,
ModInfo.DEFAULT);
}
public ServerPing(Version version, @Nullable Players players,
net.kyori.adventure.text.Component description, @Nullable Favicon favicon) {
this(version, players, description, favicon, ModInfo.DEFAULT);
}
@@ -40,8 +47,25 @@ public final class ServerPing {
* @param favicon the server's favicon
* @param modinfo the mods this server runs
*/
public ServerPing(Version version, @Nullable Players players, Component description,
@Nullable Favicon favicon, @Nullable ModInfo modinfo) {
@Deprecated
public ServerPing(Version version, @Nullable Players players,
net.kyori.text.Component description, @Nullable Favicon favicon,
@Nullable ModInfo modinfo) {
this(version, players, AdventureCompat.asAdventureComponent(description), favicon, modinfo);
}
/**
* Constructs a ServerPing instance.
*
* @param version the version of the server
* @param players the players on the server
* @param description the MOTD for the server
* @param favicon the server's favicon
* @param modinfo the mods this server runs
*/
public ServerPing(Version version, @Nullable Players players,
net.kyori.adventure.text.Component description, @Nullable Favicon favicon,
@Nullable ModInfo modinfo) {
this.version = Preconditions.checkNotNull(version, "version");
this.players = players;
this.description = Preconditions.checkNotNull(description, "description");
@@ -57,7 +81,12 @@ public final class ServerPing {
return Optional.ofNullable(players);
}
public Component getDescription() {
@Deprecated
public net.kyori.text.Component getDescription() {
return AdventureCompat.asOriginalTextComponent(description);
}
public net.kyori.adventure.text.Component getDescriptionComponent() {
return description;
}
@@ -143,7 +172,7 @@ public final class ServerPing {
private final List<SamplePlayer> samplePlayers = new ArrayList<>();
private String modType = "FML";
private final List<ModInfo.Mod> mods = new ArrayList<>();
private @Nullable Component description;
private net.kyori.adventure.text.Component description;
private @Nullable Favicon favicon;
private boolean nullOutPlayers;
private boolean nullOutModinfo;
@@ -215,7 +244,13 @@ public final class ServerPing {
return this;
}
public Builder description(Component description) {
@Deprecated
public Builder description(net.kyori.text.Component description) {
this.description(AdventureCompat.asAdventureComponent(description));
return this;
}
public Builder description(net.kyori.adventure.text.Component description) {
this.description = Preconditions.checkNotNull(description, "description");
return this;
}
@@ -258,7 +293,11 @@ public final class ServerPing {
return samplePlayers;
}
public Optional<Component> getDescription() {
public Optional<net.kyori.text.Component> getDescription() {
return Optional.ofNullable(description).map(AdventureCompat::asOriginalTextComponent);
}
public Optional<net.kyori.adventure.text.Component> getDescriptionComponent() {
return Optional.ofNullable(description);
}

View File

@@ -0,0 +1,29 @@
package com.velocitypowered.api.util;
/**
* Utilities to convert from adventure {@link net.kyori.adventure.text.Component}s to text
* {@link net.kyori.text.Component}s and vice versa.
*
* @deprecated Provided only as a transitional aid, will be removed in Velocity 2.0.0
*/
@Deprecated
public class AdventureCompat {
private AdventureCompat() {
throw new AssertionError("Do not create instances of this class.");
}
public static net.kyori.adventure.text.Component asAdventureComponent(
net.kyori.text.Component component) {
String json = net.kyori.text.serializer.gson.GsonComponentSerializer.INSTANCE
.serialize(component);
return net.kyori.adventure.text.serializer.gson.GsonComponentSerializer.gson()
.deserialize(json);
}
public static net.kyori.text.Component asOriginalTextComponent(
net.kyori.adventure.text.Component component) {
String json = net.kyori.adventure.text.serializer.gson.GsonComponentSerializer
.colorDownsamplingGson().serialize(component);
return net.kyori.text.serializer.gson.GsonComponentSerializer.INSTANCE.deserialize(json);
}
}

View File

@@ -7,7 +7,10 @@ import net.kyori.text.Component;
/**
* Represents a boss bar, which can be send to a (group of) player(s).
* <b>Boss bars only work on 1.9 and above.</b>
*
* @deprecated Replaced with {@link net.kyori.adventure.bossbar.BossBar}
*/
@Deprecated
public interface BossBar {
/**

View File

@@ -2,7 +2,10 @@ package com.velocitypowered.api.util.bossbar;
/**
* Represents a color of a {@link BossBar}.
*
* @deprecated Replaced with {@link net.kyori.adventure.bossbar.BossBar.Color}
*/
@Deprecated
public enum BossBarColor {
PINK,
BLUE,

View File

@@ -2,7 +2,10 @@ package com.velocitypowered.api.util.bossbar;
/**
* Represents any {@link BossBar}'s flags.
*
* @deprecated Replaced with {@link net.kyori.adventure.bossbar.BossBar.Flag}
*/
@Deprecated
public enum BossBarFlag {
DARKEN_SCREEN,
PLAY_BOSS_MUSIC,

View File

@@ -2,7 +2,10 @@ package com.velocitypowered.api.util.bossbar;
/**
* Represents a overlay of a {@link BossBar}.
*
* @deprecated Replaced with {@link net.kyori.adventure.bossbar.BossBar.Overlay}
*/
@Deprecated
public enum BossBarOverlay {
PROGRESS,
NOTCHED_6,

View File

@@ -9,7 +9,10 @@ import org.checkerframework.checker.nullness.qual.Nullable;
/**
* Represents a "full" title, including all components. This class is immutable.
*
* @deprecated Replaced with {@link net.kyori.adventure.title.Title}
*/
@Deprecated
public final class TextTitle implements Title {
private final @Nullable Component title;

View File

@@ -2,7 +2,10 @@ package com.velocitypowered.api.util.title;
/**
* Represents a title that can be sent to a Minecraft client.
*
* @deprecated Replaced with {@link net.kyori.adventure.title.Title}
*/
@Deprecated
public interface Title {
}

View File

@@ -2,7 +2,10 @@ package com.velocitypowered.api.util.title;
/**
* Provides special-purpose titles.
*
* @deprecated Replaced with {@link net.kyori.adventure.title.Title}
*/
@Deprecated
public final class Titles {
private Titles() {

View File

@@ -1,4 +1,6 @@
/**
* Provides data structures for creating and manipulating titles.
*
* @deprecated Replaced with {@link net.kyori.adventure.title}
*/
package com.velocitypowered.api.util.title;