Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-12-04 21:50:23 +01:00
Improve protocol version checking (#1203)
* Improve protocol version checking * chore: since 3.3.0
Dieser Commit ist enthalten in:
Ursprung
2ac8751337
Commit
0993ce2f86
@ -18,6 +18,8 @@ java {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnlyApi(libs.jspecify)
|
||||
|
||||
api(libs.gson)
|
||||
api(libs.guava)
|
||||
|
||||
|
@ -100,7 +100,7 @@ public class PlayerResourcePackStatusEvent {
|
||||
*/
|
||||
public void setOverwriteKick(boolean overwriteKick) {
|
||||
Preconditions.checkArgument(player.getProtocolVersion()
|
||||
.compareTo(ProtocolVersion.MINECRAFT_1_17) < 0,
|
||||
.lessThan(ProtocolVersion.MINECRAFT_1_17),
|
||||
"overwriteKick is not supported on 1.17 or newer");
|
||||
this.overwriteKick = overwriteKick;
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ package com.velocitypowered.api.network;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.velocitypowered.api.util.Ordered;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -19,7 +20,7 @@ import java.util.Set;
|
||||
/**
|
||||
* Represents each Minecraft protocol version.
|
||||
*/
|
||||
public enum ProtocolVersion {
|
||||
public enum ProtocolVersion implements Ordered<ProtocolVersion> {
|
||||
UNKNOWN(-1, "Unknown"),
|
||||
LEGACY(-2, "Legacy"),
|
||||
MINECRAFT_1_7_2(4,
|
||||
|
@ -9,6 +9,7 @@ package com.velocitypowered.api.proxy.crypto;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.api.util.Ordered;
|
||||
import java.security.PublicKey;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
@ -57,7 +58,7 @@ public interface IdentifiedKey extends KeySigned {
|
||||
/**
|
||||
* 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)),
|
||||
LINKED_V2(ImmutableSet.of(), ImmutableSet.of(ProtocolVersion.MINECRAFT_1_19_1));
|
||||
|
||||
|
93
api/src/main/java/com/velocitypowered/api/util/Ordered.java
Normale Datei
93
api/src/main/java/com/velocitypowered/api/util/Ordered.java
Normale Datei
@ -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;
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@ extensions.configure<SpotlessExtension> {
|
||||
java {
|
||||
if (project.name == "velocity-api") {
|
||||
licenseHeaderFile(file("HEADER.txt"))
|
||||
targetExclude("**/java/com/velocitypowered/api/util/Ordered.java")
|
||||
} else {
|
||||
licenseHeaderFile(rootProject.file("HEADER.txt"))
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ flare-fastutil = { module = "space.vectrix.flare:flare-fastutil", version.ref =
|
||||
jline = "org.jline:jline-terminal-jansi:3.23.0"
|
||||
jopt = "net.sf.jopt-simple:jopt-simple:5.0.4"
|
||||
junit = "org.junit.jupiter:junit-jupiter:5.9.0"
|
||||
jspecify = "org.jspecify:jspecify:0.3.0"
|
||||
kyori-ansi = "net.kyori:ansi:1.0.3"
|
||||
guava = "com.google.guava:guava:25.1-jre"
|
||||
gson = "com.google.code.gson:gson:2.10.1"
|
||||
|
@ -776,10 +776,10 @@ public class VelocityServer implements ProxyServer, ForwardingAudience {
|
||||
*/
|
||||
public static Gson getPingGsonInstance(ProtocolVersion version) {
|
||||
if (version == ProtocolVersion.UNKNOWN
|
||||
|| version.compareTo(ProtocolVersion.MINECRAFT_1_20_3) >= 0) {
|
||||
|| version.noLessThan(ProtocolVersion.MINECRAFT_1_20_3)) {
|
||||
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_16_PING_SERIALIZER;
|
||||
|
@ -268,8 +268,8 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
|
||||
*/
|
||||
public void closeWith(Object msg) {
|
||||
if (channel.isActive()) {
|
||||
boolean is17 = this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) < 0
|
||||
&& this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_7_2) >= 0;
|
||||
boolean is17 = this.getProtocolVersion().lessThan(ProtocolVersion.MINECRAFT_1_8)
|
||||
&& this.getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_7_2);
|
||||
if (is17 && this.getState() != StateRegistry.STATUS) {
|
||||
channel.eventLoop().execute(() -> {
|
||||
// 1.7.x versions have a race condition with switching protocol states, so just explicitly
|
||||
|
@ -297,7 +297,7 @@ public class BungeeCordMessageResponder {
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -153,7 +153,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
||||
|
||||
// Move into the PLAY phase.
|
||||
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,
|
||||
new TransitionSessionHandler(server, serverConn, resultFuture));
|
||||
} else {
|
||||
@ -202,7 +202,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
||||
// Ensure we are in range
|
||||
requested = Math.min(requested, VelocityConstants.MODERN_FORWARDING_MAX_VERSION);
|
||||
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
|
||||
? VelocityConstants.MODERN_LAZY_SESSION
|
||||
: VelocityConstants.MODERN_FORWARDING_DEFAULT;
|
||||
|
@ -144,7 +144,7 @@ public class TransitionSessionHandler implements MinecraftSessionHandler {
|
||||
serverConn.getPlayer().setConnectedServer(serverConn);
|
||||
|
||||
// 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) {
|
||||
serverConn.ensureConnected().write(player.getClientSettingsPacket());
|
||||
}
|
||||
|
@ -203,7 +203,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
|
||||
mc.setProtocolVersion(protocolVersion);
|
||||
mc.setActiveSessionHandler(StateRegistry.LOGIN);
|
||||
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()));
|
||||
} else {
|
||||
mc.delayedWrite(new ServerLoginPacket(proxyPlayer.getUsername(),
|
||||
|
@ -131,7 +131,7 @@ public class AuthSessionHandler implements MinecraftSessionHandler {
|
||||
|
||||
private void startLoginCompletion(ConnectedPlayer player) {
|
||||
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.setCompressionThreshold(threshold);
|
||||
}
|
||||
@ -216,7 +216,7 @@ public class AuthSessionHandler implements MinecraftSessionHandler {
|
||||
mcConnection.write(success);
|
||||
|
||||
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;
|
||||
mcConnection.setActiveSessionHandler(StateRegistry.PLAY,
|
||||
new InitialConnectSessionHandler(player, server));
|
||||
|
@ -118,10 +118,10 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
||||
this.player = player;
|
||||
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.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.commandHandler = new KeyedCommandHandler(this.player, this.server);
|
||||
} else {
|
||||
@ -551,7 +551,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
||||
}
|
||||
|
||||
// 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(
|
||||
GenericTitlePacket.constructTitlePacket(GenericTitlePacket.ActionType.RESET,
|
||||
player.getProtocolVersion()));
|
||||
@ -574,7 +574,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
||||
// improving compatibility with mods.
|
||||
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
|
||||
// additional respawn. On older versions of Minecraft this forces the client to perform
|
||||
// garbage collection which adds additional latency.
|
||||
@ -616,7 +616,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
||||
|
||||
String commandLabel = command.substring(0, commandEndPosition);
|
||||
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
|
||||
// additional tab completion support.
|
||||
outstandingTabComplete = packet;
|
||||
@ -659,7 +659,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
||||
}
|
||||
|
||||
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
|
||||
// additional tab completion support.
|
||||
outstandingTabComplete = packet;
|
||||
@ -692,7 +692,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
||||
server.getCommandManager().offerBrigadierSuggestions(player, command)
|
||||
.thenAcceptAsync(offers -> {
|
||||
boolean legacy =
|
||||
player.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_13) < 0;
|
||||
player.getProtocolVersion().lessThan(ProtocolVersion.MINECRAFT_1_13);
|
||||
try {
|
||||
for (Suggestion suggestion : offers.getList()) {
|
||||
String offer = suggestion.getText();
|
||||
|
@ -178,9 +178,9 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
|
||||
this.connectionPhase = connection.getType().getInitialClientPhase();
|
||||
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);
|
||||
} 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);
|
||||
} else {
|
||||
this.tabList = new VelocityTabListLegacy(this, server);
|
||||
@ -371,7 +371,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
|
||||
Component translated = translateMessage(message);
|
||||
|
||||
ProtocolVersion playerVersion = getProtocolVersion();
|
||||
if (playerVersion.compareTo(ProtocolVersion.MINECRAFT_1_11) >= 0) {
|
||||
if (playerVersion.noLessThan(ProtocolVersion.MINECRAFT_1_11)) {
|
||||
// Use the title packet instead.
|
||||
GenericTitlePacket pkt = GenericTitlePacket.constructTitlePacket(
|
||||
GenericTitlePacket.ActionType.SET_ACTION_BAR, playerVersion);
|
||||
@ -416,7 +416,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
|
||||
Component translatedFooter = translateMessage(footer);
|
||||
this.playerListHeader = translatedHeader;
|
||||
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(
|
||||
translatedHeader, translatedFooter, this.getProtocolVersion()));
|
||||
}
|
||||
@ -424,7 +424,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
|
||||
|
||||
@Override
|
||||
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.ActionType.SET_TIMES, this.getProtocolVersion());
|
||||
net.kyori.adventure.title.Title.Times times = title.times();
|
||||
@ -460,7 +460,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
|
||||
throw new NullPointerException("value");
|
||||
}
|
||||
|
||||
if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) < 0) {
|
||||
if (this.getProtocolVersion().lessThan(ProtocolVersion.MINECRAFT_1_8)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -491,7 +491,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
|
||||
|
||||
@Override
|
||||
public void clearTitle() {
|
||||
if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
|
||||
if (this.getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_8)) {
|
||||
connection.write(GenericTitlePacket.constructTitlePacket(
|
||||
GenericTitlePacket.ActionType.HIDE, this.getProtocolVersion()));
|
||||
}
|
||||
@ -499,7 +499,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
|
||||
|
||||
@Override
|
||||
public void resetTitle() {
|
||||
if (this.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
|
||||
if (this.getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_8)) {
|
||||
connection.write(GenericTitlePacket.constructTitlePacket(
|
||||
GenericTitlePacket.ActionType.RESET, this.getProtocolVersion()));
|
||||
}
|
||||
@ -507,14 +507,14 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
|
||||
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -542,7 +542,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
|
||||
@Override
|
||||
public void clearPlayerListHeaderAndFooter() {
|
||||
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()));
|
||||
}
|
||||
}
|
||||
@ -942,7 +942,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
|
||||
Preconditions.checkArgument(input.length() <= LegacyChatPacket.MAX_SERVERBOUND_MESSAGE_LENGTH,
|
||||
"input cannot be greater than " + LegacyChatPacket.MAX_SERVERBOUND_MESSAGE_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),
|
||||
(instant, item) -> {
|
||||
item.setTimestamp(instant);
|
||||
@ -968,7 +968,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
|
||||
|
||||
@Override
|
||||
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");
|
||||
queueResourcePack(packInfo);
|
||||
}
|
||||
@ -996,7 +996,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
|
||||
while (!outstandingResourcePacks.isEmpty()) {
|
||||
queued = outstandingResourcePacks.peek();
|
||||
if (queued.getShouldForce() && getProtocolVersion()
|
||||
.compareTo(ProtocolVersion.MINECRAFT_1_17) >= 0) {
|
||||
.noLessThan(ProtocolVersion.MINECRAFT_1_17)) {
|
||||
break;
|
||||
}
|
||||
onResourcePackResponse(PlayerResourcePackStatusEvent.Status.DECLINED);
|
||||
@ -1068,7 +1068,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
|
||||
if (event.getStatus() == PlayerResourcePackStatusEvent.Status.DECLINED
|
||||
&& event.getPackInfo() != null && event.getPackInfo().getShouldForce()
|
||||
&& (!event.isOverwriteKick() || event.getPlayer()
|
||||
.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_17) >= 0)
|
||||
.getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_17))
|
||||
) {
|
||||
event.getPlayer().disconnect(Component
|
||||
.translatable("multiplayer.requiredTexturePrompt.disconnect"));
|
||||
|
@ -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
|
||||
// and lower, otherwise IP information will never get forwarded.
|
||||
if (server.getConfiguration().getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN
|
||||
&& handshake.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_13) < 0) {
|
||||
&& handshake.getProtocolVersion().lessThan(ProtocolVersion.MINECRAFT_1_13)) {
|
||||
ic.disconnectQuietly(
|
||||
Component.translatable("velocity.error.modern-forwarding-needs-new-client"));
|
||||
return;
|
||||
@ -155,14 +155,14 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler {
|
||||
|
||||
private ConnectionType getHandshakeConnectionType(HandshakePacket handshake) {
|
||||
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());
|
||||
}
|
||||
// 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)
|
||||
&& handshake.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_13) < 0) {
|
||||
&& handshake.getProtocolVersion().lessThan(ProtocolVersion.MINECRAFT_1_13)) {
|
||||
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
|
||||
// forge handshake attempts. Also sends a reset handshake packet on every transition.
|
||||
return ConnectionTypes.UNDETERMINED_17;
|
||||
|
@ -111,9 +111,9 @@ public class InitialLoginSessionHandler implements MinecraftSessionHandler {
|
||||
inbound.disconnect(Component.translatable("multiplayer.disconnect.invalid_public_key"));
|
||||
return true;
|
||||
}
|
||||
} else if (mcConnection.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0
|
||||
} else if (mcConnection.getProtocolVersion().noLessThan(ProtocolVersion.MINECRAFT_1_19)
|
||||
&& 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"));
|
||||
return true;
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ public class LoginInboundConnection implements LoginPhaseConnection, KeyIdentifi
|
||||
if (consumer == null) {
|
||||
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 "
|
||||
+ "Minecraft 1.13 and above");
|
||||
}
|
||||
|
@ -435,7 +435,7 @@ public enum ProtocolUtils {
|
||||
public static BinaryTag readBinaryTag(ByteBuf buf, ProtocolVersion version,
|
||||
BinaryTagIO.Reader reader) {
|
||||
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());
|
||||
}
|
||||
try {
|
||||
@ -456,7 +456,7 @@ public enum ProtocolUtils {
|
||||
BinaryTagType<T> type = (BinaryTagType<T>) tag.type();
|
||||
buf.writeByte(type.id());
|
||||
try {
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_20_2) < 0) {
|
||||
if (version.lessThan(ProtocolVersion.MINECRAFT_1_20_2)) {
|
||||
// Empty name
|
||||
buf.writeShort(0);
|
||||
}
|
||||
@ -710,10 +710,10 @@ public enum ProtocolUtils {
|
||||
* @return the appropriate {@link GsonComponentSerializer}
|
||||
*/
|
||||
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;
|
||||
}
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_16)) {
|
||||
return PRE_1_20_3_SERIALIZER;
|
||||
}
|
||||
return PRE_1_16_SERIALIZER;
|
||||
@ -741,7 +741,7 @@ public enum ProtocolUtils {
|
||||
long expiry = buf.readLong();
|
||||
byte[] key = ProtocolUtils.readByteArray(buf);
|
||||
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;
|
||||
return new IdentifiedKeyImpl(revision, key, expiry, signature);
|
||||
}
|
||||
|
@ -669,7 +669,7 @@ public enum StateRegistry {
|
||||
if (next != current) {
|
||||
throw new IllegalArgumentException("Cannot add a mapping after last valid mapping");
|
||||
}
|
||||
if (from.compareTo(lastValid) > 0) {
|
||||
if (from.greaterThan(lastValid)) {
|
||||
throw new IllegalArgumentException(
|
||||
"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);
|
||||
|
||||
if (from.compareTo(to) >= 0 && from != lastInList) {
|
||||
if (from.noLessThan(to) && from != lastInList) {
|
||||
throw new IllegalArgumentException(String.format(
|
||||
"Next mapping version (%s) should be lower then current (%s)", to, from));
|
||||
}
|
||||
|
@ -133,19 +133,19 @@ public class ClientSettingsPacket implements MinecraftPacket {
|
||||
this.chatVisibility = ProtocolUtils.readVarInt(buf);
|
||||
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.skinParts = buf.readUnsignedByte();
|
||||
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_9) >= 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_9)) {
|
||||
this.mainHand = ProtocolUtils.readVarInt(buf);
|
||||
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_17) >= 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_17)) {
|
||||
this.chatFilteringEnabled = buf.readBoolean();
|
||||
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_18) >= 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_18)) {
|
||||
this.clientListingAllowed = buf.readBoolean();
|
||||
}
|
||||
}
|
||||
@ -162,19 +162,19 @@ public class ClientSettingsPacket implements MinecraftPacket {
|
||||
ProtocolUtils.writeVarInt(buf, chatVisibility);
|
||||
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(skinParts);
|
||||
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_9) >= 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_9)) {
|
||||
ProtocolUtils.writeVarInt(buf, mainHand);
|
||||
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_17) >= 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_17)) {
|
||||
buf.writeBoolean(chatFilteringEnabled);
|
||||
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_18) >= 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_18)) {
|
||||
buf.writeBoolean(clientListingAllowed);
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ public class EncryptionRequestPacket implements MinecraftPacket {
|
||||
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
|
||||
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);
|
||||
verifyToken = ProtocolUtils.readByteArray(buf, 16);
|
||||
} else {
|
||||
@ -73,7 +73,7 @@ public class EncryptionRequestPacket implements MinecraftPacket {
|
||||
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
|
||||
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, verifyToken);
|
||||
} else {
|
||||
|
@ -64,17 +64,17 @@ public class EncryptionResponsePacket implements MinecraftPacket {
|
||||
|
||||
@Override
|
||||
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);
|
||||
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0
|
||||
&& version.compareTo(ProtocolVersion.MINECRAFT_1_19_3) < 0
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_19)
|
||||
&& version.lessThan(ProtocolVersion.MINECRAFT_1_19_3)
|
||||
&& !buf.readBoolean()) {
|
||||
salt = buf.readLong();
|
||||
}
|
||||
|
||||
this.verifyToken = ProtocolUtils.readByteArray(buf,
|
||||
version.compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0 ? 256 : 128);
|
||||
version.noLessThan(ProtocolVersion.MINECRAFT_1_19) ? 256 : 128);
|
||||
} else {
|
||||
this.sharedSecret = ProtocolUtils.readByteArray17(buf);
|
||||
this.verifyToken = ProtocolUtils.readByteArray17(buf);
|
||||
@ -83,10 +83,10 @@ public class EncryptionResponsePacket implements MinecraftPacket {
|
||||
|
||||
@Override
|
||||
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);
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0
|
||||
&& version.compareTo(ProtocolVersion.MINECRAFT_1_19_3) < 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_19)
|
||||
&& version.lessThan(ProtocolVersion.MINECRAFT_1_19_3)) {
|
||||
if (salt != null) {
|
||||
buf.writeBoolean(false);
|
||||
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.
|
||||
// The length prefix always winds up being 2 bytes.
|
||||
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;
|
||||
}
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_19)) {
|
||||
// Verify token is twice as long on 1.19+
|
||||
// Additional 1 byte for left <> right and 8 bytes for salt
|
||||
base += 128 + 8 + 1;
|
||||
@ -125,7 +125,7 @@ public class EncryptionResponsePacket implements MinecraftPacket {
|
||||
@Override
|
||||
public int expectedMinLength(ByteBuf buf, Direction direction, ProtocolVersion 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"
|
||||
base -= 128 + 8;
|
||||
}
|
||||
|
@ -200,10 +200,10 @@ public class JoinGamePacket implements MinecraftPacket {
|
||||
|
||||
@Override
|
||||
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
|
||||
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,
|
||||
// so separate it out.
|
||||
this.decode116Up(buf, version);
|
||||
@ -218,33 +218,33 @@ public class JoinGamePacket implements MinecraftPacket {
|
||||
this.isHardcore = (this.gamemode & 0x08) != 0;
|
||||
this.gamemode &= ~0x08;
|
||||
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_9_1) >= 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_9_1)) {
|
||||
this.dimension = buf.readInt();
|
||||
} else {
|
||||
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();
|
||||
}
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_15) >= 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_15)) {
|
||||
this.partialHashedSeed = buf.readLong();
|
||||
}
|
||||
this.maxPlayers = buf.readUnsignedByte();
|
||||
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);
|
||||
}
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_8)) {
|
||||
this.reducedDebugInfo = buf.readBoolean();
|
||||
}
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_15) >= 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_15)) {
|
||||
this.showRespawnScreen = buf.readBoolean();
|
||||
}
|
||||
}
|
||||
|
||||
private void decode116Up(ByteBuf buf, ProtocolVersion version) {
|
||||
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.gamemode = buf.readByte();
|
||||
} else {
|
||||
@ -258,8 +258,8 @@ public class JoinGamePacket implements MinecraftPacket {
|
||||
this.registry = ProtocolUtils.readCompoundTag(buf, version, JOINGAME_READER);
|
||||
String dimensionIdentifier;
|
||||
String levelName = null;
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0
|
||||
&& version.compareTo(ProtocolVersion.MINECRAFT_1_19) < 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_16_2)
|
||||
&& version.lessThan(ProtocolVersion.MINECRAFT_1_19)) {
|
||||
this.currentDimensionData = ProtocolUtils.readCompoundTag(buf, version, JOINGAME_READER);
|
||||
dimensionIdentifier = ProtocolUtils.readString(buf);
|
||||
} else {
|
||||
@ -268,14 +268,14 @@ public class JoinGamePacket implements MinecraftPacket {
|
||||
}
|
||||
|
||||
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);
|
||||
} else {
|
||||
this.maxPlayers = buf.readUnsignedByte();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@ -287,11 +287,11 @@ public class JoinGamePacket implements MinecraftPacket {
|
||||
this.dimensionInfo = new DimensionInfo(dimensionIdentifier, levelName, isFlat, isDebug);
|
||||
|
||||
// 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());
|
||||
}
|
||||
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_20) >= 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_20)) {
|
||||
this.portalCooldown = ProtocolUtils.readVarInt(buf);
|
||||
}
|
||||
}
|
||||
@ -332,10 +332,10 @@ public class JoinGamePacket implements MinecraftPacket {
|
||||
|
||||
@Override
|
||||
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
|
||||
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,
|
||||
// so separate it out.
|
||||
this.encode116Up(buf, version);
|
||||
@ -346,21 +346,21 @@ public class JoinGamePacket implements MinecraftPacket {
|
||||
|
||||
private void encodeLegacy(ByteBuf buf, ProtocolVersion version) {
|
||||
buf.writeInt(entityId);
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_16_2)) {
|
||||
buf.writeBoolean(isHardcore);
|
||||
buf.writeByte(gamemode);
|
||||
} else {
|
||||
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);
|
||||
} else {
|
||||
buf.writeByte(dimension);
|
||||
}
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_13_2) <= 0) {
|
||||
if (version.noGreaterThan(ProtocolVersion.MINECRAFT_1_13_2)) {
|
||||
buf.writeByte(difficulty);
|
||||
}
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_15) >= 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_15)) {
|
||||
buf.writeLong(partialHashedSeed);
|
||||
}
|
||||
buf.writeByte(maxPlayers);
|
||||
@ -368,20 +368,20 @@ public class JoinGamePacket implements MinecraftPacket {
|
||||
throw new IllegalStateException("No level type specified.");
|
||||
}
|
||||
ProtocolUtils.writeString(buf, levelType);
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_14) >= 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_14)) {
|
||||
ProtocolUtils.writeVarInt(buf, viewDistance);
|
||||
}
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_8)) {
|
||||
buf.writeBoolean(reducedDebugInfo);
|
||||
}
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_15) >= 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_15)) {
|
||||
buf.writeBoolean(showRespawnScreen);
|
||||
}
|
||||
}
|
||||
|
||||
private void encode116Up(ByteBuf buf, ProtocolVersion version) {
|
||||
buf.writeInt(entityId);
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_16_2)) {
|
||||
buf.writeBoolean(isHardcore);
|
||||
buf.writeByte(gamemode);
|
||||
} else {
|
||||
@ -391,8 +391,8 @@ public class JoinGamePacket implements MinecraftPacket {
|
||||
|
||||
ProtocolUtils.writeStringArray(buf, levelNames.toArray(String[]::new));
|
||||
ProtocolUtils.writeBinaryTag(buf, version, this.registry);
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0
|
||||
&& version.compareTo(ProtocolVersion.MINECRAFT_1_19) < 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_16_2)
|
||||
&& version.lessThan(ProtocolVersion.MINECRAFT_1_19)) {
|
||||
ProtocolUtils.writeBinaryTag(buf, version, currentDimensionData);
|
||||
ProtocolUtils.writeString(buf, dimensionInfo.getRegistryIdentifier());
|
||||
} else {
|
||||
@ -401,14 +401,14 @@ public class JoinGamePacket implements MinecraftPacket {
|
||||
}
|
||||
|
||||
buf.writeLong(partialHashedSeed);
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_16_2)) {
|
||||
ProtocolUtils.writeVarInt(buf, maxPlayers);
|
||||
} else {
|
||||
buf.writeByte(maxPlayers);
|
||||
}
|
||||
|
||||
ProtocolUtils.writeVarInt(buf, viewDistance);
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_18) >= 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_18)) {
|
||||
ProtocolUtils.writeVarInt(buf, simulationDistance);
|
||||
}
|
||||
|
||||
@ -419,7 +419,7 @@ public class JoinGamePacket implements MinecraftPacket {
|
||||
buf.writeBoolean(dimensionInfo.isFlat());
|
||||
|
||||
// optional death location
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_19)) {
|
||||
if (lastDeathPosition != null) {
|
||||
buf.writeBoolean(true);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -44,9 +44,9 @@ public class KeepAlivePacket implements MinecraftPacket {
|
||||
|
||||
@Override
|
||||
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();
|
||||
} else if (version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
|
||||
} else if (version.noLessThan(ProtocolVersion.MINECRAFT_1_8)) {
|
||||
randomId = ProtocolUtils.readVarInt(buf);
|
||||
} else {
|
||||
randomId = buf.readInt();
|
||||
@ -55,9 +55,9 @@ public class KeepAlivePacket implements MinecraftPacket {
|
||||
|
||||
@Override
|
||||
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);
|
||||
} else if (version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
|
||||
} else if (version.noLessThan(ProtocolVersion.MINECRAFT_1_8)) {
|
||||
ProtocolUtils.writeVarInt(buf, (int) randomId);
|
||||
} else {
|
||||
buf.writeInt((int) randomId);
|
||||
|
@ -61,7 +61,7 @@ public class LegacyPlayerListItemPacket implements MinecraftPacket {
|
||||
|
||||
@Override
|
||||
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);
|
||||
int length = ProtocolUtils.readVarInt(buf);
|
||||
|
||||
@ -76,7 +76,7 @@ public class LegacyPlayerListItemPacket implements MinecraftPacket {
|
||||
item.setLatency(ProtocolUtils.readVarInt(buf));
|
||||
item.setDisplayName(readOptionalComponent(buf, version));
|
||||
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_19)) {
|
||||
if (buf.readBoolean()) {
|
||||
item.setPlayerKey(ProtocolUtils.readPlayerKey(version, buf));
|
||||
}
|
||||
@ -117,7 +117,7 @@ public class LegacyPlayerListItemPacket implements MinecraftPacket {
|
||||
|
||||
@Override
|
||||
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, items.size());
|
||||
for (Item item : items) {
|
||||
@ -132,7 +132,7 @@ public class LegacyPlayerListItemPacket implements MinecraftPacket {
|
||||
ProtocolUtils.writeVarInt(buf, item.getGameMode());
|
||||
ProtocolUtils.writeVarInt(buf, item.getLatency());
|
||||
writeDisplayName(buf, item.getDisplayName(), version);
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_19)) {
|
||||
if (item.getPlayerKey() != null) {
|
||||
buf.writeBoolean(true);
|
||||
ProtocolUtils.writePlayerKey(buf, item.getPlayerKey());
|
||||
|
@ -64,10 +64,10 @@ public class PluginMessagePacket extends DeferredByteBufHolder implements Minecr
|
||||
@Override
|
||||
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
|
||||
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);
|
||||
}
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_8)) {
|
||||
this.replace(buf.readRetainedSlice(buf.readableBytes()));
|
||||
} else {
|
||||
this.replace(ProtocolUtils.readRetainedByteBufSlice17(buf));
|
||||
@ -86,12 +86,12 @@ public class PluginMessagePacket extends DeferredByteBufHolder implements Minecr
|
||||
+ " 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));
|
||||
} else {
|
||||
ProtocolUtils.writeString(buf, this.channel);
|
||||
}
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_8)) {
|
||||
buf.writeBytes(content());
|
||||
} else {
|
||||
ProtocolUtils.writeByteBuf17(content(), buf, true); // True for Forge support
|
||||
|
@ -86,12 +86,12 @@ public class ResourcePackRequestPacket implements MinecraftPacket {
|
||||
|
||||
@Override
|
||||
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.url = 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();
|
||||
if (buf.readBoolean()) {
|
||||
this.prompt = ComponentHolder.read(buf, protocolVersion);
|
||||
@ -103,7 +103,7 @@ public class ResourcePackRequestPacket implements MinecraftPacket {
|
||||
|
||||
@Override
|
||||
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) {
|
||||
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, hash);
|
||||
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_17) >= 0) {
|
||||
if (protocolVersion.noLessThan(ProtocolVersion.MINECRAFT_1_17)) {
|
||||
buf.writeBoolean(isRequired);
|
||||
if (prompt != null) {
|
||||
buf.writeBoolean(true);
|
||||
|
@ -56,10 +56,10 @@ public class ResourcePackResponsePacket implements MinecraftPacket {
|
||||
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_9_4) <= 0) {
|
||||
if (protocolVersion.noGreaterThan(ProtocolVersion.MINECRAFT_1_9_4)) {
|
||||
this.hash = ProtocolUtils.readString(buf);
|
||||
}
|
||||
this.status = Status.values()[ProtocolUtils.readVarInt(buf)];
|
||||
@ -67,10 +67,10 @@ public class ResourcePackResponsePacket implements MinecraftPacket {
|
||||
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_9_4) <= 0) {
|
||||
if (protocolVersion.noGreaterThan(ProtocolVersion.MINECRAFT_1_9_4)) {
|
||||
ProtocolUtils.writeString(buf, hash);
|
||||
}
|
||||
ProtocolUtils.writeVarInt(buf, status.ordinal());
|
||||
|
@ -162,9 +162,9 @@ public class RespawnPacket implements MinecraftPacket {
|
||||
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
|
||||
String dimensionIdentifier = null;
|
||||
String levelName = null;
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0
|
||||
&& version.compareTo(ProtocolVersion.MINECRAFT_1_19) < 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_16)) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_16_2)
|
||||
&& version.lessThan(ProtocolVersion.MINECRAFT_1_19)) {
|
||||
this.currentDimensionData = ProtocolUtils.readCompoundTag(buf, version, BinaryTagIO.reader());
|
||||
dimensionIdentifier = ProtocolUtils.readString(buf);
|
||||
} else {
|
||||
@ -174,42 +174,42 @@ public class RespawnPacket implements MinecraftPacket {
|
||||
} else {
|
||||
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();
|
||||
}
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_15) >= 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_15)) {
|
||||
this.partialHashedSeed = buf.readLong();
|
||||
}
|
||||
this.gamemode = buf.readByte();
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_16)) {
|
||||
this.previousGamemode = buf.readByte();
|
||||
boolean isDebug = buf.readBoolean();
|
||||
boolean isFlat = buf.readBoolean();
|
||||
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);
|
||||
} else if (version.compareTo(ProtocolVersion.MINECRAFT_1_20_2) < 0) {
|
||||
} else if (version.lessThan(ProtocolVersion.MINECRAFT_1_20_2)) {
|
||||
this.dataToKeep = buf.readByte();
|
||||
}
|
||||
} else {
|
||||
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());
|
||||
}
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_20) >= 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_20)) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0
|
||||
&& version.compareTo(ProtocolVersion.MINECRAFT_1_19) < 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_16)) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_16_2)
|
||||
&& version.lessThan(ProtocolVersion.MINECRAFT_1_19)) {
|
||||
ProtocolUtils.writeBinaryTag(buf, version, currentDimensionData);
|
||||
ProtocolUtils.writeString(buf, dimensionInfo.getRegistryIdentifier());
|
||||
} else {
|
||||
@ -219,20 +219,20 @@ public class RespawnPacket implements MinecraftPacket {
|
||||
} else {
|
||||
buf.writeInt(dimension);
|
||||
}
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_13_2) <= 0) {
|
||||
if (version.noGreaterThan(ProtocolVersion.MINECRAFT_1_13_2)) {
|
||||
buf.writeByte(difficulty);
|
||||
}
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_15) >= 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_15)) {
|
||||
buf.writeLong(partialHashedSeed);
|
||||
}
|
||||
buf.writeByte(gamemode);
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_16)) {
|
||||
buf.writeByte(previousGamemode);
|
||||
buf.writeBoolean(dimensionInfo.isDebugType());
|
||||
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);
|
||||
} else if (version.compareTo(ProtocolVersion.MINECRAFT_1_20_2) < 0) {
|
||||
} else if (version.lessThan(ProtocolVersion.MINECRAFT_1_20_2)) {
|
||||
buf.writeByte(dataToKeep);
|
||||
}
|
||||
} else {
|
||||
@ -240,7 +240,7 @@ public class RespawnPacket implements MinecraftPacket {
|
||||
}
|
||||
|
||||
// optional death location
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_19)) {
|
||||
if (lastDeathPosition != null) {
|
||||
buf.writeBoolean(true);
|
||||
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);
|
||||
}
|
||||
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_20_2) >= 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_20_2)) {
|
||||
buf.writeByte(dataToKeep);
|
||||
}
|
||||
}
|
||||
|
@ -47,12 +47,12 @@ public class ServerDataPacket implements MinecraftPacket {
|
||||
@Override
|
||||
public void decode(ByteBuf buf, ProtocolUtils.Direction direction,
|
||||
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);
|
||||
}
|
||||
if (buf.readBoolean()) {
|
||||
String iconBase64;
|
||||
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_19_4) >= 0) {
|
||||
if (protocolVersion.noLessThan(ProtocolVersion.MINECRAFT_1_19_4)) {
|
||||
byte[] iconBytes = ProtocolUtils.readByteArray(buf);
|
||||
iconBase64 = "data:image/png;base64," + new String(Base64.getEncoder().encode(iconBytes), StandardCharsets.UTF_8);
|
||||
} else {
|
||||
@ -60,10 +60,10 @@ public class ServerDataPacket implements MinecraftPacket {
|
||||
}
|
||||
this.favicon = new Favicon(iconBase64);
|
||||
}
|
||||
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_19_3) < 0) {
|
||||
if (protocolVersion.lessThan(ProtocolVersion.MINECRAFT_1_19_3)) {
|
||||
buf.readBoolean();
|
||||
}
|
||||
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_19_1) >= 0) {
|
||||
if (protocolVersion.noLessThan(ProtocolVersion.MINECRAFT_1_19_1)) {
|
||||
this.secureChatEnforced = buf.readBoolean();
|
||||
}
|
||||
}
|
||||
@ -72,17 +72,17 @@ public class ServerDataPacket implements MinecraftPacket {
|
||||
public void encode(ByteBuf buf, ProtocolUtils.Direction direction,
|
||||
ProtocolVersion protocolVersion) {
|
||||
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);
|
||||
}
|
||||
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_19_4) >= 0 || hasDescription) {
|
||||
if (protocolVersion.noLessThan(ProtocolVersion.MINECRAFT_1_19_4) || hasDescription) {
|
||||
this.description.write(buf);
|
||||
}
|
||||
|
||||
boolean hasFavicon = this.favicon != null;
|
||||
buf.writeBoolean(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());
|
||||
byte[] iconBytes = Base64.getDecoder().decode(cutIconBase64.getBytes(StandardCharsets.UTF_8));
|
||||
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);
|
||||
}
|
||||
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_19_1) >= 0) {
|
||||
if (protocolVersion.noLessThan(ProtocolVersion.MINECRAFT_1_19_1)) {
|
||||
buf.writeBoolean(this.secureChatEnforced);
|
||||
}
|
||||
}
|
||||
|
@ -84,8 +84,8 @@ public class ServerLoginPacket implements MinecraftPacket {
|
||||
throw EMPTY_USERNAME;
|
||||
}
|
||||
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0) {
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19_3) >= 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_19)) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_19_3)) {
|
||||
playerKey = null;
|
||||
} else {
|
||||
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);
|
||||
return;
|
||||
}
|
||||
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19_1) >= 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_19_1)) {
|
||||
if (buf.readBoolean()) {
|
||||
holderUuid = ProtocolUtils.readUuid(buf);
|
||||
}
|
||||
@ -117,8 +117,8 @@ public class ServerLoginPacket implements MinecraftPacket {
|
||||
}
|
||||
ProtocolUtils.writeString(buf, username);
|
||||
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0) {
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19_3) < 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_19)) {
|
||||
if (version.lessThan(ProtocolVersion.MINECRAFT_1_19_3)) {
|
||||
if (playerKey != null) {
|
||||
buf.writeBoolean(true);
|
||||
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);
|
||||
return;
|
||||
}
|
||||
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19_1) >= 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_19_1)) {
|
||||
if (playerKey != null && playerKey.getSignatureHolder() != null) {
|
||||
buf.writeBoolean(true);
|
||||
ProtocolUtils.writeUuid(buf, playerKey.getSignatureHolder());
|
||||
@ -152,8 +152,8 @@ public class ServerLoginPacket implements MinecraftPacket {
|
||||
// legal on the protocol level.
|
||||
int base = 1 + (16 * 3);
|
||||
// Adjustments for Key-authentication
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0) {
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19_3) < 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_19)) {
|
||||
if (version.lessThan(ProtocolVersion.MINECRAFT_1_19_3)) {
|
||||
// + 1 for the boolean present/ not present
|
||||
// + 8 for the long expiry
|
||||
// + 2 len for varint key size
|
||||
@ -162,7 +162,7 @@ public class ServerLoginPacket implements MinecraftPacket {
|
||||
// + 512 for signature
|
||||
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
|
||||
// + 2 * 8 for the long msb/lsb
|
||||
base += 1 + 8 + 8;
|
||||
|
@ -76,18 +76,18 @@ public class ServerLoginSuccessPacket implements MinecraftPacket {
|
||||
|
||||
@Override
|
||||
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);
|
||||
} else if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
|
||||
} else if (version.noLessThan(ProtocolVersion.MINECRAFT_1_16)) {
|
||||
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));
|
||||
} else {
|
||||
uuid = UuidUtils.fromUndashed(ProtocolUtils.readString(buf, 32));
|
||||
}
|
||||
username = ProtocolUtils.readString(buf, 16);
|
||||
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_19)) {
|
||||
properties = ProtocolUtils.readProperties(buf);
|
||||
}
|
||||
}
|
||||
@ -97,11 +97,11 @@ public class ServerLoginSuccessPacket implements MinecraftPacket {
|
||||
if (uuid == null) {
|
||||
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);
|
||||
} else if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
|
||||
} else if (version.noLessThan(ProtocolVersion.MINECRAFT_1_16)) {
|
||||
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());
|
||||
} else {
|
||||
ProtocolUtils.writeString(buf, UuidUtils.toUndashed(uuid));
|
||||
@ -111,7 +111,7 @@ public class ServerLoginSuccessPacket implements MinecraftPacket {
|
||||
}
|
||||
ProtocolUtils.writeString(buf, username);
|
||||
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_19)) {
|
||||
if (properties == null) {
|
||||
ProtocolUtils.writeVarInt(buf, 0);
|
||||
} else {
|
||||
|
@ -95,15 +95,15 @@ public class TabCompleteRequestPacket implements MinecraftPacket {
|
||||
|
||||
@Override
|
||||
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.command = ProtocolUtils.readString(buf, VANILLA_MAX_TAB_COMPLETE_LEN);
|
||||
} else {
|
||||
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();
|
||||
}
|
||||
if (version.compareTo(MINECRAFT_1_8) >= 0) {
|
||||
if (version.noLessThan(MINECRAFT_1_8)) {
|
||||
this.hasPosition = buf.readBoolean();
|
||||
if (hasPosition) {
|
||||
this.position = buf.readLong();
|
||||
@ -118,15 +118,15 @@ public class TabCompleteRequestPacket implements MinecraftPacket {
|
||||
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.writeString(buf, command);
|
||||
} else {
|
||||
ProtocolUtils.writeString(buf, command);
|
||||
if (version.compareTo(MINECRAFT_1_9) >= 0) {
|
||||
if (version.noLessThan(MINECRAFT_1_9)) {
|
||||
buf.writeBoolean(assumeCommand);
|
||||
}
|
||||
if (version.compareTo(MINECRAFT_1_8) >= 0) {
|
||||
if (version.noLessThan(MINECRAFT_1_8)) {
|
||||
buf.writeBoolean(hasPosition);
|
||||
if (hasPosition) {
|
||||
buf.writeLong(position);
|
||||
|
@ -77,7 +77,7 @@ public class TabCompleteResponsePacket implements MinecraftPacket {
|
||||
|
||||
@Override
|
||||
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.start = ProtocolUtils.readVarInt(buf);
|
||||
this.length = ProtocolUtils.readVarInt(buf);
|
||||
@ -97,7 +97,7 @@ public class TabCompleteResponsePacket implements MinecraftPacket {
|
||||
|
||||
@Override
|
||||
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.start);
|
||||
ProtocolUtils.writeVarInt(buf, this.length);
|
||||
|
@ -41,13 +41,13 @@ public class ArgumentIdentifier {
|
||||
VersionSet current = Preconditions.checkNotNull(versions[i]);
|
||||
|
||||
Preconditions.checkArgument(
|
||||
current.getVersion().compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0,
|
||||
current.getVersion().noLessThan(ProtocolVersion.MINECRAFT_1_19),
|
||||
"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");
|
||||
|
||||
for (ProtocolVersion v : ProtocolVersion.values()) {
|
||||
if (v.compareTo(current.getVersion()) >= 0) {
|
||||
if (v.noLessThan(current.getVersion())) {
|
||||
temp.putIfAbsent(v, current.getId());
|
||||
}
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ public class ArgumentPropertyRegistry {
|
||||
*/
|
||||
public static void writeIdentifier(ByteBuf buf, ArgumentIdentifier identifier,
|
||||
ProtocolVersion protocolVersion) {
|
||||
if (protocolVersion.compareTo(MINECRAFT_1_19) >= 0) {
|
||||
if (protocolVersion.noLessThan(MINECRAFT_1_19)) {
|
||||
Integer id = identifier.getIdByProtocolVersion(protocolVersion);
|
||||
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
|
||||
*/
|
||||
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);
|
||||
for (ArgumentIdentifier i : byIdentifier.keySet()) {
|
||||
Integer v = i.getIdByProtocolVersion(protocolVersion);
|
||||
|
@ -34,7 +34,7 @@ class ModArgumentPropertySerializer implements ArgumentPropertySerializer<ModArg
|
||||
@Override
|
||||
public @Nullable ModArgumentProperty deserialize(ByteBuf buf, ProtocolVersion version) {
|
||||
ArgumentIdentifier identifier;
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_19)) {
|
||||
int idx = ProtocolUtils.readVarInt(buf);
|
||||
identifier = ArgumentIdentifier.id("crossstitch:identified_" + (idx < 0 ? "n" + (-idx) : idx),
|
||||
ArgumentIdentifier.mapSet(version, idx));
|
||||
|
@ -26,7 +26,7 @@ public class TimeArgumentSerializer implements ArgumentPropertySerializer<Intege
|
||||
|
||||
@Override
|
||||
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 0;
|
||||
@ -34,7 +34,7 @@ public class TimeArgumentSerializer implements ArgumentPropertySerializer<Intege
|
||||
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -279,7 +279,7 @@ public class ComponentHolder {
|
||||
}
|
||||
|
||||
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,
|
||||
ProtocolUtils.readBinaryTag(buf, version, BinaryTagIO.reader()));
|
||||
} else {
|
||||
@ -288,7 +288,7 @@ public class ComponentHolder {
|
||||
}
|
||||
|
||||
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());
|
||||
} else {
|
||||
ProtocolUtils.writeString(buf, getJson());
|
||||
|
@ -54,7 +54,7 @@ public class SystemChatPacket implements MinecraftPacket {
|
||||
@Override
|
||||
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
|
||||
component.write(buf);
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_19_1) >= 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_19_1)) {
|
||||
switch (type) {
|
||||
case SYSTEM:
|
||||
buf.writeBoolean(false);
|
||||
|
@ -30,9 +30,9 @@ public class ChatBuilderFactory {
|
||||
|
||||
public ChatBuilderFactory(ProtocolVersion 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;
|
||||
} else if (version.compareTo(ProtocolVersion.MINECRAFT_1_19) >= 0) {
|
||||
} else if (version.noLessThan(ProtocolVersion.MINECRAFT_1_19)) {
|
||||
this.builderFunction = KeyedChatBuilder::new;
|
||||
} else {
|
||||
this.builderFunction = LegacyChatBuilder::new;
|
||||
|
@ -105,7 +105,7 @@ public class KeyedChatHandler implements
|
||||
return pme -> {
|
||||
PlayerChatEvent.ChatResult chatResult = pme.getResult();
|
||||
if (!chatResult.isAllowed()) {
|
||||
if (playerKey.getKeyRevision().compareTo(IdentifiedKey.Revision.LINKED_V2) >= 0) {
|
||||
if (playerKey.getKeyRevision().noLessThan(IdentifiedKey.Revision.LINKED_V2)) {
|
||||
// Bad, very bad.
|
||||
invalidCancel(logger, player);
|
||||
}
|
||||
@ -113,7 +113,7 @@ public class KeyedChatHandler implements
|
||||
}
|
||||
|
||||
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.
|
||||
invalidChange(logger, player);
|
||||
} else {
|
||||
|
@ -49,7 +49,7 @@ public class KeyedCommandHandler implements CommandHandler<KeyedPlayerCommandPac
|
||||
if (result == CommandExecuteEvent.CommandResult.denied()) {
|
||||
if (playerKey != null) {
|
||||
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). "
|
||||
+ "This is not supported. "
|
||||
+ "Disconnecting player " + player.getUsername() + ". Command packet: " + packet);
|
||||
@ -72,7 +72,7 @@ public class KeyedCommandHandler implements CommandHandler<KeyedPlayerCommandPac
|
||||
return CompletableFuture.completedFuture(packet);
|
||||
} else {
|
||||
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). "
|
||||
+ "This is not supported. "
|
||||
+ "Disconnecting player " + player.getUsername() + ". Command packet: " + packet);
|
||||
@ -92,7 +92,7 @@ public class KeyedCommandHandler implements CommandHandler<KeyedPlayerCommandPac
|
||||
}
|
||||
|
||||
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). "
|
||||
+ "This is not supported. "
|
||||
+ "Disconnecting player " + player.getUsername() + ". Command packet: " + packet);
|
||||
|
@ -86,7 +86,7 @@ public class KeyedPlayerChatPacket implements MinecraftPacket {
|
||||
salt = Longs.toByteArray(saltLong);
|
||||
signature = signatureBytes;
|
||||
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) {
|
||||
unsigned = true;
|
||||
} else {
|
||||
@ -98,7 +98,7 @@ public class KeyedPlayerChatPacket implements MinecraftPacket {
|
||||
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);
|
||||
if (size < 0 || size > MAXIMUM_PREVIOUS_MESSAGE_COUNT) {
|
||||
throw INVALID_PREVIOUS_MESSAGES;
|
||||
@ -130,7 +130,7 @@ public class KeyedPlayerChatPacket implements MinecraftPacket {
|
||||
|
||||
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);
|
||||
for (SignaturePair previousMessage : previousMessages) {
|
||||
ProtocolUtils.writeUuid(buf, previousMessage.getSigner());
|
||||
|
@ -109,7 +109,7 @@ public class KeyedPlayerCommandPacket implements MinecraftPacket {
|
||||
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);
|
||||
if (size < 0 || size > MAXIMUM_PREVIOUS_MESSAGE_COUNT) {
|
||||
throw INVALID_PREVIOUS_MESSAGES;
|
||||
@ -155,7 +155,7 @@ public class KeyedPlayerCommandPacket implements MinecraftPacket {
|
||||
|
||||
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);
|
||||
for (SignaturePair previousMessage : previousMessages) {
|
||||
ProtocolUtils.writeUuid(buf, previousMessage.getSigner());
|
||||
|
@ -93,9 +93,9 @@ public class LegacyChatPacket implements MinecraftPacket {
|
||||
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
|
||||
message = ProtocolUtils.readString(buf);
|
||||
if (direction == ProtocolUtils.Direction.CLIENTBOUND
|
||||
&& version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
|
||||
&& version.noLessThan(ProtocolVersion.MINECRAFT_1_8)) {
|
||||
type = buf.readByte();
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_16)) {
|
||||
sender = ProtocolUtils.readUuid(buf);
|
||||
}
|
||||
}
|
||||
@ -108,9 +108,9 @@ public class LegacyChatPacket implements MinecraftPacket {
|
||||
}
|
||||
ProtocolUtils.writeString(buf, message);
|
||||
if (direction == ProtocolUtils.Direction.CLIENTBOUND
|
||||
&& version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
|
||||
&& version.noLessThan(ProtocolVersion.MINECRAFT_1_8)) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ public class SessionCommandHandler implements CommandHandler<SessionPlayerComman
|
||||
+ "Contact your network administrator."));
|
||||
}
|
||||
// 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(null);
|
||||
@ -108,7 +108,7 @@ public class SessionCommandHandler implements CommandHandler<SessionPlayerComman
|
||||
.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 null;
|
||||
|
@ -40,7 +40,7 @@ public abstract class GenericTitlePacket implements MinecraftPacket {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -104,7 +104,7 @@ public abstract class GenericTitlePacket implements MinecraftPacket {
|
||||
*/
|
||||
public static GenericTitlePacket constructTitlePacket(ActionType type, ProtocolVersion version) {
|
||||
GenericTitlePacket packet = null;
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_17) >= 0) {
|
||||
if (version.noLessThan(ProtocolVersion.MINECRAFT_1_17)) {
|
||||
switch (type) {
|
||||
case SET_ACTION_BAR:
|
||||
packet = new TitleActionbarPacket();
|
||||
|
@ -33,7 +33,7 @@ public class LegacyTitlePacket extends GenericTitlePacket {
|
||||
|
||||
@Override
|
||||
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) {
|
||||
throw new IllegalStateException("Action bars are only supported on 1.11 and newer");
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ public final class PluginMessageUtil {
|
||||
Collection<String> channels) {
|
||||
checkNotNull(channels, "channels");
|
||||
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;
|
||||
ByteBuf contents = Unpooled.buffer();
|
||||
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());
|
||||
|
||||
ByteBuf rewrittenBuf = Unpooled.buffer();
|
||||
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
|
||||
if (protocolVersion.noLessThan(ProtocolVersion.MINECRAFT_1_8)) {
|
||||
ProtocolUtils.writeString(rewrittenBuf, rewrittenBrand);
|
||||
} else {
|
||||
rewrittenBuf.writeCharSequence(rewrittenBrand, StandardCharsets.UTF_8);
|
||||
|
@ -115,7 +115,7 @@ public class VelocityChannelRegistrar implements ChannelRegistrar {
|
||||
* @return the list of channels to register
|
||||
*/
|
||||
public Collection<String> getChannelsForProtocol(ProtocolVersion protocolVersion) {
|
||||
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_13) >= 0) {
|
||||
if (protocolVersion.noLessThan(ProtocolVersion.MINECRAFT_1_13)) {
|
||||
return getModernChannelIds();
|
||||
}
|
||||
return getLegacyChannelIds();
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren