3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-09-29 06:30:16 +02:00

Improve protocol version checking (#1203)

* Improve protocol version checking

* chore: since 3.3.0
Dieser Commit ist enthalten in:
Riley Park 2024-01-18 17:32:42 -08:00 committet von GitHub
Ursprung 2ac8751337
Commit 0993ce2f86
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: B5690EEEBB952194
53 geänderte Dateien mit 313 neuen und 214 gelöschten Zeilen

Datei anzeigen

@ -18,6 +18,8 @@ java {
} }
dependencies { dependencies {
compileOnlyApi(libs.jspecify)
api(libs.gson) api(libs.gson)
api(libs.guava) api(libs.guava)

Datei anzeigen

@ -100,7 +100,7 @@ public class PlayerResourcePackStatusEvent {
*/ */
public void setOverwriteKick(boolean overwriteKick) { public void setOverwriteKick(boolean overwriteKick) {
Preconditions.checkArgument(player.getProtocolVersion() Preconditions.checkArgument(player.getProtocolVersion()
.compareTo(ProtocolVersion.MINECRAFT_1_17) < 0, .lessThan(ProtocolVersion.MINECRAFT_1_17),
"overwriteKick is not supported on 1.17 or newer"); "overwriteKick is not supported on 1.17 or newer");
this.overwriteKick = overwriteKick; this.overwriteKick = overwriteKick;
} }

Datei anzeigen

@ -10,6 +10,7 @@ package com.velocitypowered.api.network;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.velocitypowered.api.util.Ordered;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -19,7 +20,7 @@ import java.util.Set;
/** /**
* Represents each Minecraft protocol version. * Represents each Minecraft protocol version.
*/ */
public enum ProtocolVersion { public enum ProtocolVersion implements Ordered<ProtocolVersion> {
UNKNOWN(-1, "Unknown"), UNKNOWN(-1, "Unknown"),
LEGACY(-2, "Legacy"), LEGACY(-2, "Legacy"),
MINECRAFT_1_7_2(4, MINECRAFT_1_7_2(4,

Datei anzeigen

@ -9,6 +9,7 @@ package com.velocitypowered.api.proxy.crypto;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.api.util.Ordered;
import java.security.PublicKey; import java.security.PublicKey;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
@ -57,7 +58,7 @@ public interface IdentifiedKey extends KeySigned {
/** /**
* The different versions of player keys, per Minecraft version. * The different versions of player keys, per Minecraft version.
*/ */
enum Revision { enum Revision implements Ordered<Revision> {
GENERIC_V1(ImmutableSet.of(), ImmutableSet.of(ProtocolVersion.MINECRAFT_1_19)), GENERIC_V1(ImmutableSet.of(), ImmutableSet.of(ProtocolVersion.MINECRAFT_1_19)),
LINKED_V2(ImmutableSet.of(), ImmutableSet.of(ProtocolVersion.MINECRAFT_1_19_1)); LINKED_V2(ImmutableSet.of(), ImmutableSet.of(ProtocolVersion.MINECRAFT_1_19_1));

Datei anzeigen

@ -0,0 +1,93 @@
/*
* This file is part of commons, licensed under the MIT License.
*
* Copyright (c) 2021-2024 Seiama
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.velocitypowered.api.util;
import org.jspecify.annotations.NullMarked;
/**
* Something that is ordered.
*
* @param <T> the type
* @since 3.3.0
*/
@NullMarked
@SuppressWarnings("ComparableType") // allows us to be more flexible
public interface Ordered<T> extends Comparable<T> {
/**
* Checks if {@code this} is greater than {@code that}.
*
* @param that the other object
* @return {@code true} if {@code this} is greater than {@code that}, {@code false} otherwise
* @since 3.3.0
*/
default boolean greaterThan(final T that) {
return this.compareTo(that) > 0;
}
/**
* Checks if {@code this} is greater than or equal to {@code that}.
*
* @param that the other object
* @return {@code true} if {@code this} is greater than or
* equal to {@code that}, {@code false} otherwise
* @since 3.3.0
*/
default boolean noLessThan(final T that) {
return this.compareTo(that) >= 0;
}
/**
* Checks if {@code this} is less than {@code that}.
*
* @param that the other object
* @return {@code true} if {@code this} is less than {@code that}, {@code false} otherwise
* @since 3.3.0
*/
default boolean lessThan(final T that) {
return this.compareTo(that) < 0;
}
/**
* Checks if {@code this} is less than or equal to {@code that}.
*
* @param that the other object
* @return {@code true} if {@code this} is less than or
* equal to {@code that}, {@code false} otherwise
* @since 3.3.0
*/
default boolean noGreaterThan(final T that) {
return this.compareTo(that) <= 0;
}
/**
* Checks if {@code this} is equal to {@code that}.
*
* @param that the other object
* @return {@code true} if {@code this} is equal to {@code that}, {@code false} otherwise
* @since 3.3.0
*/
default boolean noGreaterOrLessThan(final T that) {
return this.compareTo(that) == 0;
}
}

Datei anzeigen

@ -7,6 +7,7 @@ extensions.configure<SpotlessExtension> {
java { java {
if (project.name == "velocity-api") { if (project.name == "velocity-api") {
licenseHeaderFile(file("HEADER.txt")) licenseHeaderFile(file("HEADER.txt"))
targetExclude("**/java/com/velocitypowered/api/util/Ordered.java")
} else { } else {
licenseHeaderFile(rootProject.file("HEADER.txt")) licenseHeaderFile(rootProject.file("HEADER.txt"))
} }

Datei anzeigen

@ -34,6 +34,7 @@ flare-fastutil = { module = "space.vectrix.flare:flare-fastutil", version.ref =
jline = "org.jline:jline-terminal-jansi:3.23.0" jline = "org.jline:jline-terminal-jansi:3.23.0"
jopt = "net.sf.jopt-simple:jopt-simple:5.0.4" jopt = "net.sf.jopt-simple:jopt-simple:5.0.4"
junit = "org.junit.jupiter:junit-jupiter:5.9.0" junit = "org.junit.jupiter:junit-jupiter:5.9.0"
jspecify = "org.jspecify:jspecify:0.3.0"
kyori-ansi = "net.kyori:ansi:1.0.3" kyori-ansi = "net.kyori:ansi:1.0.3"
guava = "com.google.guava:guava:25.1-jre" guava = "com.google.guava:guava:25.1-jre"
gson = "com.google.code.gson:gson:2.10.1" gson = "com.google.code.gson:gson:2.10.1"

Datei anzeigen

@ -776,10 +776,10 @@ public class VelocityServer implements ProxyServer, ForwardingAudience {
*/ */
public static Gson getPingGsonInstance(ProtocolVersion version) { public static Gson getPingGsonInstance(ProtocolVersion version) {
if (version == ProtocolVersion.UNKNOWN if (version == ProtocolVersion.UNKNOWN
|| version.compareTo(ProtocolVersion.MINECRAFT_1_20_3) >= 0) { || version.noLessThan(ProtocolVersion.MINECRAFT_1_20_3)) {
return MODERN_PING_SERIALIZER; return MODERN_PING_SERIALIZER;
} }
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_16)) {
return PRE_1_20_3_PING_SERIALIZER; return PRE_1_20_3_PING_SERIALIZER;
} }
return PRE_1_16_PING_SERIALIZER; return PRE_1_16_PING_SERIALIZER;

Datei anzeigen

@ -268,8 +268,8 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
*/ */
public void closeWith(Object msg) { public void closeWith(Object msg) {
if (channel.isActive()) { if (channel.isActive()) {
boolean is17 = this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) < 0 boolean is17 = this.getProtocolVersion().lessThan(ProtocolVersion.MINECRAFT_1_8)
&& this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_7_2) >= 0; && this.getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_7_2);
if (is17 && this.getState() != StateRegistry.STATUS) { if (is17 && this.getState() != StateRegistry.STATUS) {
channel.eventLoop().execute(() -> { channel.eventLoop().execute(() -> {
// 1.7.x versions have a race condition with switching protocol states, so just explicitly // 1.7.x versions have a race condition with switching protocol states, so just explicitly

Datei anzeigen

@ -297,7 +297,7 @@ public class BungeeCordMessageResponder {
} }
static String getBungeeCordChannel(ProtocolVersion version) { static String getBungeeCordChannel(ProtocolVersion version) {
return version.compareTo(ProtocolVersion.MINECRAFT_1_13) >= 0 ? MODERN_CHANNEL.getId() return version.noLessThan(ProtocolVersion.MINECRAFT_1_13) ? MODERN_CHANNEL.getId()
: LEGACY_CHANNEL.getId(); : LEGACY_CHANNEL.getId();
} }

Datei anzeigen

@ -153,7 +153,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
// Move into the PLAY phase. // Move into the PLAY phase.
MinecraftConnection smc = serverConn.ensureConnected(); MinecraftConnection smc = serverConn.ensureConnected();
if (smc.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_20_2) < 0) { if (smc.getProtocolVersion().lessThan(ProtocolVersion.MINECRAFT_1_20_2)) {
smc.setActiveSessionHandler(StateRegistry.PLAY, smc.setActiveSessionHandler(StateRegistry.PLAY,
new TransitionSessionHandler(server, serverConn, resultFuture)); new TransitionSessionHandler(server, serverConn, resultFuture));
} else { } else {
@ -202,7 +202,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
// Ensure we are in range // Ensure we are in range
requested = Math.min(requested, VelocityConstants.MODERN_FORWARDING_MAX_VERSION); requested = Math.min(requested, VelocityConstants.MODERN_FORWARDING_MAX_VERSION);
if (requested > VelocityConstants.MODERN_FORWARDING_DEFAULT) { if (requested > VelocityConstants.MODERN_FORWARDING_DEFAULT) {
if (player.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_19_3) >= 0) { if (player.getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_19_3)) {
return requested >= VelocityConstants.MODERN_LAZY_SESSION return requested >= VelocityConstants.MODERN_LAZY_SESSION
? VelocityConstants.MODERN_LAZY_SESSION ? VelocityConstants.MODERN_LAZY_SESSION
: VelocityConstants.MODERN_FORWARDING_DEFAULT; : VelocityConstants.MODERN_FORWARDING_DEFAULT;

Datei anzeigen

@ -144,7 +144,7 @@ public class TransitionSessionHandler implements MinecraftSessionHandler {
serverConn.getPlayer().setConnectedServer(serverConn); serverConn.getPlayer().setConnectedServer(serverConn);
// Send client settings. In 1.20.2+ this is done in the config state. // Send client settings. In 1.20.2+ this is done in the config state.
if (smc.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_20_2) < 0 if (smc.getProtocolVersion().lessThan(ProtocolVersion.MINECRAFT_1_20_2)
&& player.getClientSettingsPacket() != null) { && player.getClientSettingsPacket() != null) {
serverConn.ensureConnected().write(player.getClientSettingsPacket()); serverConn.ensureConnected().write(player.getClientSettingsPacket());
} }

Datei anzeigen

@ -203,7 +203,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
mc.setProtocolVersion(protocolVersion); mc.setProtocolVersion(protocolVersion);
mc.setActiveSessionHandler(StateRegistry.LOGIN); mc.setActiveSessionHandler(StateRegistry.LOGIN);
if (proxyPlayer.getIdentifiedKey() == null if (proxyPlayer.getIdentifiedKey() == null
&& proxyPlayer.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_19_3) >= 0) { && proxyPlayer.getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_19_3)) {
mc.delayedWrite(new ServerLoginPacket(proxyPlayer.getUsername(), proxyPlayer.getUniqueId())); mc.delayedWrite(new ServerLoginPacket(proxyPlayer.getUsername(), proxyPlayer.getUniqueId()));
} else { } else {
mc.delayedWrite(new ServerLoginPacket(proxyPlayer.getUsername(), mc.delayedWrite(new ServerLoginPacket(proxyPlayer.getUsername(),

Datei anzeigen

@ -131,7 +131,7 @@ public class AuthSessionHandler implements MinecraftSessionHandler {
private void startLoginCompletion(ConnectedPlayer player) { private void startLoginCompletion(ConnectedPlayer player) {
int threshold = server.getConfiguration().getCompressionThreshold(); int threshold = server.getConfiguration().getCompressionThreshold();
if (threshold >= 0 && mcConnection.getProtocolVersion().compareTo(MINECRAFT_1_8) >= 0) { if (threshold >= 0 && mcConnection.getProtocolVersion().noLessThan(MINECRAFT_1_8)) {
mcConnection.write(new SetCompressionPacket(threshold)); mcConnection.write(new SetCompressionPacket(threshold));
mcConnection.setCompressionThreshold(threshold); mcConnection.setCompressionThreshold(threshold);
} }
@ -216,7 +216,7 @@ public class AuthSessionHandler implements MinecraftSessionHandler {
mcConnection.write(success); mcConnection.write(success);
loginState = State.SUCCESS_SENT; loginState = State.SUCCESS_SENT;
if (inbound.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_20_2) < 0) { if (inbound.getProtocolVersion().lessThan(ProtocolVersion.MINECRAFT_1_20_2)) {
loginState = State.ACKNOWLEDGED; loginState = State.ACKNOWLEDGED;
mcConnection.setActiveSessionHandler(StateRegistry.PLAY, mcConnection.setActiveSessionHandler(StateRegistry.PLAY,
new InitialConnectSessionHandler(player, server)); new InitialConnectSessionHandler(player, server));

Datei anzeigen

@ -118,10 +118,10 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
this.player = player; this.player = player;
this.server = server; this.server = server;
if (this.player.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_19_3) >= 0) { if (this.player.getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_19_3)) {
this.chatHandler = new SessionChatHandler(this.player, this.server); this.chatHandler = new SessionChatHandler(this.player, this.server);
this.commandHandler = new SessionCommandHandler(this.player, this.server); this.commandHandler = new SessionCommandHandler(this.player, this.server);
} else if (this.player.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0) { } else if (this.player.getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_19)) {
this.chatHandler = new KeyedChatHandler(this.server, this.player); this.chatHandler = new KeyedChatHandler(this.server, this.player);
this.commandHandler = new KeyedCommandHandler(this.player, this.server); this.commandHandler = new KeyedCommandHandler(this.player, this.server);
} else { } else {
@ -551,7 +551,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
} }
// Clear any title from the previous server. // Clear any title from the previous server.
if (player.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { if (player.getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_8)) {
player.getConnection().delayedWrite( player.getConnection().delayedWrite(
GenericTitlePacket.constructTitlePacket(GenericTitlePacket.ActionType.RESET, GenericTitlePacket.constructTitlePacket(GenericTitlePacket.ActionType.RESET,
player.getProtocolVersion())); player.getProtocolVersion()));
@ -574,7 +574,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
// improving compatibility with mods. // improving compatibility with mods.
final RespawnPacket respawn = RespawnPacket.fromJoinGame(joinGame); final RespawnPacket respawn = RespawnPacket.fromJoinGame(joinGame);
if (player.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_16) < 0) { if (player.getProtocolVersion().lessThan(ProtocolVersion.MINECRAFT_1_16)) {
// Before Minecraft 1.16, we could not switch to the same dimension without sending an // Before Minecraft 1.16, we could not switch to the same dimension without sending an
// additional respawn. On older versions of Minecraft this forces the client to perform // additional respawn. On older versions of Minecraft this forces the client to perform
// garbage collection which adds additional latency. // garbage collection which adds additional latency.
@ -616,7 +616,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
String commandLabel = command.substring(0, commandEndPosition); String commandLabel = command.substring(0, commandEndPosition);
if (!server.getCommandManager().hasCommand(commandLabel)) { if (!server.getCommandManager().hasCommand(commandLabel)) {
if (player.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_13) < 0) { if (player.getProtocolVersion().lessThan(ProtocolVersion.MINECRAFT_1_13)) {
// Outstanding tab completes are recorded for use with 1.12 clients and below to provide // Outstanding tab completes are recorded for use with 1.12 clients and below to provide
// additional tab completion support. // additional tab completion support.
outstandingTabComplete = packet; outstandingTabComplete = packet;
@ -659,7 +659,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
} }
private boolean handleRegularTabComplete(TabCompleteRequestPacket packet) { private boolean handleRegularTabComplete(TabCompleteRequestPacket packet) {
if (player.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_13) < 0) { if (player.getProtocolVersion().lessThan(ProtocolVersion.MINECRAFT_1_13)) {
// Outstanding tab completes are recorded for use with 1.12 clients and below to provide // Outstanding tab completes are recorded for use with 1.12 clients and below to provide
// additional tab completion support. // additional tab completion support.
outstandingTabComplete = packet; outstandingTabComplete = packet;
@ -692,7 +692,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
server.getCommandManager().offerBrigadierSuggestions(player, command) server.getCommandManager().offerBrigadierSuggestions(player, command)
.thenAcceptAsync(offers -> { .thenAcceptAsync(offers -> {
boolean legacy = boolean legacy =
player.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_13) < 0; player.getProtocolVersion().lessThan(ProtocolVersion.MINECRAFT_1_13);
try { try {
for (Suggestion suggestion : offers.getList()) { for (Suggestion suggestion : offers.getList()) {
String offer = suggestion.getText(); String offer = suggestion.getText();

Datei anzeigen

@ -178,9 +178,9 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
this.connectionPhase = connection.getType().getInitialClientPhase(); this.connectionPhase = connection.getType().getInitialClientPhase();
this.onlineMode = onlineMode; this.onlineMode = onlineMode;
if (connection.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_19_3) >= 0) { if (connection.getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_19_3)) {
this.tabList = new VelocityTabList(this); this.tabList = new VelocityTabList(this);
} else if (connection.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { } else if (connection.getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_8)) {
this.tabList = new KeyedVelocityTabList(this, server); this.tabList = new KeyedVelocityTabList(this, server);
} else { } else {
this.tabList = new VelocityTabListLegacy(this, server); this.tabList = new VelocityTabListLegacy(this, server);
@ -371,7 +371,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
Component translated = translateMessage(message); Component translated = translateMessage(message);
ProtocolVersion playerVersion = getProtocolVersion(); ProtocolVersion playerVersion = getProtocolVersion();
if (playerVersion.compareTo(ProtocolVersion.MINECRAFT_1_11) >= 0) { if (playerVersion.noLessThan(ProtocolVersion.MINECRAFT_1_11)) {
// Use the title packet instead. // Use the title packet instead.
GenericTitlePacket pkt = GenericTitlePacket.constructTitlePacket( GenericTitlePacket pkt = GenericTitlePacket.constructTitlePacket(
GenericTitlePacket.ActionType.SET_ACTION_BAR, playerVersion); GenericTitlePacket.ActionType.SET_ACTION_BAR, playerVersion);
@ -416,7 +416,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
Component translatedFooter = translateMessage(footer); Component translatedFooter = translateMessage(footer);
this.playerListHeader = translatedHeader; this.playerListHeader = translatedHeader;
this.playerListFooter = translatedFooter; this.playerListFooter = translatedFooter;
if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { if (this.getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_8)) {
this.connection.write(HeaderAndFooterPacket.create( this.connection.write(HeaderAndFooterPacket.create(
translatedHeader, translatedFooter, this.getProtocolVersion())); translatedHeader, translatedFooter, this.getProtocolVersion()));
} }
@ -424,7 +424,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
@Override @Override
public void showTitle(net.kyori.adventure.title.@NonNull Title title) { public void showTitle(net.kyori.adventure.title.@NonNull Title title) {
if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { if (this.getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_8)) {
GenericTitlePacket timesPkt = GenericTitlePacket.constructTitlePacket( GenericTitlePacket timesPkt = GenericTitlePacket.constructTitlePacket(
GenericTitlePacket.ActionType.SET_TIMES, this.getProtocolVersion()); GenericTitlePacket.ActionType.SET_TIMES, this.getProtocolVersion());
net.kyori.adventure.title.Title.Times times = title.times(); net.kyori.adventure.title.Title.Times times = title.times();
@ -460,7 +460,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
throw new NullPointerException("value"); throw new NullPointerException("value");
} }
if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) < 0) { if (this.getProtocolVersion().lessThan(ProtocolVersion.MINECRAFT_1_8)) {
return; return;
} }
@ -491,7 +491,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
@Override @Override
public void clearTitle() { public void clearTitle() {
if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { if (this.getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_8)) {
connection.write(GenericTitlePacket.constructTitlePacket( connection.write(GenericTitlePacket.constructTitlePacket(
GenericTitlePacket.ActionType.HIDE, this.getProtocolVersion())); GenericTitlePacket.ActionType.HIDE, this.getProtocolVersion()));
} }
@ -499,7 +499,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
@Override @Override
public void resetTitle() { public void resetTitle() {
if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { if (this.getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_8)) {
connection.write(GenericTitlePacket.constructTitlePacket( connection.write(GenericTitlePacket.constructTitlePacket(
GenericTitlePacket.ActionType.RESET, this.getProtocolVersion())); GenericTitlePacket.ActionType.RESET, this.getProtocolVersion()));
} }
@ -507,14 +507,14 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
@Override @Override
public void hideBossBar(@NonNull BossBar bar) { public void hideBossBar(@NonNull BossBar bar) {
if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_9) >= 0) { if (this.getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_9)) {
this.server.getBossBarManager().removeBossBar(this, bar); this.server.getBossBarManager().removeBossBar(this, bar);
} }
} }
@Override @Override
public void showBossBar(@NonNull BossBar bar) { public void showBossBar(@NonNull BossBar bar) {
if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_9) >= 0) { if (this.getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_9)) {
this.server.getBossBarManager().addBossBar(this, bar); this.server.getBossBarManager().addBossBar(this, bar);
} }
} }
@ -542,7 +542,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
@Override @Override
public void clearPlayerListHeaderAndFooter() { public void clearPlayerListHeaderAndFooter() {
clearPlayerListHeaderAndFooterSilent(); clearPlayerListHeaderAndFooterSilent();
if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { if (this.getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_8)) {
this.connection.write(HeaderAndFooterPacket.reset(this.getProtocolVersion())); this.connection.write(HeaderAndFooterPacket.reset(this.getProtocolVersion()));
} }
} }
@ -942,7 +942,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
Preconditions.checkArgument(input.length() <= LegacyChatPacket.MAX_SERVERBOUND_MESSAGE_LENGTH, Preconditions.checkArgument(input.length() <= LegacyChatPacket.MAX_SERVERBOUND_MESSAGE_LENGTH,
"input cannot be greater than " + LegacyChatPacket.MAX_SERVERBOUND_MESSAGE_LENGTH "input cannot be greater than " + LegacyChatPacket.MAX_SERVERBOUND_MESSAGE_LENGTH
+ " characters in length"); + " characters in length");
if (getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0) { if (getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_19)) {
this.chatQueue.hijack(getChatBuilderFactory().builder().asPlayer(this).message(input), this.chatQueue.hijack(getChatBuilderFactory().builder().asPlayer(this).message(input),
(instant, item) -> { (instant, item) -> {
item.setTimestamp(instant); item.setTimestamp(instant);
@ -968,7 +968,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
@Override @Override
public void sendResourcePackOffer(ResourcePackInfo packInfo) { public void sendResourcePackOffer(ResourcePackInfo packInfo) {
if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { if (this.getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_8)) {
Preconditions.checkNotNull(packInfo, "packInfo"); Preconditions.checkNotNull(packInfo, "packInfo");
queueResourcePack(packInfo); queueResourcePack(packInfo);
} }
@ -996,7 +996,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
while (!outstandingResourcePacks.isEmpty()) { while (!outstandingResourcePacks.isEmpty()) {
queued = outstandingResourcePacks.peek(); queued = outstandingResourcePacks.peek();
if (queued.getShouldForce() && getProtocolVersion() if (queued.getShouldForce() && getProtocolVersion()
.compareTo(ProtocolVersion.MINECRAFT_1_17) >= 0) { .noLessThan(ProtocolVersion.MINECRAFT_1_17)) {
break; break;
} }
onResourcePackResponse(PlayerResourcePackStatusEvent.Status.DECLINED); onResourcePackResponse(PlayerResourcePackStatusEvent.Status.DECLINED);
@ -1068,7 +1068,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
if (event.getStatus() == PlayerResourcePackStatusEvent.Status.DECLINED if (event.getStatus() == PlayerResourcePackStatusEvent.Status.DECLINED
&& event.getPackInfo() != null && event.getPackInfo().getShouldForce() && event.getPackInfo() != null && event.getPackInfo().getShouldForce()
&& (!event.isOverwriteKick() || event.getPlayer() && (!event.isOverwriteKick() || event.getPlayer()
.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_17) >= 0) .getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_17))
) { ) {
event.getPlayer().disconnect(Component event.getPlayer().disconnect(Component
.translatable("multiplayer.requiredTexturePrompt.disconnect")); .translatable("multiplayer.requiredTexturePrompt.disconnect"));

Datei anzeigen

@ -141,7 +141,7 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler {
// If the proxy is configured for modern forwarding, we must deny connections from 1.12.2 // If the proxy is configured for modern forwarding, we must deny connections from 1.12.2
// and lower, otherwise IP information will never get forwarded. // and lower, otherwise IP information will never get forwarded.
if (server.getConfiguration().getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN if (server.getConfiguration().getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN
&& handshake.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_13) < 0) { && handshake.getProtocolVersion().lessThan(ProtocolVersion.MINECRAFT_1_13)) {
ic.disconnectQuietly( ic.disconnectQuietly(
Component.translatable("velocity.error.modern-forwarding-needs-new-client")); Component.translatable("velocity.error.modern-forwarding-needs-new-client"));
return; return;
@ -155,14 +155,14 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler {
private ConnectionType getHandshakeConnectionType(HandshakePacket handshake) { private ConnectionType getHandshakeConnectionType(HandshakePacket handshake) {
if (handshake.getServerAddress().contains(ModernForgeConstants.MODERN_FORGE_TOKEN) if (handshake.getServerAddress().contains(ModernForgeConstants.MODERN_FORGE_TOKEN)
&& handshake.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_20_2) >= 0) { && handshake.getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_20_2)) {
return new ModernForgeConnectionType(handshake.getServerAddress()); return new ModernForgeConnectionType(handshake.getServerAddress());
} }
// Determine if we're using Forge (1.8 to 1.12, may not be the case in 1.13). // Determine if we're using Forge (1.8 to 1.12, may not be the case in 1.13).
if (handshake.getServerAddress().endsWith(LegacyForgeConstants.HANDSHAKE_HOSTNAME_TOKEN) if (handshake.getServerAddress().endsWith(LegacyForgeConstants.HANDSHAKE_HOSTNAME_TOKEN)
&& handshake.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_13) < 0) { && handshake.getProtocolVersion().lessThan(ProtocolVersion.MINECRAFT_1_13)) {
return ConnectionTypes.LEGACY_FORGE; return ConnectionTypes.LEGACY_FORGE;
} else if (handshake.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_7_6) <= 0) { } else if (handshake.getProtocolVersion().noGreaterThan(ProtocolVersion.MINECRAFT_1_7_6)) {
// 1.7 Forge will not notify us during handshake. UNDETERMINED will listen for incoming // 1.7 Forge will not notify us during handshake. UNDETERMINED will listen for incoming
// forge handshake attempts. Also sends a reset handshake packet on every transition. // forge handshake attempts. Also sends a reset handshake packet on every transition.
return ConnectionTypes.UNDETERMINED_17; return ConnectionTypes.UNDETERMINED_17;

Datei anzeigen

@ -111,9 +111,9 @@ public class InitialLoginSessionHandler implements MinecraftSessionHandler {
inbound.disconnect(Component.translatable("multiplayer.disconnect.invalid_public_key")); inbound.disconnect(Component.translatable("multiplayer.disconnect.invalid_public_key"));
return true; return true;
} }
} else if (mcConnection.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0 } else if (mcConnection.getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_19)
&& forceKeyAuthentication && forceKeyAuthentication
&& mcConnection.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_19_3) < 0) { && mcConnection.getProtocolVersion().lessThan(ProtocolVersion.MINECRAFT_1_19_3)) {
inbound.disconnect(Component.translatable("multiplayer.disconnect.missing_public_key")); inbound.disconnect(Component.translatable("multiplayer.disconnect.missing_public_key"));
return true; return true;
} }

Datei anzeigen

@ -92,7 +92,7 @@ public class LoginInboundConnection implements LoginPhaseConnection, KeyIdentifi
if (consumer == null) { if (consumer == null) {
throw new NullPointerException("consumer"); throw new NullPointerException("consumer");
} }
if (delegate.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_13) < 0) { if (delegate.getProtocolVersion().lessThan(ProtocolVersion.MINECRAFT_1_13)) {
throw new IllegalStateException("Login plugin messages can only be sent to clients running " throw new IllegalStateException("Login plugin messages can only be sent to clients running "
+ "Minecraft 1.13 and above"); + "Minecraft 1.13 and above");
} }

Datei anzeigen

@ -435,7 +435,7 @@ public enum ProtocolUtils {
public static BinaryTag readBinaryTag(ByteBuf buf, ProtocolVersion version, public static BinaryTag readBinaryTag(ByteBuf buf, ProtocolVersion version,
BinaryTagIO.Reader reader) { BinaryTagIO.Reader reader) {
BinaryTagType<?> type = BINARY_TAG_TYPES[buf.readByte()]; BinaryTagType<?> type = BINARY_TAG_TYPES[buf.readByte()];
if (version.compareTo(ProtocolVersion.MINECRAFT_1_20_2) < 0) { if (version.lessThan(ProtocolVersion.MINECRAFT_1_20_2)) {
buf.skipBytes(buf.readUnsignedShort()); buf.skipBytes(buf.readUnsignedShort());
} }
try { try {
@ -456,7 +456,7 @@ public enum ProtocolUtils {
BinaryTagType<T> type = (BinaryTagType<T>) tag.type(); BinaryTagType<T> type = (BinaryTagType<T>) tag.type();
buf.writeByte(type.id()); buf.writeByte(type.id());
try { try {
if (version.compareTo(ProtocolVersion.MINECRAFT_1_20_2) < 0) { if (version.lessThan(ProtocolVersion.MINECRAFT_1_20_2)) {
// Empty name // Empty name
buf.writeShort(0); buf.writeShort(0);
} }
@ -710,10 +710,10 @@ public enum ProtocolUtils {
* @return the appropriate {@link GsonComponentSerializer} * @return the appropriate {@link GsonComponentSerializer}
*/ */
public static GsonComponentSerializer getJsonChatSerializer(ProtocolVersion version) { public static GsonComponentSerializer getJsonChatSerializer(ProtocolVersion version) {
if (version.compareTo(ProtocolVersion.MINECRAFT_1_20_3) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_20_3)) {
return MODERN_SERIALIZER; return MODERN_SERIALIZER;
} }
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_16)) {
return PRE_1_20_3_SERIALIZER; return PRE_1_20_3_SERIALIZER;
} }
return PRE_1_16_SERIALIZER; return PRE_1_16_SERIALIZER;
@ -741,7 +741,7 @@ public enum ProtocolUtils {
long expiry = buf.readLong(); long expiry = buf.readLong();
byte[] key = ProtocolUtils.readByteArray(buf); byte[] key = ProtocolUtils.readByteArray(buf);
byte[] signature = ProtocolUtils.readByteArray(buf, 4096); byte[] signature = ProtocolUtils.readByteArray(buf, 4096);
IdentifiedKey.Revision revision = version.compareTo(ProtocolVersion.MINECRAFT_1_19) == 0 IdentifiedKey.Revision revision = version.noGreaterOrLessThan(ProtocolVersion.MINECRAFT_1_19)
? IdentifiedKey.Revision.GENERIC_V1 : IdentifiedKey.Revision.LINKED_V2; ? IdentifiedKey.Revision.GENERIC_V1 : IdentifiedKey.Revision.LINKED_V2;
return new IdentifiedKeyImpl(revision, key, expiry, signature); return new IdentifiedKeyImpl(revision, key, expiry, signature);
} }

Datei anzeigen

@ -669,7 +669,7 @@ public enum StateRegistry {
if (next != current) { if (next != current) {
throw new IllegalArgumentException("Cannot add a mapping after last valid mapping"); throw new IllegalArgumentException("Cannot add a mapping after last valid mapping");
} }
if (from.compareTo(lastValid) > 0) { if (from.greaterThan(lastValid)) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Last mapping version cannot be higher than highest mapping version"); "Last mapping version cannot be higher than highest mapping version");
} }
@ -679,7 +679,7 @@ public enum StateRegistry {
ProtocolVersion lastInList = lastValid != null ? lastValid : getLast(SUPPORTED_VERSIONS); ProtocolVersion lastInList = lastValid != null ? lastValid : getLast(SUPPORTED_VERSIONS);
if (from.compareTo(to) >= 0 && from != lastInList) { if (from.noLessThan(to) && from != lastInList) {
throw new IllegalArgumentException(String.format( throw new IllegalArgumentException(String.format(
"Next mapping version (%s) should be lower then current (%s)", to, from)); "Next mapping version (%s) should be lower then current (%s)", to, from));
} }

Datei anzeigen

@ -133,19 +133,19 @@ public class ClientSettingsPacket implements MinecraftPacket {
this.chatVisibility = ProtocolUtils.readVarInt(buf); this.chatVisibility = ProtocolUtils.readVarInt(buf);
this.chatColors = buf.readBoolean(); this.chatColors = buf.readBoolean();
if (version.compareTo(ProtocolVersion.MINECRAFT_1_7_6) <= 0) { if (version.noGreaterThan(ProtocolVersion.MINECRAFT_1_7_6)) {
this.difficulty = buf.readByte(); this.difficulty = buf.readByte();
} }
this.skinParts = buf.readUnsignedByte(); this.skinParts = buf.readUnsignedByte();
if (version.compareTo(ProtocolVersion.MINECRAFT_1_9) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_9)) {
this.mainHand = ProtocolUtils.readVarInt(buf); this.mainHand = ProtocolUtils.readVarInt(buf);
if (version.compareTo(ProtocolVersion.MINECRAFT_1_17) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_17)) {
this.chatFilteringEnabled = buf.readBoolean(); this.chatFilteringEnabled = buf.readBoolean();
if (version.compareTo(ProtocolVersion.MINECRAFT_1_18) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_18)) {
this.clientListingAllowed = buf.readBoolean(); this.clientListingAllowed = buf.readBoolean();
} }
} }
@ -162,19 +162,19 @@ public class ClientSettingsPacket implements MinecraftPacket {
ProtocolUtils.writeVarInt(buf, chatVisibility); ProtocolUtils.writeVarInt(buf, chatVisibility);
buf.writeBoolean(chatColors); buf.writeBoolean(chatColors);
if (version.compareTo(ProtocolVersion.MINECRAFT_1_7_6) <= 0) { if (version.noGreaterThan(ProtocolVersion.MINECRAFT_1_7_6)) {
buf.writeByte(difficulty); buf.writeByte(difficulty);
} }
buf.writeByte(skinParts); buf.writeByte(skinParts);
if (version.compareTo(ProtocolVersion.MINECRAFT_1_9) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_9)) {
ProtocolUtils.writeVarInt(buf, mainHand); ProtocolUtils.writeVarInt(buf, mainHand);
if (version.compareTo(ProtocolVersion.MINECRAFT_1_17) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_17)) {
buf.writeBoolean(chatFilteringEnabled); buf.writeBoolean(chatFilteringEnabled);
if (version.compareTo(ProtocolVersion.MINECRAFT_1_18) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_18)) {
buf.writeBoolean(clientListingAllowed); buf.writeBoolean(clientListingAllowed);
} }
} }

Datei anzeigen

@ -60,7 +60,7 @@ public class EncryptionRequestPacket implements MinecraftPacket {
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
this.serverId = ProtocolUtils.readString(buf, 20); this.serverId = ProtocolUtils.readString(buf, 20);
if (version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_8)) {
publicKey = ProtocolUtils.readByteArray(buf, 256); publicKey = ProtocolUtils.readByteArray(buf, 256);
verifyToken = ProtocolUtils.readByteArray(buf, 16); verifyToken = ProtocolUtils.readByteArray(buf, 16);
} else { } else {
@ -73,7 +73,7 @@ public class EncryptionRequestPacket implements MinecraftPacket {
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
ProtocolUtils.writeString(buf, this.serverId); ProtocolUtils.writeString(buf, this.serverId);
if (version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_8)) {
ProtocolUtils.writeByteArray(buf, publicKey); ProtocolUtils.writeByteArray(buf, publicKey);
ProtocolUtils.writeByteArray(buf, verifyToken); ProtocolUtils.writeByteArray(buf, verifyToken);
} else { } else {

Datei anzeigen

@ -64,17 +64,17 @@ public class EncryptionResponsePacket implements MinecraftPacket {
@Override @Override
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
if (version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_8)) {
this.sharedSecret = ProtocolUtils.readByteArray(buf, 128); this.sharedSecret = ProtocolUtils.readByteArray(buf, 128);
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0 if (version.noLessThan(ProtocolVersion.MINECRAFT_1_19)
&& version.compareTo(ProtocolVersion.MINECRAFT_1_19_3) < 0 && version.lessThan(ProtocolVersion.MINECRAFT_1_19_3)
&& !buf.readBoolean()) { && !buf.readBoolean()) {
salt = buf.readLong(); salt = buf.readLong();
} }
this.verifyToken = ProtocolUtils.readByteArray(buf, this.verifyToken = ProtocolUtils.readByteArray(buf,
version.compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0 ? 256 : 128); version.noLessThan(ProtocolVersion.MINECRAFT_1_19) ? 256 : 128);
} else { } else {
this.sharedSecret = ProtocolUtils.readByteArray17(buf); this.sharedSecret = ProtocolUtils.readByteArray17(buf);
this.verifyToken = ProtocolUtils.readByteArray17(buf); this.verifyToken = ProtocolUtils.readByteArray17(buf);
@ -83,10 +83,10 @@ public class EncryptionResponsePacket implements MinecraftPacket {
@Override @Override
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
if (version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_8)) {
ProtocolUtils.writeByteArray(buf, sharedSecret); ProtocolUtils.writeByteArray(buf, sharedSecret);
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0 if (version.noLessThan(ProtocolVersion.MINECRAFT_1_19)
&& version.compareTo(ProtocolVersion.MINECRAFT_1_19_3) < 0) { && version.lessThan(ProtocolVersion.MINECRAFT_1_19_3)) {
if (salt != null) { if (salt != null) {
buf.writeBoolean(false); buf.writeBoolean(false);
buf.writeLong(salt); buf.writeLong(salt);
@ -111,10 +111,10 @@ public class EncryptionResponsePacket implements MinecraftPacket {
// It turns out these come out to the same length, whether we're talking >=1.8 or not. // It turns out these come out to the same length, whether we're talking >=1.8 or not.
// The length prefix always winds up being 2 bytes. // The length prefix always winds up being 2 bytes.
int base = 256 + 2 + 2; int base = 256 + 2 + 2;
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19_3) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_19_3)) {
return base + 128; return base + 128;
} }
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_19)) {
// Verify token is twice as long on 1.19+ // Verify token is twice as long on 1.19+
// Additional 1 byte for left <> right and 8 bytes for salt // Additional 1 byte for left <> right and 8 bytes for salt
base += 128 + 8 + 1; base += 128 + 8 + 1;
@ -125,7 +125,7 @@ public class EncryptionResponsePacket implements MinecraftPacket {
@Override @Override
public int expectedMinLength(ByteBuf buf, Direction direction, ProtocolVersion version) { public int expectedMinLength(ByteBuf buf, Direction direction, ProtocolVersion version) {
int base = expectedMaxLength(buf, direction, version); int base = expectedMaxLength(buf, direction, version);
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_19)) {
// These are "optional" // These are "optional"
base -= 128 + 8; base -= 128 + 8;
} }

Datei anzeigen

@ -200,10 +200,10 @@ public class JoinGamePacket implements MinecraftPacket {
@Override @Override
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
if (version.compareTo(ProtocolVersion.MINECRAFT_1_20_2) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_20_2)) {
// haha funny, they made 1.20.2 more complicated // haha funny, they made 1.20.2 more complicated
this.decode1202Up(buf, version); this.decode1202Up(buf, version);
} else if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) { } else if (version.noLessThan(ProtocolVersion.MINECRAFT_1_16)) {
// Minecraft 1.16 and above have significantly more complicated logic for reading this packet, // Minecraft 1.16 and above have significantly more complicated logic for reading this packet,
// so separate it out. // so separate it out.
this.decode116Up(buf, version); this.decode116Up(buf, version);
@ -218,33 +218,33 @@ public class JoinGamePacket implements MinecraftPacket {
this.isHardcore = (this.gamemode & 0x08) != 0; this.isHardcore = (this.gamemode & 0x08) != 0;
this.gamemode &= ~0x08; this.gamemode &= ~0x08;
if (version.compareTo(ProtocolVersion.MINECRAFT_1_9_1) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_9_1)) {
this.dimension = buf.readInt(); this.dimension = buf.readInt();
} else { } else {
this.dimension = buf.readByte(); this.dimension = buf.readByte();
} }
if (version.compareTo(ProtocolVersion.MINECRAFT_1_13_2) <= 0) { if (version.noGreaterThan(ProtocolVersion.MINECRAFT_1_13_2)) {
this.difficulty = buf.readUnsignedByte(); this.difficulty = buf.readUnsignedByte();
} }
if (version.compareTo(ProtocolVersion.MINECRAFT_1_15) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_15)) {
this.partialHashedSeed = buf.readLong(); this.partialHashedSeed = buf.readLong();
} }
this.maxPlayers = buf.readUnsignedByte(); this.maxPlayers = buf.readUnsignedByte();
this.levelType = ProtocolUtils.readString(buf, 16); this.levelType = ProtocolUtils.readString(buf, 16);
if (version.compareTo(ProtocolVersion.MINECRAFT_1_14) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_14)) {
this.viewDistance = ProtocolUtils.readVarInt(buf); this.viewDistance = ProtocolUtils.readVarInt(buf);
} }
if (version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_8)) {
this.reducedDebugInfo = buf.readBoolean(); this.reducedDebugInfo = buf.readBoolean();
} }
if (version.compareTo(ProtocolVersion.MINECRAFT_1_15) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_15)) {
this.showRespawnScreen = buf.readBoolean(); this.showRespawnScreen = buf.readBoolean();
} }
} }
private void decode116Up(ByteBuf buf, ProtocolVersion version) { private void decode116Up(ByteBuf buf, ProtocolVersion version) {
this.entityId = buf.readInt(); this.entityId = buf.readInt();
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_16_2)) {
this.isHardcore = buf.readBoolean(); this.isHardcore = buf.readBoolean();
this.gamemode = buf.readByte(); this.gamemode = buf.readByte();
} else { } else {
@ -258,8 +258,8 @@ public class JoinGamePacket implements MinecraftPacket {
this.registry = ProtocolUtils.readCompoundTag(buf, version, JOINGAME_READER); this.registry = ProtocolUtils.readCompoundTag(buf, version, JOINGAME_READER);
String dimensionIdentifier; String dimensionIdentifier;
String levelName = null; String levelName = null;
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0 if (version.noLessThan(ProtocolVersion.MINECRAFT_1_16_2)
&& version.compareTo(ProtocolVersion.MINECRAFT_1_19) < 0) { && version.lessThan(ProtocolVersion.MINECRAFT_1_19)) {
this.currentDimensionData = ProtocolUtils.readCompoundTag(buf, version, JOINGAME_READER); this.currentDimensionData = ProtocolUtils.readCompoundTag(buf, version, JOINGAME_READER);
dimensionIdentifier = ProtocolUtils.readString(buf); dimensionIdentifier = ProtocolUtils.readString(buf);
} else { } else {
@ -268,14 +268,14 @@ public class JoinGamePacket implements MinecraftPacket {
} }
this.partialHashedSeed = buf.readLong(); this.partialHashedSeed = buf.readLong();
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_16_2)) {
this.maxPlayers = ProtocolUtils.readVarInt(buf); this.maxPlayers = ProtocolUtils.readVarInt(buf);
} else { } else {
this.maxPlayers = buf.readUnsignedByte(); this.maxPlayers = buf.readUnsignedByte();
} }
this.viewDistance = ProtocolUtils.readVarInt(buf); this.viewDistance = ProtocolUtils.readVarInt(buf);
if (version.compareTo(ProtocolVersion.MINECRAFT_1_18) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_18)) {
this.simulationDistance = ProtocolUtils.readVarInt(buf); this.simulationDistance = ProtocolUtils.readVarInt(buf);
} }
@ -287,11 +287,11 @@ public class JoinGamePacket implements MinecraftPacket {
this.dimensionInfo = new DimensionInfo(dimensionIdentifier, levelName, isFlat, isDebug); this.dimensionInfo = new DimensionInfo(dimensionIdentifier, levelName, isFlat, isDebug);
// optional death location // optional death location
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0 && buf.readBoolean()) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_19) && buf.readBoolean()) {
this.lastDeathPosition = Pair.of(ProtocolUtils.readString(buf), buf.readLong()); this.lastDeathPosition = Pair.of(ProtocolUtils.readString(buf), buf.readLong());
} }
if (version.compareTo(ProtocolVersion.MINECRAFT_1_20) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_20)) {
this.portalCooldown = ProtocolUtils.readVarInt(buf); this.portalCooldown = ProtocolUtils.readVarInt(buf);
} }
} }
@ -332,10 +332,10 @@ public class JoinGamePacket implements MinecraftPacket {
@Override @Override
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
if (version.compareTo(ProtocolVersion.MINECRAFT_1_20_2) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_20_2)) {
// haha funny, they made 1.20.2 more complicated // haha funny, they made 1.20.2 more complicated
this.encode1202Up(buf, version); this.encode1202Up(buf, version);
} else if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) { } else if (version.noLessThan(ProtocolVersion.MINECRAFT_1_16)) {
// Minecraft 1.16 and above have significantly more complicated logic for reading this packet, // Minecraft 1.16 and above have significantly more complicated logic for reading this packet,
// so separate it out. // so separate it out.
this.encode116Up(buf, version); this.encode116Up(buf, version);
@ -346,21 +346,21 @@ public class JoinGamePacket implements MinecraftPacket {
private void encodeLegacy(ByteBuf buf, ProtocolVersion version) { private void encodeLegacy(ByteBuf buf, ProtocolVersion version) {
buf.writeInt(entityId); buf.writeInt(entityId);
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_16_2)) {
buf.writeBoolean(isHardcore); buf.writeBoolean(isHardcore);
buf.writeByte(gamemode); buf.writeByte(gamemode);
} else { } else {
buf.writeByte(isHardcore ? gamemode | 0x8 : gamemode); buf.writeByte(isHardcore ? gamemode | 0x8 : gamemode);
} }
if (version.compareTo(ProtocolVersion.MINECRAFT_1_9_1) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_9_1)) {
buf.writeInt(dimension); buf.writeInt(dimension);
} else { } else {
buf.writeByte(dimension); buf.writeByte(dimension);
} }
if (version.compareTo(ProtocolVersion.MINECRAFT_1_13_2) <= 0) { if (version.noGreaterThan(ProtocolVersion.MINECRAFT_1_13_2)) {
buf.writeByte(difficulty); buf.writeByte(difficulty);
} }
if (version.compareTo(ProtocolVersion.MINECRAFT_1_15) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_15)) {
buf.writeLong(partialHashedSeed); buf.writeLong(partialHashedSeed);
} }
buf.writeByte(maxPlayers); buf.writeByte(maxPlayers);
@ -368,20 +368,20 @@ public class JoinGamePacket implements MinecraftPacket {
throw new IllegalStateException("No level type specified."); throw new IllegalStateException("No level type specified.");
} }
ProtocolUtils.writeString(buf, levelType); ProtocolUtils.writeString(buf, levelType);
if (version.compareTo(ProtocolVersion.MINECRAFT_1_14) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_14)) {
ProtocolUtils.writeVarInt(buf, viewDistance); ProtocolUtils.writeVarInt(buf, viewDistance);
} }
if (version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_8)) {
buf.writeBoolean(reducedDebugInfo); buf.writeBoolean(reducedDebugInfo);
} }
if (version.compareTo(ProtocolVersion.MINECRAFT_1_15) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_15)) {
buf.writeBoolean(showRespawnScreen); buf.writeBoolean(showRespawnScreen);
} }
} }
private void encode116Up(ByteBuf buf, ProtocolVersion version) { private void encode116Up(ByteBuf buf, ProtocolVersion version) {
buf.writeInt(entityId); buf.writeInt(entityId);
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_16_2)) {
buf.writeBoolean(isHardcore); buf.writeBoolean(isHardcore);
buf.writeByte(gamemode); buf.writeByte(gamemode);
} else { } else {
@ -391,8 +391,8 @@ public class JoinGamePacket implements MinecraftPacket {
ProtocolUtils.writeStringArray(buf, levelNames.toArray(String[]::new)); ProtocolUtils.writeStringArray(buf, levelNames.toArray(String[]::new));
ProtocolUtils.writeBinaryTag(buf, version, this.registry); ProtocolUtils.writeBinaryTag(buf, version, this.registry);
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0 if (version.noLessThan(ProtocolVersion.MINECRAFT_1_16_2)
&& version.compareTo(ProtocolVersion.MINECRAFT_1_19) < 0) { && version.lessThan(ProtocolVersion.MINECRAFT_1_19)) {
ProtocolUtils.writeBinaryTag(buf, version, currentDimensionData); ProtocolUtils.writeBinaryTag(buf, version, currentDimensionData);
ProtocolUtils.writeString(buf, dimensionInfo.getRegistryIdentifier()); ProtocolUtils.writeString(buf, dimensionInfo.getRegistryIdentifier());
} else { } else {
@ -401,14 +401,14 @@ public class JoinGamePacket implements MinecraftPacket {
} }
buf.writeLong(partialHashedSeed); buf.writeLong(partialHashedSeed);
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_16_2)) {
ProtocolUtils.writeVarInt(buf, maxPlayers); ProtocolUtils.writeVarInt(buf, maxPlayers);
} else { } else {
buf.writeByte(maxPlayers); buf.writeByte(maxPlayers);
} }
ProtocolUtils.writeVarInt(buf, viewDistance); ProtocolUtils.writeVarInt(buf, viewDistance);
if (version.compareTo(ProtocolVersion.MINECRAFT_1_18) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_18)) {
ProtocolUtils.writeVarInt(buf, simulationDistance); ProtocolUtils.writeVarInt(buf, simulationDistance);
} }
@ -419,7 +419,7 @@ public class JoinGamePacket implements MinecraftPacket {
buf.writeBoolean(dimensionInfo.isFlat()); buf.writeBoolean(dimensionInfo.isFlat());
// optional death location // optional death location
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_19)) {
if (lastDeathPosition != null) { if (lastDeathPosition != null) {
buf.writeBoolean(true); buf.writeBoolean(true);
ProtocolUtils.writeString(buf, lastDeathPosition.key()); ProtocolUtils.writeString(buf, lastDeathPosition.key());
@ -429,7 +429,7 @@ public class JoinGamePacket implements MinecraftPacket {
} }
} }
if (version.compareTo(ProtocolVersion.MINECRAFT_1_20) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_20)) {
ProtocolUtils.writeVarInt(buf, portalCooldown); ProtocolUtils.writeVarInt(buf, portalCooldown);
} }
} }

Datei anzeigen

@ -44,9 +44,9 @@ public class KeepAlivePacket implements MinecraftPacket {
@Override @Override
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
if (version.compareTo(ProtocolVersion.MINECRAFT_1_12_2) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_12_2)) {
randomId = buf.readLong(); randomId = buf.readLong();
} else if (version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { } else if (version.noLessThan(ProtocolVersion.MINECRAFT_1_8)) {
randomId = ProtocolUtils.readVarInt(buf); randomId = ProtocolUtils.readVarInt(buf);
} else { } else {
randomId = buf.readInt(); randomId = buf.readInt();
@ -55,9 +55,9 @@ public class KeepAlivePacket implements MinecraftPacket {
@Override @Override
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
if (version.compareTo(ProtocolVersion.MINECRAFT_1_12_2) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_12_2)) {
buf.writeLong(randomId); buf.writeLong(randomId);
} else if (version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { } else if (version.noLessThan(ProtocolVersion.MINECRAFT_1_8)) {
ProtocolUtils.writeVarInt(buf, (int) randomId); ProtocolUtils.writeVarInt(buf, (int) randomId);
} else { } else {
buf.writeInt((int) randomId); buf.writeInt((int) randomId);

Datei anzeigen

@ -61,7 +61,7 @@ public class LegacyPlayerListItemPacket implements MinecraftPacket {
@Override @Override
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
if (version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_8)) {
action = ProtocolUtils.readVarInt(buf); action = ProtocolUtils.readVarInt(buf);
int length = ProtocolUtils.readVarInt(buf); int length = ProtocolUtils.readVarInt(buf);
@ -76,7 +76,7 @@ public class LegacyPlayerListItemPacket implements MinecraftPacket {
item.setLatency(ProtocolUtils.readVarInt(buf)); item.setLatency(ProtocolUtils.readVarInt(buf));
item.setDisplayName(readOptionalComponent(buf, version)); item.setDisplayName(readOptionalComponent(buf, version));
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_19)) {
if (buf.readBoolean()) { if (buf.readBoolean()) {
item.setPlayerKey(ProtocolUtils.readPlayerKey(version, buf)); item.setPlayerKey(ProtocolUtils.readPlayerKey(version, buf));
} }
@ -117,7 +117,7 @@ public class LegacyPlayerListItemPacket implements MinecraftPacket {
@Override @Override
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
if (version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_8)) {
ProtocolUtils.writeVarInt(buf, action); ProtocolUtils.writeVarInt(buf, action);
ProtocolUtils.writeVarInt(buf, items.size()); ProtocolUtils.writeVarInt(buf, items.size());
for (Item item : items) { for (Item item : items) {
@ -132,7 +132,7 @@ public class LegacyPlayerListItemPacket implements MinecraftPacket {
ProtocolUtils.writeVarInt(buf, item.getGameMode()); ProtocolUtils.writeVarInt(buf, item.getGameMode());
ProtocolUtils.writeVarInt(buf, item.getLatency()); ProtocolUtils.writeVarInt(buf, item.getLatency());
writeDisplayName(buf, item.getDisplayName(), version); writeDisplayName(buf, item.getDisplayName(), version);
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_19)) {
if (item.getPlayerKey() != null) { if (item.getPlayerKey() != null) {
buf.writeBoolean(true); buf.writeBoolean(true);
ProtocolUtils.writePlayerKey(buf, item.getPlayerKey()); ProtocolUtils.writePlayerKey(buf, item.getPlayerKey());

Datei anzeigen

@ -64,10 +64,10 @@ public class PluginMessagePacket extends DeferredByteBufHolder implements Minecr
@Override @Override
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
this.channel = ProtocolUtils.readString(buf); this.channel = ProtocolUtils.readString(buf);
if (version.compareTo(ProtocolVersion.MINECRAFT_1_13) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_13)) {
this.channel = transformLegacyToModernChannel(this.channel); this.channel = transformLegacyToModernChannel(this.channel);
} }
if (version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_8)) {
this.replace(buf.readRetainedSlice(buf.readableBytes())); this.replace(buf.readRetainedSlice(buf.readableBytes()));
} else { } else {
this.replace(ProtocolUtils.readRetainedByteBufSlice17(buf)); this.replace(ProtocolUtils.readRetainedByteBufSlice17(buf));
@ -86,12 +86,12 @@ public class PluginMessagePacket extends DeferredByteBufHolder implements Minecr
+ " freed too many times."); + " freed too many times.");
} }
if (version.compareTo(ProtocolVersion.MINECRAFT_1_13) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_13)) {
ProtocolUtils.writeString(buf, transformLegacyToModernChannel(this.channel)); ProtocolUtils.writeString(buf, transformLegacyToModernChannel(this.channel));
} else { } else {
ProtocolUtils.writeString(buf, this.channel); ProtocolUtils.writeString(buf, this.channel);
} }
if (version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_8)) {
buf.writeBytes(content()); buf.writeBytes(content());
} else { } else {
ProtocolUtils.writeByteBuf17(content(), buf, true); // True for Forge support ProtocolUtils.writeByteBuf17(content(), buf, true); // True for Forge support

Datei anzeigen

@ -86,12 +86,12 @@ public class ResourcePackRequestPacket implements MinecraftPacket {
@Override @Override
public void decode(ByteBuf buf, Direction direction, ProtocolVersion protocolVersion) { public void decode(ByteBuf buf, Direction direction, ProtocolVersion protocolVersion) {
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_20_3) >= 0) { if (protocolVersion.noLessThan(ProtocolVersion.MINECRAFT_1_20_3)) {
this.id = ProtocolUtils.readUuid(buf); this.id = ProtocolUtils.readUuid(buf);
} }
this.url = ProtocolUtils.readString(buf); this.url = ProtocolUtils.readString(buf);
this.hash = ProtocolUtils.readString(buf); this.hash = ProtocolUtils.readString(buf);
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_17) >= 0) { if (protocolVersion.noLessThan(ProtocolVersion.MINECRAFT_1_17)) {
this.isRequired = buf.readBoolean(); this.isRequired = buf.readBoolean();
if (buf.readBoolean()) { if (buf.readBoolean()) {
this.prompt = ComponentHolder.read(buf, protocolVersion); this.prompt = ComponentHolder.read(buf, protocolVersion);
@ -103,7 +103,7 @@ public class ResourcePackRequestPacket implements MinecraftPacket {
@Override @Override
public void encode(ByteBuf buf, Direction direction, ProtocolVersion protocolVersion) { public void encode(ByteBuf buf, Direction direction, ProtocolVersion protocolVersion) {
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_20_3) >= 0) { if (protocolVersion.noLessThan(ProtocolVersion.MINECRAFT_1_20_3)) {
if (id == null) { if (id == null) {
throw new IllegalStateException("Resource pack id not set yet!"); throw new IllegalStateException("Resource pack id not set yet!");
} }
@ -114,7 +114,7 @@ public class ResourcePackRequestPacket implements MinecraftPacket {
} }
ProtocolUtils.writeString(buf, url); ProtocolUtils.writeString(buf, url);
ProtocolUtils.writeString(buf, hash); ProtocolUtils.writeString(buf, hash);
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_17) >= 0) { if (protocolVersion.noLessThan(ProtocolVersion.MINECRAFT_1_17)) {
buf.writeBoolean(isRequired); buf.writeBoolean(isRequired);
if (prompt != null) { if (prompt != null) {
buf.writeBoolean(true); buf.writeBoolean(true);

Datei anzeigen

@ -56,10 +56,10 @@ public class ResourcePackResponsePacket implements MinecraftPacket {
@Override @Override
public void decode(ByteBuf buf, Direction direction, ProtocolVersion protocolVersion) { public void decode(ByteBuf buf, Direction direction, ProtocolVersion protocolVersion) {
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_20_3) >= 0) { if (protocolVersion.noLessThan(ProtocolVersion.MINECRAFT_1_20_3)) {
this.id = ProtocolUtils.readUuid(buf); this.id = ProtocolUtils.readUuid(buf);
} }
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_9_4) <= 0) { if (protocolVersion.noGreaterThan(ProtocolVersion.MINECRAFT_1_9_4)) {
this.hash = ProtocolUtils.readString(buf); this.hash = ProtocolUtils.readString(buf);
} }
this.status = Status.values()[ProtocolUtils.readVarInt(buf)]; this.status = Status.values()[ProtocolUtils.readVarInt(buf)];
@ -67,10 +67,10 @@ public class ResourcePackResponsePacket implements MinecraftPacket {
@Override @Override
public void encode(ByteBuf buf, Direction direction, ProtocolVersion protocolVersion) { public void encode(ByteBuf buf, Direction direction, ProtocolVersion protocolVersion) {
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_20_3) >= 0) { if (protocolVersion.noLessThan(ProtocolVersion.MINECRAFT_1_20_3)) {
ProtocolUtils.writeUuid(buf, id); ProtocolUtils.writeUuid(buf, id);
} }
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_9_4) <= 0) { if (protocolVersion.noGreaterThan(ProtocolVersion.MINECRAFT_1_9_4)) {
ProtocolUtils.writeString(buf, hash); ProtocolUtils.writeString(buf, hash);
} }
ProtocolUtils.writeVarInt(buf, status.ordinal()); ProtocolUtils.writeVarInt(buf, status.ordinal());

Datei anzeigen

@ -162,9 +162,9 @@ public class RespawnPacket implements MinecraftPacket {
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
String dimensionIdentifier = null; String dimensionIdentifier = null;
String levelName = null; String levelName = null;
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_16)) {
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0 if (version.noLessThan(ProtocolVersion.MINECRAFT_1_16_2)
&& version.compareTo(ProtocolVersion.MINECRAFT_1_19) < 0) { && version.lessThan(ProtocolVersion.MINECRAFT_1_19)) {
this.currentDimensionData = ProtocolUtils.readCompoundTag(buf, version, BinaryTagIO.reader()); this.currentDimensionData = ProtocolUtils.readCompoundTag(buf, version, BinaryTagIO.reader());
dimensionIdentifier = ProtocolUtils.readString(buf); dimensionIdentifier = ProtocolUtils.readString(buf);
} else { } else {
@ -174,42 +174,42 @@ public class RespawnPacket implements MinecraftPacket {
} else { } else {
this.dimension = buf.readInt(); this.dimension = buf.readInt();
} }
if (version.compareTo(ProtocolVersion.MINECRAFT_1_13_2) <= 0) { if (version.noGreaterThan(ProtocolVersion.MINECRAFT_1_13_2)) {
this.difficulty = buf.readUnsignedByte(); this.difficulty = buf.readUnsignedByte();
} }
if (version.compareTo(ProtocolVersion.MINECRAFT_1_15) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_15)) {
this.partialHashedSeed = buf.readLong(); this.partialHashedSeed = buf.readLong();
} }
this.gamemode = buf.readByte(); this.gamemode = buf.readByte();
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_16)) {
this.previousGamemode = buf.readByte(); this.previousGamemode = buf.readByte();
boolean isDebug = buf.readBoolean(); boolean isDebug = buf.readBoolean();
boolean isFlat = buf.readBoolean(); boolean isFlat = buf.readBoolean();
this.dimensionInfo = new DimensionInfo(dimensionIdentifier, levelName, isFlat, isDebug); this.dimensionInfo = new DimensionInfo(dimensionIdentifier, levelName, isFlat, isDebug);
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19_3) < 0) { if (version.lessThan(ProtocolVersion.MINECRAFT_1_19_3)) {
this.dataToKeep = (byte) (buf.readBoolean() ? 1 : 0); this.dataToKeep = (byte) (buf.readBoolean() ? 1 : 0);
} else if (version.compareTo(ProtocolVersion.MINECRAFT_1_20_2) < 0) { } else if (version.lessThan(ProtocolVersion.MINECRAFT_1_20_2)) {
this.dataToKeep = buf.readByte(); this.dataToKeep = buf.readByte();
} }
} else { } else {
this.levelType = ProtocolUtils.readString(buf, 16); this.levelType = ProtocolUtils.readString(buf, 16);
} }
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0 && buf.readBoolean()) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_19) && buf.readBoolean()) {
this.lastDeathPosition = Pair.of(ProtocolUtils.readString(buf), buf.readLong()); this.lastDeathPosition = Pair.of(ProtocolUtils.readString(buf), buf.readLong());
} }
if (version.compareTo(ProtocolVersion.MINECRAFT_1_20) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_20)) {
this.portalCooldown = ProtocolUtils.readVarInt(buf); this.portalCooldown = ProtocolUtils.readVarInt(buf);
} }
if (version.compareTo(ProtocolVersion.MINECRAFT_1_20_2) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_20_2)) {
this.dataToKeep = buf.readByte(); this.dataToKeep = buf.readByte();
} }
} }
@Override @Override
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_16)) {
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0 if (version.noLessThan(ProtocolVersion.MINECRAFT_1_16_2)
&& version.compareTo(ProtocolVersion.MINECRAFT_1_19) < 0) { && version.lessThan(ProtocolVersion.MINECRAFT_1_19)) {
ProtocolUtils.writeBinaryTag(buf, version, currentDimensionData); ProtocolUtils.writeBinaryTag(buf, version, currentDimensionData);
ProtocolUtils.writeString(buf, dimensionInfo.getRegistryIdentifier()); ProtocolUtils.writeString(buf, dimensionInfo.getRegistryIdentifier());
} else { } else {
@ -219,20 +219,20 @@ public class RespawnPacket implements MinecraftPacket {
} else { } else {
buf.writeInt(dimension); buf.writeInt(dimension);
} }
if (version.compareTo(ProtocolVersion.MINECRAFT_1_13_2) <= 0) { if (version.noGreaterThan(ProtocolVersion.MINECRAFT_1_13_2)) {
buf.writeByte(difficulty); buf.writeByte(difficulty);
} }
if (version.compareTo(ProtocolVersion.MINECRAFT_1_15) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_15)) {
buf.writeLong(partialHashedSeed); buf.writeLong(partialHashedSeed);
} }
buf.writeByte(gamemode); buf.writeByte(gamemode);
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_16)) {
buf.writeByte(previousGamemode); buf.writeByte(previousGamemode);
buf.writeBoolean(dimensionInfo.isDebugType()); buf.writeBoolean(dimensionInfo.isDebugType());
buf.writeBoolean(dimensionInfo.isFlat()); buf.writeBoolean(dimensionInfo.isFlat());
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19_3) < 0) { if (version.lessThan(ProtocolVersion.MINECRAFT_1_19_3)) {
buf.writeBoolean(dataToKeep != 0); buf.writeBoolean(dataToKeep != 0);
} else if (version.compareTo(ProtocolVersion.MINECRAFT_1_20_2) < 0) { } else if (version.lessThan(ProtocolVersion.MINECRAFT_1_20_2)) {
buf.writeByte(dataToKeep); buf.writeByte(dataToKeep);
} }
} else { } else {
@ -240,7 +240,7 @@ public class RespawnPacket implements MinecraftPacket {
} }
// optional death location // optional death location
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_19)) {
if (lastDeathPosition != null) { if (lastDeathPosition != null) {
buf.writeBoolean(true); buf.writeBoolean(true);
ProtocolUtils.writeString(buf, lastDeathPosition.key()); ProtocolUtils.writeString(buf, lastDeathPosition.key());
@ -250,11 +250,11 @@ public class RespawnPacket implements MinecraftPacket {
} }
} }
if (version.compareTo(ProtocolVersion.MINECRAFT_1_20) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_20)) {
ProtocolUtils.writeVarInt(buf, portalCooldown); ProtocolUtils.writeVarInt(buf, portalCooldown);
} }
if (version.compareTo(ProtocolVersion.MINECRAFT_1_20_2) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_20_2)) {
buf.writeByte(dataToKeep); buf.writeByte(dataToKeep);
} }
} }

Datei anzeigen

@ -47,12 +47,12 @@ public class ServerDataPacket implements MinecraftPacket {
@Override @Override
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, public void decode(ByteBuf buf, ProtocolUtils.Direction direction,
ProtocolVersion protocolVersion) { ProtocolVersion protocolVersion) {
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_19_4) >= 0 || buf.readBoolean()) { if (protocolVersion.noLessThan(ProtocolVersion.MINECRAFT_1_19_4) || buf.readBoolean()) {
this.description = ComponentHolder.read(buf, protocolVersion); this.description = ComponentHolder.read(buf, protocolVersion);
} }
if (buf.readBoolean()) { if (buf.readBoolean()) {
String iconBase64; String iconBase64;
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_19_4) >= 0) { if (protocolVersion.noLessThan(ProtocolVersion.MINECRAFT_1_19_4)) {
byte[] iconBytes = ProtocolUtils.readByteArray(buf); byte[] iconBytes = ProtocolUtils.readByteArray(buf);
iconBase64 = "data:image/png;base64," + new String(Base64.getEncoder().encode(iconBytes), StandardCharsets.UTF_8); iconBase64 = "data:image/png;base64," + new String(Base64.getEncoder().encode(iconBytes), StandardCharsets.UTF_8);
} else { } else {
@ -60,10 +60,10 @@ public class ServerDataPacket implements MinecraftPacket {
} }
this.favicon = new Favicon(iconBase64); this.favicon = new Favicon(iconBase64);
} }
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_19_3) < 0) { if (protocolVersion.lessThan(ProtocolVersion.MINECRAFT_1_19_3)) {
buf.readBoolean(); buf.readBoolean();
} }
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_19_1) >= 0) { if (protocolVersion.noLessThan(ProtocolVersion.MINECRAFT_1_19_1)) {
this.secureChatEnforced = buf.readBoolean(); this.secureChatEnforced = buf.readBoolean();
} }
} }
@ -72,17 +72,17 @@ public class ServerDataPacket implements MinecraftPacket {
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, public void encode(ByteBuf buf, ProtocolUtils.Direction direction,
ProtocolVersion protocolVersion) { ProtocolVersion protocolVersion) {
boolean hasDescription = this.description != null; boolean hasDescription = this.description != null;
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_19_4) < 0) { if (protocolVersion.lessThan(ProtocolVersion.MINECRAFT_1_19_4)) {
buf.writeBoolean(hasDescription); buf.writeBoolean(hasDescription);
} }
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_19_4) >= 0 || hasDescription) { if (protocolVersion.noLessThan(ProtocolVersion.MINECRAFT_1_19_4) || hasDescription) {
this.description.write(buf); this.description.write(buf);
} }
boolean hasFavicon = this.favicon != null; boolean hasFavicon = this.favicon != null;
buf.writeBoolean(hasFavicon); buf.writeBoolean(hasFavicon);
if (hasFavicon) { if (hasFavicon) {
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_19_4) >= 0) { if (protocolVersion.noLessThan(ProtocolVersion.MINECRAFT_1_19_4)) {
String cutIconBase64 = favicon.getBase64Url().substring("data:image/png;base64,".length()); String cutIconBase64 = favicon.getBase64Url().substring("data:image/png;base64,".length());
byte[] iconBytes = Base64.getDecoder().decode(cutIconBase64.getBytes(StandardCharsets.UTF_8)); byte[] iconBytes = Base64.getDecoder().decode(cutIconBase64.getBytes(StandardCharsets.UTF_8));
ProtocolUtils.writeByteArray(buf, iconBytes); ProtocolUtils.writeByteArray(buf, iconBytes);
@ -91,10 +91,10 @@ public class ServerDataPacket implements MinecraftPacket {
} }
} }
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_19_3) < 0) { if (protocolVersion.lessThan(ProtocolVersion.MINECRAFT_1_19_3)) {
buf.writeBoolean(false); buf.writeBoolean(false);
} }
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_19_1) >= 0) { if (protocolVersion.noLessThan(ProtocolVersion.MINECRAFT_1_19_1)) {
buf.writeBoolean(this.secureChatEnforced); buf.writeBoolean(this.secureChatEnforced);
} }
} }

