Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose protocol version for status pings #2456

Merged
merged 1 commit into from
Apr 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/main/java/org/spongepowered/api/MinecraftVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ public interface MinecraftVersion extends Comparable<MinecraftVersion> {
*/
String name();

/**
* Gets the protocol version of this Minecraft version.
*
* @implNote This should be interpreted together with {@link #isLegacy()},
* since legacy clients use a different protocol version numbering scheme.
* @return The protocol version
* @see <a href="https://minecraft.fandom.com/wiki/Protocol_version">Protocol version (Minecraft Wiki)</a>
*/
int protocolVersion();

/**
* Returns whether this version is an older version that doesn't support
* all of the features in {@link StatusResponse}. These versions are only
Expand All @@ -62,4 +72,13 @@ public interface MinecraftVersion extends Comparable<MinecraftVersion> {
* @return The data version
*/
OptionalInt dataVersion();

@Override
default int compareTo(MinecraftVersion o) {
final int result = Boolean.compare(this.isLegacy(), o.isLegacy());
if (result != 0) {
return result;
}
return this.protocolVersion() - o.protocolVersion();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.spongepowered.api.MinecraftVersion;
import org.spongepowered.api.event.Cancellable;
import org.spongepowered.api.event.Event;
import org.spongepowered.api.network.status.Favicon;
Expand Down Expand Up @@ -92,6 +93,9 @@ interface Response extends StatusResponse {
*/
void setHidePlayers(boolean hide);

ImMorpheus marked this conversation as resolved.
Show resolved Hide resolved
@Override
Version version();

/**
* Sets the {@link Favicon} to display on the client.
*
Expand Down Expand Up @@ -130,6 +134,33 @@ interface Players extends StatusResponse.Players {
@Override
List<GameProfile> profiles();
}

/**
* Represents the information about the version of the server, sent
* after the {@link ClientPingServerEvent}.
*/
@NoFactoryMethod
interface Version extends MinecraftVersion {

/**
* Sets the name of the version of the server. This is usually
* displayed on the client if the server is using an incompatible
* protocol version.
*
* @param name The new display name of the server version
*/
void setName(String name);

/**
* Sets the server protocol version reported to the client.
* Modifying this will change if the client sees the server as
* incompatible or not, forcing it to display the {@link #name()}.
*
* @param protocolVersion The new server protocol version
* @see <a href="https://minecraft.fandom.com/wiki/Protocol_version">Protocol version (Minecraft Wiki)</a>
*/
void setProtocolVersion(int protocolVersion);
}
}

}