Datei anzeigen

@ -84,8 +84,8 @@ public class ServerLoginPacket implements MinecraftPacket {
throw EMPTY_USERNAME; throw EMPTY_USERNAME;
} }
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_19)) {
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19_3) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_19_3)) {
playerKey = null; playerKey = null;
} else { } else {
if (buf.readBoolean()) { if (buf.readBoolean()) {
@ -95,12 +95,12 @@ public class ServerLoginPacket implements MinecraftPacket {
} }
} }
if (version.compareTo(ProtocolVersion.MINECRAFT_1_20_2) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_20_2)) {
this.holderUuid = ProtocolUtils.readUuid(buf); this.holderUuid = ProtocolUtils.readUuid(buf);
return; return;
} }
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19_1) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_19_1)) {
if (buf.readBoolean()) { if (buf.readBoolean()) {
holderUuid = ProtocolUtils.readUuid(buf); holderUuid = ProtocolUtils.readUuid(buf);
} }
@ -117,8 +117,8 @@ public class ServerLoginPacket implements MinecraftPacket {
} }
ProtocolUtils.writeString(buf, username); ProtocolUtils.writeString(buf, username);
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_19)) {
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19_3) < 0) { if (version.lessThan(ProtocolVersion.MINECRAFT_1_19_3)) {
if (playerKey != null) { if (playerKey != null) {
buf.writeBoolean(true); buf.writeBoolean(true);
ProtocolUtils.writePlayerKey(buf, playerKey); ProtocolUtils.writePlayerKey(buf, playerKey);
@ -127,12 +127,12 @@ public class ServerLoginPacket implements MinecraftPacket {
} }
} }
if (version.compareTo(ProtocolVersion.MINECRAFT_1_20_2) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_20_2)) {
ProtocolUtils.writeUuid(buf, this.holderUuid); ProtocolUtils.writeUuid(buf, this.holderUuid);
return; return;
} }
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19_1) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_19_1)) {
if (playerKey != null && playerKey.getSignatureHolder() != null) { if (playerKey != null && playerKey.getSignatureHolder() != null) {
buf.writeBoolean(true); buf.writeBoolean(true);
ProtocolUtils.writeUuid(buf, playerKey.getSignatureHolder()); ProtocolUtils.writeUuid(buf, playerKey.getSignatureHolder());
@ -152,8 +152,8 @@ public class ServerLoginPacket implements MinecraftPacket {
// legal on the protocol level. // legal on the protocol level.
int base = 1 + (16 * 3); int base = 1 + (16 * 3);
// Adjustments for Key-authentication // Adjustments for Key-authentication
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_19)) {
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19_3) < 0) { if (version.lessThan(ProtocolVersion.MINECRAFT_1_19_3)) {
// + 1 for the boolean present/ not present // + 1 for the boolean present/ not present
// + 8 for the long expiry // + 8 for the long expiry
// + 2 len for varint key size // + 2 len for varint key size
@ -162,7 +162,7 @@ public class ServerLoginPacket implements MinecraftPacket {
// + 512 for signature // + 512 for signature
base += 1 + 8 + 2 + 294 + 2 + 512; base += 1 + 8 + 2 + 294 + 2 + 512;
} }
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19_1) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_19_1)) {
// +1 boolean uuid optional // +1 boolean uuid optional
// + 2 * 8 for the long msb/lsb // + 2 * 8 for the long msb/lsb
base += 1 + 8 + 8; base += 1 + 8 + 8;

Datei anzeigen

@ -76,18 +76,18 @@ public class ServerLoginSuccessPacket implements MinecraftPacket {
@Override @Override
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_19)) {
uuid = ProtocolUtils.readUuid(buf); uuid = ProtocolUtils.readUuid(buf);
} else if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) { } else if (version.noLessThan(ProtocolVersion.MINECRAFT_1_16)) {
uuid = ProtocolUtils.readUuidIntArray(buf); uuid = ProtocolUtils.readUuidIntArray(buf);
} else if (version.compareTo(ProtocolVersion.MINECRAFT_1_7_6) >= 0) { } else if (version.noLessThan(ProtocolVersion.MINECRAFT_1_7_6)) {
uuid = UUID.fromString(ProtocolUtils.readString(buf, 36)); uuid = UUID.fromString(ProtocolUtils.readString(buf, 36));
} else { } else {
uuid = UuidUtils.fromUndashed(ProtocolUtils.readString(buf, 32)); uuid = UuidUtils.fromUndashed(ProtocolUtils.readString(buf, 32));
} }
username = ProtocolUtils.readString(buf, 16); username = ProtocolUtils.readString(buf, 16);
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_19)) {
properties = ProtocolUtils.readProperties(buf); properties = ProtocolUtils.readProperties(buf);
} }
} }
@ -97,11 +97,11 @@ public class ServerLoginSuccessPacket implements MinecraftPacket {
if (uuid == null) { if (uuid == null) {
throw new IllegalStateException("No UUID specified!"); throw new IllegalStateException("No UUID specified!");
} }
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_19)) {
ProtocolUtils.writeUuid(buf, uuid); ProtocolUtils.writeUuid(buf, uuid);
} else if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) { } else if (version.noLessThan(ProtocolVersion.MINECRAFT_1_16)) {
ProtocolUtils.writeUuidIntArray(buf, uuid); ProtocolUtils.writeUuidIntArray(buf, uuid);
} else if (version.compareTo(ProtocolVersion.MINECRAFT_1_7_6) >= 0) { } else if (version.noLessThan(ProtocolVersion.MINECRAFT_1_7_6)) {
ProtocolUtils.writeString(buf, uuid.toString()); ProtocolUtils.writeString(buf, uuid.toString());
} else { } else {
ProtocolUtils.writeString(buf, UuidUtils.toUndashed(uuid)); ProtocolUtils.writeString(buf, UuidUtils.toUndashed(uuid));
@ -111,7 +111,7 @@ public class ServerLoginSuccessPacket implements MinecraftPacket {
} }
ProtocolUtils.writeString(buf, username); ProtocolUtils.writeString(buf, username);
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_19)) {
if (properties == null) { if (properties == null) {
ProtocolUtils.writeVarInt(buf, 0); ProtocolUtils.writeVarInt(buf, 0);
} else { } else {

Datei anzeigen

@ -95,15 +95,15 @@ public class TabCompleteRequestPacket implements MinecraftPacket {
@Override @Override
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
if (version.compareTo(MINECRAFT_1_13) >= 0) { if (version.noLessThan(MINECRAFT_1_13)) {
this.transactionId = ProtocolUtils.readVarInt(buf); this.transactionId = ProtocolUtils.readVarInt(buf);
this.command = ProtocolUtils.readString(buf, VANILLA_MAX_TAB_COMPLETE_LEN); this.command = ProtocolUtils.readString(buf, VANILLA_MAX_TAB_COMPLETE_LEN);
} else { } else {
this.command = ProtocolUtils.readString(buf, VANILLA_MAX_TAB_COMPLETE_LEN); this.command = ProtocolUtils.readString(buf, VANILLA_MAX_TAB_COMPLETE_LEN);
if (version.compareTo(MINECRAFT_1_9) >= 0) { if (version.noLessThan(MINECRAFT_1_9)) {
this.assumeCommand = buf.readBoolean(); this.assumeCommand = buf.readBoolean();
} }
if (version.compareTo(MINECRAFT_1_8) >= 0) { if (version.noLessThan(MINECRAFT_1_8)) {
this.hasPosition = buf.readBoolean(); this.hasPosition = buf.readBoolean();
if (hasPosition) { if (hasPosition) {
this.position = buf.readLong(); this.position = buf.readLong();
@ -118,15 +118,15 @@ public class TabCompleteRequestPacket implements MinecraftPacket {
throw new IllegalStateException("Command is not specified"); throw new IllegalStateException("Command is not specified");
} }
if (version.compareTo(MINECRAFT_1_13) >= 0) { if (version.noLessThan(MINECRAFT_1_13)) {
ProtocolUtils.writeVarInt(buf, transactionId); ProtocolUtils.writeVarInt(buf, transactionId);
ProtocolUtils.writeString(buf, command); ProtocolUtils.writeString(buf, command);
} else { } else {
ProtocolUtils.writeString(buf, command); ProtocolUtils.writeString(buf, command);
if (version.compareTo(MINECRAFT_1_9) >= 0) { if (version.noLessThan(MINECRAFT_1_9)) {
buf.writeBoolean(assumeCommand); buf.writeBoolean(assumeCommand);
} }
if (version.compareTo(MINECRAFT_1_8) >= 0) { if (version.noLessThan(MINECRAFT_1_8)) {
buf.writeBoolean(hasPosition); buf.writeBoolean(hasPosition);
if (hasPosition) { if (hasPosition) {
buf.writeLong(position); buf.writeLong(position);

Datei anzeigen

@ -77,7 +77,7 @@ public class TabCompleteResponsePacket implements MinecraftPacket {
@Override @Override
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
if (version.compareTo(MINECRAFT_1_13) >= 0) { if (version.noLessThan(MINECRAFT_1_13)) {
this.transactionId = ProtocolUtils.readVarInt(buf); this.transactionId = ProtocolUtils.readVarInt(buf);
this.start = ProtocolUtils.readVarInt(buf); this.start = ProtocolUtils.readVarInt(buf);
this.length = ProtocolUtils.readVarInt(buf); this.length = ProtocolUtils.readVarInt(buf);
@ -97,7 +97,7 @@ public class TabCompleteResponsePacket implements MinecraftPacket {
@Override @Override
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
if (version.compareTo(MINECRAFT_1_13) >= 0) { if (version.noLessThan(MINECRAFT_1_13)) {
ProtocolUtils.writeVarInt(buf, this.transactionId); ProtocolUtils.writeVarInt(buf, this.transactionId);
ProtocolUtils.writeVarInt(buf, this.start); ProtocolUtils.writeVarInt(buf, this.start);
ProtocolUtils.writeVarInt(buf, this.length); ProtocolUtils.writeVarInt(buf, this.length);

Datei anzeigen

@ -41,13 +41,13 @@ public class ArgumentIdentifier {
VersionSet current = Preconditions.checkNotNull(versions[i]); VersionSet current = Preconditions.checkNotNull(versions[i]);
Preconditions.checkArgument( Preconditions.checkArgument(
current.getVersion().compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0, current.getVersion().noLessThan(ProtocolVersion.MINECRAFT_1_19),
"Version too old for ID index"); "Version too old for ID index");
Preconditions.checkArgument(previous == null || previous.compareTo(current.getVersion()) > 0, Preconditions.checkArgument(previous == null || previous.greaterThan(current.getVersion()),
"Invalid protocol version order"); "Invalid protocol version order");
for (ProtocolVersion v : ProtocolVersion.values()) { for (ProtocolVersion v : ProtocolVersion.values()) {
if (v.compareTo(current.getVersion()) >= 0) { if (v.noLessThan(current.getVersion())) {
temp.putIfAbsent(v, current.getId()); temp.putIfAbsent(v, current.getId());
} }
} }

Datei anzeigen

@ -135,7 +135,7 @@ public class ArgumentPropertyRegistry {
*/ */
public static void writeIdentifier(ByteBuf buf, ArgumentIdentifier identifier, public static void writeIdentifier(ByteBuf buf, ArgumentIdentifier identifier,
ProtocolVersion protocolVersion) { ProtocolVersion protocolVersion) {
if (protocolVersion.compareTo(MINECRAFT_1_19) >= 0) { if (protocolVersion.noLessThan(MINECRAFT_1_19)) {
Integer id = identifier.getIdByProtocolVersion(protocolVersion); Integer id = identifier.getIdByProtocolVersion(protocolVersion);
Preconditions.checkNotNull(id, "Don't know how to serialize type " + identifier); Preconditions.checkNotNull(id, "Don't know how to serialize type " + identifier);
@ -154,7 +154,7 @@ public class ArgumentPropertyRegistry {
* @return the identifier read from the buffer * @return the identifier read from the buffer
*/ */
public static ArgumentIdentifier readIdentifier(ByteBuf buf, ProtocolVersion protocolVersion) { public static ArgumentIdentifier readIdentifier(ByteBuf buf, ProtocolVersion protocolVersion) {
if (protocolVersion.compareTo(MINECRAFT_1_19) >= 0) { if (protocolVersion.noLessThan(MINECRAFT_1_19)) {
int id = ProtocolUtils.readVarInt(buf); int id = ProtocolUtils.readVarInt(buf);
for (ArgumentIdentifier i : byIdentifier.keySet()) { for (ArgumentIdentifier i : byIdentifier.keySet()) {
Integer v = i.getIdByProtocolVersion(protocolVersion); Integer v = i.getIdByProtocolVersion(protocolVersion);

Datei anzeigen

@ -34,7 +34,7 @@ class ModArgumentPropertySerializer implements ArgumentPropertySerializer<ModArg
@Override @Override
public @Nullable ModArgumentProperty deserialize(ByteBuf buf, ProtocolVersion version) { public @Nullable ModArgumentProperty deserialize(ByteBuf buf, ProtocolVersion version) {
ArgumentIdentifier identifier; ArgumentIdentifier identifier;
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_19)) {
int idx = ProtocolUtils.readVarInt(buf); int idx = ProtocolUtils.readVarInt(buf);
identifier = ArgumentIdentifier.id("crossstitch:identified_" + (idx < 0 ? "n" + (-idx) : idx), identifier = ArgumentIdentifier.id("crossstitch:identified_" + (idx < 0 ? "n" + (-idx) : idx),
ArgumentIdentifier.mapSet(version, idx)); ArgumentIdentifier.mapSet(version, idx));

Datei anzeigen

@ -26,7 +26,7 @@ public class TimeArgumentSerializer implements ArgumentPropertySerializer<Intege
@Override @Override
public Integer deserialize(ByteBuf buf, ProtocolVersion protocolVersion) { public Integer deserialize(ByteBuf buf, ProtocolVersion protocolVersion) {
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_19_4) >= 0) { if (protocolVersion.noLessThan(ProtocolVersion.MINECRAFT_1_19_4)) {
return buf.readInt(); return buf.readInt();
} }
return 0; return 0;
@ -34,7 +34,7 @@ public class TimeArgumentSerializer implements ArgumentPropertySerializer<Intege
@Override @Override
public void serialize(Integer object, ByteBuf buf, ProtocolVersion protocolVersion) { public void serialize(Integer object, ByteBuf buf, ProtocolVersion protocolVersion) {
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_19_4) >= 0) { if (protocolVersion.noLessThan(ProtocolVersion.MINECRAFT_1_19_4)) {
buf.writeInt(object); buf.writeInt(object);
} }
} }

Datei anzeigen

@ -279,7 +279,7 @@ public class ComponentHolder {
} }
public static ComponentHolder read(ByteBuf buf, ProtocolVersion version) { public static ComponentHolder read(ByteBuf buf, ProtocolVersion version) {
if (version.compareTo(ProtocolVersion.MINECRAFT_1_20_3) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_20_3)) {
return new ComponentHolder(version, return new ComponentHolder(version,
ProtocolUtils.readBinaryTag(buf, version, BinaryTagIO.reader())); ProtocolUtils.readBinaryTag(buf, version, BinaryTagIO.reader()));
} else { } else {
@ -288,7 +288,7 @@ public class ComponentHolder {
} }
public void write(ByteBuf buf) { public void write(ByteBuf buf) {
if (version.compareTo(ProtocolVersion.MINECRAFT_1_20_3) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_20_3)) {
ProtocolUtils.writeBinaryTag(buf, version, getBinaryTag()); ProtocolUtils.writeBinaryTag(buf, version, getBinaryTag());
} else { } else {
ProtocolUtils.writeString(buf, getJson()); ProtocolUtils.writeString(buf, getJson());

Datei anzeigen

@ -54,7 +54,7 @@ public class SystemChatPacket implements MinecraftPacket {
@Override @Override
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
component.write(buf); component.write(buf);
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19_1) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_19_1)) {
switch (type) { switch (type) {
case SYSTEM: case SYSTEM:
buf.writeBoolean(false); buf.writeBoolean(false);

Datei anzeigen

@ -30,9 +30,9 @@ public class ChatBuilderFactory {
public ChatBuilderFactory(ProtocolVersion version) { public ChatBuilderFactory(ProtocolVersion version) {
this.version = version; this.version = version;
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19_3) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_19_3)) {
this.builderFunction = SessionChatBuilder::new; this.builderFunction = SessionChatBuilder::new;
} else if (version.compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0) { } else if (version.noLessThan(ProtocolVersion.MINECRAFT_1_19)) {
this.builderFunction = KeyedChatBuilder::new; this.builderFunction = KeyedChatBuilder::new;
} else { } else {
this.builderFunction = LegacyChatBuilder::new; this.builderFunction = LegacyChatBuilder::new;

Datei anzeigen

@ -105,7 +105,7 @@ public class KeyedChatHandler implements
return pme -> { return pme -> {
PlayerChatEvent.ChatResult chatResult = pme.getResult(); PlayerChatEvent.ChatResult chatResult = pme.getResult();
if (!chatResult.isAllowed()) { if (!chatResult.isAllowed()) {
if (playerKey.getKeyRevision().compareTo(IdentifiedKey.Revision.LINKED_V2) >= 0) { if (playerKey.getKeyRevision().noLessThan(IdentifiedKey.Revision.LINKED_V2)) {
// Bad, very bad. // Bad, very bad.
invalidCancel(logger, player); invalidCancel(logger, player);
} }
@ -113,7 +113,7 @@ public class KeyedChatHandler implements
} }
if (chatResult.getMessage().map(str -> !str.equals(packet.getMessage())).orElse(false)) { if (chatResult.getMessage().map(str -> !str.equals(packet.getMessage())).orElse(false)) {
if (playerKey.getKeyRevision().compareTo(IdentifiedKey.Revision.LINKED_V2) >= 0) { if (playerKey.getKeyRevision().noLessThan(IdentifiedKey.Revision.LINKED_V2)) {
// Bad, very bad. // Bad, very bad.
invalidChange(logger, player); invalidChange(logger, player);
} else { } else {

Datei anzeigen

@ -49,7 +49,7 @@ public class KeyedCommandHandler implements CommandHandler<KeyedPlayerCommandPac
if (result == CommandExecuteEvent.CommandResult.denied()) { if (result == CommandExecuteEvent.CommandResult.denied()) {
if (playerKey != null) { if (playerKey != null) {
if (!packet.isUnsigned() if (!packet.isUnsigned()
&& playerKey.getKeyRevision().compareTo(IdentifiedKey.Revision.LINKED_V2) >= 0) { && playerKey.getKeyRevision().noLessThan(IdentifiedKey.Revision.LINKED_V2)) {
logger.fatal("A plugin tried to deny a command with signable component(s). " logger.fatal("A plugin tried to deny a command with signable component(s). "
+ "This is not supported. " + "This is not supported. "
+ "Disconnecting player " + player.getUsername() + ". Command packet: " + packet); + "Disconnecting player " + player.getUsername() + ". Command packet: " + packet);
@ -72,7 +72,7 @@ public class KeyedCommandHandler implements CommandHandler<KeyedPlayerCommandPac
return CompletableFuture.completedFuture(packet); return CompletableFuture.completedFuture(packet);
} else { } else {
if (!packet.isUnsigned() && playerKey != null if (!packet.isUnsigned() && playerKey != null
&& playerKey.getKeyRevision().compareTo(IdentifiedKey.Revision.LINKED_V2) >= 0) { && playerKey.getKeyRevision().noLessThan(IdentifiedKey.Revision.LINKED_V2)) {
logger.fatal("A plugin tried to change a command with signed component(s). " logger.fatal("A plugin tried to change a command with signed component(s). "
+ "This is not supported. " + "This is not supported. "
+ "Disconnecting player " + player.getUsername() + ". Command packet: " + packet); + "Disconnecting player " + player.getUsername() + ". Command packet: " + packet);
@ -92,7 +92,7 @@ public class KeyedCommandHandler implements CommandHandler<KeyedPlayerCommandPac
} }
if (!packet.isUnsigned() && playerKey != null if (!packet.isUnsigned() && playerKey != null
&& playerKey.getKeyRevision().compareTo(IdentifiedKey.Revision.LINKED_V2) >= 0) { && playerKey.getKeyRevision().noLessThan(IdentifiedKey.Revision.LINKED_V2)) {
logger.fatal("A plugin tried to change a command with signed component(s). " logger.fatal("A plugin tried to change a command with signed component(s). "
+ "This is not supported. " + "This is not supported. "
+ "Disconnecting player " + player.getUsername() + ". Command packet: " + packet); + "Disconnecting player " + player.getUsername() + ". Command packet: " + packet);

Datei anzeigen

@ -86,7 +86,7 @@ public class KeyedPlayerChatPacket implements MinecraftPacket {
salt = Longs.toByteArray(saltLong); salt = Longs.toByteArray(saltLong);
signature = signatureBytes; signature = signatureBytes;
expiry = Instant.ofEpochMilli(expiresAt); expiry = Instant.ofEpochMilli(expiresAt);
} else if ((protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_19_1) >= 0 } else if ((protocolVersion.noLessThan(ProtocolVersion.MINECRAFT_1_19_1)
|| saltLong == 0L) && signatureBytes.length == 0) { || saltLong == 0L) && signatureBytes.length == 0) {
unsigned = true; unsigned = true;
} else { } else {
@ -98,7 +98,7 @@ public class KeyedPlayerChatPacket implements MinecraftPacket {
throw EncryptionUtils.PREVIEW_SIGNATURE_MISSING; throw EncryptionUtils.PREVIEW_SIGNATURE_MISSING;
} }
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_19_1) >= 0) { if (protocolVersion.noLessThan(ProtocolVersion.MINECRAFT_1_19_1)) {
int size = ProtocolUtils.readVarInt(buf); int size = ProtocolUtils.readVarInt(buf);
if (size < 0 || size > MAXIMUM_PREVIOUS_MESSAGE_COUNT) { if (size < 0 || size > MAXIMUM_PREVIOUS_MESSAGE_COUNT) {
throw INVALID_PREVIOUS_MESSAGES; throw INVALID_PREVIOUS_MESSAGES;
@ -130,7 +130,7 @@ public class KeyedPlayerChatPacket implements MinecraftPacket {
buf.writeBoolean(signedPreview); buf.writeBoolean(signedPreview);
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_19_1) >= 0) { if (protocolVersion.noLessThan(ProtocolVersion.MINECRAFT_1_19_1)) {
ProtocolUtils.writeVarInt(buf, previousMessages.length); ProtocolUtils.writeVarInt(buf, previousMessages.length);
for (SignaturePair previousMessage : previousMessages) { for (SignaturePair previousMessage : previousMessages) {
ProtocolUtils.writeUuid(buf, previousMessage.getSigner()); ProtocolUtils.writeUuid(buf, previousMessage.getSigner());

Datei anzeigen

@ -109,7 +109,7 @@ public class KeyedPlayerCommandPacket implements MinecraftPacket {
throw EncryptionUtils.PREVIEW_SIGNATURE_MISSING; throw EncryptionUtils.PREVIEW_SIGNATURE_MISSING;
} }
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_19_1) >= 0) { if (protocolVersion.noLessThan(ProtocolVersion.MINECRAFT_1_19_1)) {
int size = ProtocolUtils.readVarInt(buf); int size = ProtocolUtils.readVarInt(buf);
if (size < 0 || size > MAXIMUM_PREVIOUS_MESSAGE_COUNT) { if (size < 0 || size > MAXIMUM_PREVIOUS_MESSAGE_COUNT) {
throw INVALID_PREVIOUS_MESSAGES; throw INVALID_PREVIOUS_MESSAGES;
@ -155,7 +155,7 @@ public class KeyedPlayerCommandPacket implements MinecraftPacket {
buf.writeBoolean(signedPreview); buf.writeBoolean(signedPreview);
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_19_1) >= 0) { if (protocolVersion.noLessThan(ProtocolVersion.MINECRAFT_1_19_1)) {
ProtocolUtils.writeVarInt(buf, previousMessages.length); ProtocolUtils.writeVarInt(buf, previousMessages.length);
for (SignaturePair previousMessage : previousMessages) { for (SignaturePair previousMessage : previousMessages) {
ProtocolUtils.writeUuid(buf, previousMessage.getSigner()); ProtocolUtils.writeUuid(buf, previousMessage.getSigner());

Datei anzeigen

@ -93,9 +93,9 @@ public class LegacyChatPacket implements MinecraftPacket {
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
message = ProtocolUtils.readString(buf); message = ProtocolUtils.readString(buf);
if (direction == ProtocolUtils.Direction.CLIENTBOUND if (direction == ProtocolUtils.Direction.CLIENTBOUND
&& version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { && version.noLessThan(ProtocolVersion.MINECRAFT_1_8)) {
type = buf.readByte(); type = buf.readByte();
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_16)) {
sender = ProtocolUtils.readUuid(buf); sender = ProtocolUtils.readUuid(buf);
} }
} }
@ -108,9 +108,9 @@ public class LegacyChatPacket implements MinecraftPacket {
} }
ProtocolUtils.writeString(buf, message); ProtocolUtils.writeString(buf, message);
if (direction == ProtocolUtils.Direction.CLIENTBOUND if (direction == ProtocolUtils.Direction.CLIENTBOUND
&& version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { && version.noLessThan(ProtocolVersion.MINECRAFT_1_8)) {
buf.writeByte(type); buf.writeByte(type);
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_16)) {
ProtocolUtils.writeUuid(buf, sender == null ? EMPTY_SENDER : sender); ProtocolUtils.writeUuid(buf, sender == null ? EMPTY_SENDER : sender);
} }
} }

Datei anzeigen

@ -55,7 +55,7 @@ public class SessionCommandHandler implements CommandHandler<SessionPlayerComman
+ "Contact your network administrator.")); + "Contact your network administrator."));
} }
// We seemingly can't actually do this if signed args exist, if not, we can probs keep stuff happy // We seemingly can't actually do this if signed args exist, if not, we can probs keep stuff happy
if (player.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_19_3) >= 0) { if (player.getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_19_3)) {
return CompletableFuture.completedFuture(new ChatAcknowledgementPacket(packet.lastSeenMessages.getOffset())); return CompletableFuture.completedFuture(new ChatAcknowledgementPacket(packet.lastSeenMessages.getOffset()));
} }
return CompletableFuture.completedFuture(null); return CompletableFuture.completedFuture(null);
@ -108,7 +108,7 @@ public class SessionCommandHandler implements CommandHandler<SessionPlayerComman
.toServer(); .toServer();
} }
} }
if (player.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_19_3) >= 0) { if (player.getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_19_3)) {
return new ChatAcknowledgementPacket(packet.lastSeenMessages.getOffset()); return new ChatAcknowledgementPacket(packet.lastSeenMessages.getOffset());
} }
return null; return null;

Datei anzeigen

@ -40,7 +40,7 @@ public abstract class GenericTitlePacket implements MinecraftPacket {
} }
public int getAction(ProtocolVersion version) { public int getAction(ProtocolVersion version) {
return version.compareTo(ProtocolVersion.MINECRAFT_1_11) < 0 return version.lessThan(ProtocolVersion.MINECRAFT_1_11)
? action > 2 ? action - 1 : action : action; ? action > 2 ? action - 1 : action : action;
} }
} }
@ -104,7 +104,7 @@ public abstract class GenericTitlePacket implements MinecraftPacket {
*/ */
public static GenericTitlePacket constructTitlePacket(ActionType type, ProtocolVersion version) { public static GenericTitlePacket constructTitlePacket(ActionType type, ProtocolVersion version) {
GenericTitlePacket packet = null; GenericTitlePacket packet = null;
if (version.compareTo(ProtocolVersion.MINECRAFT_1_17) >= 0) { if (version.noLessThan(ProtocolVersion.MINECRAFT_1_17)) {
switch (type) { switch (type) {
case SET_ACTION_BAR: case SET_ACTION_BAR:
packet = new TitleActionbarPacket(); packet = new TitleActionbarPacket();

Datei anzeigen

@ -33,7 +33,7 @@ public class LegacyTitlePacket extends GenericTitlePacket {
@Override @Override
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
if (version.compareTo(ProtocolVersion.MINECRAFT_1_11) < 0 if (version.lessThan(ProtocolVersion.MINECRAFT_1_11)
&& getAction() == ActionType.SET_ACTION_BAR) { && getAction() == ActionType.SET_ACTION_BAR) {
throw new IllegalStateException("Action bars are only supported on 1.11 and newer"); throw new IllegalStateException("Action bars are only supported on 1.11 and newer");
} }

Datei anzeigen

@ -115,7 +115,7 @@ public final class PluginMessageUtil {
Collection<String> channels) { Collection<String> channels) {
checkNotNull(channels, "channels"); checkNotNull(channels, "channels");
checkArgument(!channels.isEmpty(), "no channels specified"); checkArgument(!channels.isEmpty(), "no channels specified");
String channelName = protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_13) >= 0 String channelName = protocolVersion.noLessThan(ProtocolVersion.MINECRAFT_1_13)
? REGISTER_CHANNEL : REGISTER_CHANNEL_LEGACY; ? REGISTER_CHANNEL : REGISTER_CHANNEL_LEGACY;
ByteBuf contents = Unpooled.buffer(); ByteBuf contents = Unpooled.buffer();
contents.writeCharSequence(String.join("\0", channels), StandardCharsets.UTF_8); contents.writeCharSequence(String.join("\0", channels), StandardCharsets.UTF_8);
@ -140,7 +140,7 @@ public final class PluginMessageUtil {
String rewrittenBrand = String.format("%s (%s)", currentBrand, version.getName()); String rewrittenBrand = String.format("%s (%s)", currentBrand, version.getName());
ByteBuf rewrittenBuf = Unpooled.buffer(); ByteBuf rewrittenBuf = Unpooled.buffer();
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { if (protocolVersion.noLessThan(ProtocolVersion.MINECRAFT_1_8)) {
ProtocolUtils.writeString(rewrittenBuf, rewrittenBrand); ProtocolUtils.writeString(rewrittenBuf, rewrittenBrand);
} else { } else {
rewrittenBuf.writeCharSequence(rewrittenBrand, StandardCharsets.UTF_8); rewrittenBuf.writeCharSequence(rewrittenBrand, StandardCharsets.UTF_8);

Datei anzeigen

@ -115,7 +115,7 @@ public class VelocityChannelRegistrar implements ChannelRegistrar {
* @return the list of channels to register * @return the list of channels to register
*/ */
public Collection<String> getChannelsForProtocol(ProtocolVersion protocolVersion) { public Collection<String> getChannelsForProtocol(ProtocolVersion protocolVersion) {
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_13) >= 0) { if (protocolVersion.noLessThan(ProtocolVersion.MINECRAFT_1_13)) {
return getModernChannelIds(); return getModernChannelIds();
} }
return getLegacyChannelIds(); return getLegacyChannelIds();