geforkt von Mirrors/Velocity
Merge branch 'Xernium-future/1.16' into future/1.16-velocity-1.1.0
# Conflicts: # .travis.yml # api/src/main/java/com/velocitypowered/api/network/ProtocolVersion.java # build.gradle # proxy/build.gradle # proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java # proxy/src/main/java/com/velocitypowered/proxy/connection/backend/VelocityServerConnection.java # proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java # proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java # proxy/src/main/java/com/velocitypowered/proxy/network/netty/DiscardHandler.java # proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java # proxy/src/main/java/com/velocitypowered/proxy/protocol/StateRegistry.java # proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCompressDecoder.java # proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftDecoder.java # proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/JoinGame.java # proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/Respawn.java # proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/ServerLoginSuccess.java # proxy/src/test/java/com/velocitypowered/proxy/plugin/util/PluginDependencyUtilsTest.java
Dieser Commit ist enthalten in:
Commit
ada35ff286
@ -36,7 +36,8 @@ public enum ProtocolVersion {
|
||||
MINECRAFT_1_14_4(498, "1.14.4"),
|
||||
MINECRAFT_1_15(573, "1.15"),
|
||||
MINECRAFT_1_15_1(575, "1.15.1"),
|
||||
MINECRAFT_1_15_2(578, "1.15.2");
|
||||
MINECRAFT_1_15_2(578, "1.15.2"),
|
||||
MINECRAFT_1_16(734, "1.16");
|
||||
|
||||
private final int protocol;
|
||||
private final String name;
|
||||
|
@ -24,7 +24,7 @@ allprojects {
|
||||
junitVersion = '5.3.0-M1'
|
||||
slf4jVersion = '1.7.25'
|
||||
log4jVersion = '2.11.2'
|
||||
nettyVersion = '4.1.50.Final'
|
||||
nettyVersion = '4.1.49.Final'
|
||||
guavaVersion = '25.1-jre'
|
||||
checkerFrameworkVersion = '2.7.0'
|
||||
configurateVersion = '3.6'
|
||||
|
@ -48,7 +48,6 @@ dependencies {
|
||||
compile "io.netty:netty-handler:${nettyVersion}"
|
||||
compile "io.netty:netty-transport-native-epoll:${nettyVersion}"
|
||||
compile "io.netty:netty-transport-native-epoll:${nettyVersion}:linux-x86_64"
|
||||
compile "io.netty:netty-transport-native-kqueue:${nettyVersion}"
|
||||
compile "io.netty:netty-transport-native-kqueue:${nettyVersion}:osx-x86_64"
|
||||
compile "io.netty:netty-resolver-dns:${nettyVersion}"
|
||||
|
||||
@ -64,11 +63,12 @@ dependencies {
|
||||
|
||||
compile 'it.unimi.dsi:fastutil:8.2.3'
|
||||
compile 'net.kyori:event-method-asm:3.0.0'
|
||||
compile 'net.kyori:nbt:1.12-1.0.0-SNAPSHOT'
|
||||
|
||||
compile 'com.mojang:brigadier:1.0.17'
|
||||
|
||||
|
||||
compile 'org.asynchttpclient:async-http-client:2.10.4'
|
||||
|
||||
|
||||
compile 'com.spotify:completable-futures:0.3.2'
|
||||
|
||||
testCompile "org.junit.jupiter:junit-jupiter-api:${junitVersion}"
|
||||
|
@ -17,6 +17,7 @@ import com.velocitypowered.proxy.connection.ConnectionTypes;
|
||||
import com.velocitypowered.proxy.connection.MinecraftConnection;
|
||||
import com.velocitypowered.proxy.connection.MinecraftConnectionAssociation;
|
||||
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
|
||||
import com.velocitypowered.proxy.connection.registry.DimensionRegistry;
|
||||
import com.velocitypowered.proxy.connection.util.ConnectionRequestResults.Impl;
|
||||
import com.velocitypowered.proxy.protocol.StateRegistry;
|
||||
import com.velocitypowered.proxy.protocol.packet.Handshake;
|
||||
@ -43,6 +44,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
|
||||
private BackendConnectionPhase connectionPhase = BackendConnectionPhases.UNKNOWN;
|
||||
private long lastPingId;
|
||||
private long lastPingSent;
|
||||
private @MonotonicNonNull DimensionRegistry activeDimensionRegistry;
|
||||
|
||||
/**
|
||||
* Initializes a new server connection.
|
||||
@ -296,4 +298,11 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
|
||||
return hasCompletedJoin;
|
||||
}
|
||||
|
||||
public DimensionRegistry getActiveDimensionRegistry() {
|
||||
return activeDimensionRegistry;
|
||||
}
|
||||
|
||||
public void setActiveDimensionRegistry(DimensionRegistry activeDimensionRegistry) {
|
||||
this.activeDimensionRegistry = activeDimensionRegistry;
|
||||
}
|
||||
}
|
||||
|
@ -301,6 +301,8 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
||||
spawned = true;
|
||||
player.getConnection().delayedWrite(joinGame);
|
||||
|
||||
destination.setActiveDimensionRegistry(joinGame.getDimensionRegistry()); // 1.16
|
||||
player.getMinecraftConnection().delayedWrite(joinGame);
|
||||
// Required for Legacy Forge
|
||||
player.getPhase().onFirstJoin(player);
|
||||
} else {
|
||||
@ -315,12 +317,23 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
||||
// Most notably, by having the client accept the join game packet, we can work around the need
|
||||
// to perform entity ID rewrites, eliminating potential issues from rewriting packets and
|
||||
// improving compatibility with mods.
|
||||
int realDim = joinGame.getDimension();
|
||||
joinGame.setDimension(getFakeTemporaryDimensionId(realDim));
|
||||
player.getConnection().delayedWrite(joinGame);
|
||||
player.getConnection().delayedWrite(
|
||||
new Respawn(realDim, joinGame.getPartialHashedSeed(), joinGame.getDifficulty(),
|
||||
joinGame.getGamemode(), joinGame.getLevelType()));
|
||||
player.getMinecraftConnection().delayedWrite(joinGame);
|
||||
// Since 1.16 this dynamic changed:
|
||||
// We don't need to send two dimension swiches anymore!
|
||||
if (player.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_16) < 0) {
|
||||
int tempDim = joinGame.getDimension() == 0 ? -1 : 0;
|
||||
player.getMinecraftConnection().delayedWrite(
|
||||
new Respawn(tempDim, joinGame.getPartialHashedSeed(), joinGame.getDifficulty(),
|
||||
joinGame.getGamemode(), joinGame.getLevelType(),
|
||||
false, joinGame.getDimensionInfo(), joinGame.getPreviousGamemode()));
|
||||
}
|
||||
|
||||
player.getMinecraftConnection().delayedWrite(
|
||||
new Respawn(joinGame.getDimension(), joinGame.getPartialHashedSeed(),
|
||||
joinGame.getDifficulty(), joinGame.getGamemode(), joinGame.getLevelType(),
|
||||
false, joinGame.getDimensionInfo(), joinGame.getPreviousGamemode()));
|
||||
|
||||
destination.setActiveDimensionRegistry(joinGame.getDimensionRegistry()); // 1.16
|
||||
}
|
||||
|
||||
// Remove previous boss bars. These don't get cleared when sending JoinGame, thus the need to
|
||||
@ -357,10 +370,6 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
||||
destination.completeJoin();
|
||||
}
|
||||
|
||||
private static int getFakeTemporaryDimensionId(int dim) {
|
||||
return dim == 0 ? -1 : 0;
|
||||
}
|
||||
|
||||
public List<UUID> getServerBossBars() {
|
||||
return serverBossBars;
|
||||
}
|
||||
|
@ -61,6 +61,7 @@ import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import net.kyori.text.Component;
|
||||
import net.kyori.text.TextComponent;
|
||||
|
@ -17,7 +17,10 @@ import com.velocitypowered.api.event.player.GameProfileRequestEvent;
|
||||
import com.velocitypowered.api.event.player.PlayerChooseInitialServerEvent;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import com.velocitypowered.api.util.GameProfile;
|
||||
import com.velocitypowered.api.util.UuidUtils;
|
||||
import com.velocitypowered.proxy.VelocityServer;
|
||||
import com.velocitypowered.proxy.config.PlayerInfoForwarding;
|
||||
import com.velocitypowered.proxy.config.VelocityConfiguration;
|
||||
import com.velocitypowered.proxy.connection.MinecraftConnection;
|
||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||
import com.velocitypowered.proxy.protocol.StateRegistry;
|
||||
@ -34,6 +37,7 @@ import java.security.GeneralSecurityException;
|
||||
import java.security.KeyPair;
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
@ -228,10 +232,14 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
||||
mcConnection.write(new SetCompression(threshold));
|
||||
mcConnection.setCompressionThreshold(threshold);
|
||||
}
|
||||
|
||||
VelocityConfiguration configuration = server.getConfiguration();
|
||||
UUID playerUniqueId = player.getUniqueId();
|
||||
if (configuration.getPlayerInfoForwardingMode() == PlayerInfoForwarding.NONE) {
|
||||
playerUniqueId = UuidUtils.generateOfflinePlayerUuid(player.getUsername());
|
||||
}
|
||||
ServerLoginSuccess success = new ServerLoginSuccess();
|
||||
success.setUsername(player.getUsername());
|
||||
success.setUuid(player.getUniqueId());
|
||||
success.setUuid(playerUniqueId);
|
||||
mcConnection.write(success);
|
||||
|
||||
mcConnection.setAssociation(player);
|
||||
|
@ -0,0 +1,193 @@
|
||||
package com.velocitypowered.proxy.connection.registry;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.kyori.nbt.CompoundTag;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public final class DimensionData {
|
||||
private final String registryIdentifier;
|
||||
private final boolean isNatural;
|
||||
private final float ambientLight;
|
||||
private final boolean isShrunk;
|
||||
private final boolean isUltrawarm;
|
||||
private final boolean hasCeiling;
|
||||
private final boolean hasSkylight;
|
||||
private final boolean isPiglinSafe;
|
||||
private final boolean doBedsWork;
|
||||
private final boolean doRespawnAnchorsWork;
|
||||
private final boolean hasRaids;
|
||||
private final int logicalHeight;
|
||||
private final String burningBehaviourIdentifier;
|
||||
private final @Nullable Long fixedTime;
|
||||
private final @Nullable Boolean createDragonFight;
|
||||
|
||||
/**
|
||||
* Initializes a new {@link DimensionData} instance.
|
||||
* @param registryIdentifier the identifier for the dimension from the registry.
|
||||
* @param isNatural indicates if the dimension use natural world generation (e.g. overworld)
|
||||
* @param ambientLight the light level the client sees without external lighting
|
||||
* @param isShrunk indicates if the world is shrunk, aka not the full 256 blocks (e.g. nether)
|
||||
* @param isUltrawarm internal dimension warmth flag
|
||||
* @param hasCeiling indicates if the dimension has a ceiling layer
|
||||
* @param hasSkylight indicates if the dimension should display the sun
|
||||
* @param isPiglinSafe indicates if piglins should naturally zombify in this dimension
|
||||
* @param doBedsWork indicates if players should be able to sleep in beds in this dimension
|
||||
* @param doRespawnAnchorsWork indicates if player respawn points can be used in this dimension
|
||||
* @param hasRaids indicates if raids can be spawned in the dimension
|
||||
* @param logicalHeight the natural max height for the given dimension
|
||||
* @param burningBehaviourIdentifier the identifier for how burning blocks work in the dimension
|
||||
* @param fixedTime optional. If set to any game daytime value will deactivate time cycle
|
||||
* @param createDragonFight optional. Internal flag used in the end dimension
|
||||
*/
|
||||
public DimensionData(String registryIdentifier, boolean isNatural,
|
||||
float ambientLight, boolean isShrunk, boolean isUltrawarm,
|
||||
boolean hasCeiling, boolean hasSkylight,
|
||||
boolean isPiglinSafe, boolean doBedsWork,
|
||||
boolean doRespawnAnchorsWork, boolean hasRaids,
|
||||
int logicalHeight, String burningBehaviourIdentifier,
|
||||
@Nullable Long fixedTime, @Nullable Boolean createDragonFight) {
|
||||
Preconditions.checkNotNull(
|
||||
registryIdentifier, "registryIdentifier cannot be null");
|
||||
Preconditions.checkArgument(registryIdentifier.length() > 0 && !registryIdentifier.isBlank(),
|
||||
"registryIdentifier cannot be empty");
|
||||
Preconditions.checkArgument(logicalHeight >= 0, "localHeight must be >= 0");
|
||||
Preconditions.checkNotNull(
|
||||
burningBehaviourIdentifier, "burningBehaviourIdentifier cannot be null");
|
||||
Preconditions.checkArgument(burningBehaviourIdentifier.length() > 0
|
||||
&& !burningBehaviourIdentifier.isBlank(),
|
||||
"burningBehaviourIdentifier cannot be empty");
|
||||
this.registryIdentifier = registryIdentifier;
|
||||
this.isNatural = isNatural;
|
||||
this.ambientLight = ambientLight;
|
||||
this.isShrunk = isShrunk;
|
||||
this.isUltrawarm = isUltrawarm;
|
||||
this.hasCeiling = hasCeiling;
|
||||
this.hasSkylight = hasSkylight;
|
||||
this.isPiglinSafe = isPiglinSafe;
|
||||
this.doBedsWork = doBedsWork;
|
||||
this.doRespawnAnchorsWork = doRespawnAnchorsWork;
|
||||
this.hasRaids = hasRaids;
|
||||
this.logicalHeight = logicalHeight;
|
||||
this.burningBehaviourIdentifier = burningBehaviourIdentifier;
|
||||
this.fixedTime = fixedTime;
|
||||
this.createDragonFight = createDragonFight;
|
||||
}
|
||||
|
||||
public String getRegistryIdentifier() {
|
||||
return registryIdentifier;
|
||||
}
|
||||
|
||||
public boolean isNatural() {
|
||||
return isNatural;
|
||||
}
|
||||
|
||||
public float getAmbientLight() {
|
||||
return ambientLight;
|
||||
}
|
||||
|
||||
public boolean isShrunk() {
|
||||
return isShrunk;
|
||||
}
|
||||
|
||||
public boolean isUltrawarm() {
|
||||
return isUltrawarm;
|
||||
}
|
||||
|
||||
public boolean hasCeiling() {
|
||||
return hasCeiling;
|
||||
}
|
||||
|
||||
public boolean hasSkylight() {
|
||||
return hasSkylight;
|
||||
}
|
||||
|
||||
public boolean isPiglinSafe() {
|
||||
return isPiglinSafe;
|
||||
}
|
||||
|
||||
public boolean doBedsWork() {
|
||||
return doBedsWork;
|
||||
}
|
||||
|
||||
public boolean doRespawnAnchorsWork() {
|
||||
return doRespawnAnchorsWork;
|
||||
}
|
||||
|
||||
public boolean hasRaids() {
|
||||
return hasRaids;
|
||||
}
|
||||
|
||||
public int getLogicalHeight() {
|
||||
return logicalHeight;
|
||||
}
|
||||
|
||||
public String getBurningBehaviourIdentifier() {
|
||||
return burningBehaviourIdentifier;
|
||||
}
|
||||
|
||||
public @Nullable Long getFixedTime() {
|
||||
return fixedTime;
|
||||
}
|
||||
|
||||
public @Nullable Boolean getCreateDragonFight() {
|
||||
return createDragonFight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a given CompoundTag to a DimensionData instance.
|
||||
* @param toRead the compound from the registry to read
|
||||
* @return game dimension data
|
||||
*/
|
||||
public static DimensionData decodeCompoundTag(CompoundTag toRead) {
|
||||
Preconditions.checkNotNull(toRead, "CompoundTag cannot be null");
|
||||
String registryIdentifier = toRead.getString("name");
|
||||
boolean isNatural = toRead.getBoolean("natural");
|
||||
float ambientLight = toRead.getFloat("ambient_light");
|
||||
boolean isShrunk = toRead.getBoolean("shrunk");
|
||||
boolean isUltrawarm = toRead.getBoolean("ultrawarm");
|
||||
boolean hasCeiling = toRead.getBoolean("has_ceiling");
|
||||
boolean hasSkylight = toRead.getBoolean("has_skylight");
|
||||
boolean isPiglinSafe = toRead.getBoolean("piglin_safe");
|
||||
boolean doBedsWork = toRead.getBoolean("bed_works");
|
||||
boolean doRespawnAnchorsWork = toRead.getBoolean("respawn_anchor_works");
|
||||
boolean hasRaids = toRead.getBoolean("has_raids");
|
||||
int logicalHeight = toRead.getInt("logical_height");
|
||||
String burningBehaviourIdentifier = toRead.getString("infiniburn");
|
||||
Long fixedTime = toRead.contains("fixed_time")
|
||||
? toRead.getLong("fixed_time") : null;
|
||||
Boolean hasEnderdragonFight = toRead.contains("has_enderdragon_fight")
|
||||
? toRead.getBoolean("has_enderdragon_fight") : null;
|
||||
return new DimensionData(
|
||||
registryIdentifier, isNatural, ambientLight, isShrunk,
|
||||
isUltrawarm, hasCeiling, hasSkylight, isPiglinSafe, doBedsWork, doRespawnAnchorsWork,
|
||||
hasRaids, logicalHeight, burningBehaviourIdentifier, fixedTime, hasEnderdragonFight);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes the Dimension data as CompoundTag.
|
||||
* @return compound containing the dimension data
|
||||
*/
|
||||
public CompoundTag encodeAsCompundTag() {
|
||||
CompoundTag ret = new CompoundTag();
|
||||
ret.putString("name", registryIdentifier);
|
||||
ret.putBoolean("natural", isNatural);
|
||||
ret.putFloat("ambient_light", ambientLight);
|
||||
ret.putBoolean("shrunk", isShrunk);
|
||||
ret.putBoolean("ultrawarm", isUltrawarm);
|
||||
ret.putBoolean("has_ceiling", hasCeiling);
|
||||
ret.putBoolean("has_skylight", hasSkylight);
|
||||
ret.putBoolean("piglin_safe", isPiglinSafe);
|
||||
ret.putBoolean("bed_works", doBedsWork);
|
||||
ret.putBoolean("respawn_anchor_works", doRespawnAnchorsWork);
|
||||
ret.putBoolean("has_raids", hasRaids);
|
||||
ret.putInt("logical_height", logicalHeight);
|
||||
ret.putString("infiniburn", burningBehaviourIdentifier);
|
||||
if (fixedTime != null) {
|
||||
ret.putLong("fixed_time", fixedTime);
|
||||
}
|
||||
if (createDragonFight != null) {
|
||||
ret.putBoolean("has_enderdragon_fight", createDragonFight);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package com.velocitypowered.proxy.connection.registry;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
public final class DimensionInfo {
|
||||
|
||||
private final String registryIdentifier;
|
||||
private final String levelName;
|
||||
private final boolean isFlat;
|
||||
private final boolean isDebugType;
|
||||
|
||||
/**
|
||||
* Initializes a new {@link DimensionInfo} instance.
|
||||
* @param registryIdentifier the identifier for the dimension from the registry
|
||||
* @param levelName the level name as displayed in the F3 menu and logs
|
||||
* @param isFlat if true will set world lighting below surface-level to not display fog
|
||||
* @param isDebugType if true constrains the world to the very limited debug-type world
|
||||
*/
|
||||
public DimensionInfo(String registryIdentifier, String levelName,
|
||||
boolean isFlat, boolean isDebugType) {
|
||||
this.registryIdentifier = Preconditions.checkNotNull(
|
||||
registryIdentifier, "registryIdentifier cannot be null");
|
||||
Preconditions.checkArgument(
|
||||
registryIdentifier.length() > 0 && !registryIdentifier.isBlank(),
|
||||
"registryIdentifier cannot be empty");
|
||||
this.levelName = Preconditions.checkNotNull(
|
||||
levelName, "levelName cannot be null");
|
||||
Preconditions.checkArgument(
|
||||
levelName.length() > 0 && !levelName.isBlank(),
|
||||
"registryIdentifier cannot be empty");
|
||||
this.isFlat = isFlat;
|
||||
this.isDebugType = isDebugType;
|
||||
}
|
||||
|
||||
public boolean isDebugType() {
|
||||
return isDebugType;
|
||||
}
|
||||
|
||||
public boolean isFlat() {
|
||||
return isFlat;
|
||||
}
|
||||
|
||||
public String getLevelName() {
|
||||
return levelName;
|
||||
}
|
||||
|
||||
public String getRegistryIdentifier() {
|
||||
return registryIdentifier;
|
||||
}
|
||||
}
|
@ -0,0 +1,109 @@
|
||||
package com.velocitypowered.proxy.connection.registry;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.kyori.nbt.CompoundTag;
|
||||
import net.kyori.nbt.ListTag;
|
||||
import net.kyori.nbt.Tag;
|
||||
import net.kyori.nbt.TagType;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
|
||||
public final class DimensionRegistry {
|
||||
|
||||
private final Map<String, DimensionData> registeredDimensions;
|
||||
private final ImmutableSet<String> levelNames;
|
||||
|
||||
/**
|
||||
* Initializes a new {@link DimensionRegistry} instance.
|
||||
* This registry is required for 1.16+ clients/servers to communicate,
|
||||
* it constrains the dimension types and names the client can be sent
|
||||
* in a Respawn action (dimension change).
|
||||
* This WILL raise an IllegalArgumentException if the following is not met:
|
||||
* - At least one valid DimensionData instance is provided
|
||||
* - At least one valid world name is provided
|
||||
* @param registeredDimensions a populated {@link ImmutableSet} containing dimension data types
|
||||
* @param levelNames a populated {@link ImmutableSet} of the level (world) names the server offers
|
||||
*/
|
||||
public DimensionRegistry(ImmutableSet<DimensionData> registeredDimensions,
|
||||
ImmutableSet<String> levelNames) {
|
||||
Preconditions.checkNotNull(registeredDimensions,
|
||||
"registeredDimensions cannot be null");
|
||||
Preconditions.checkNotNull(levelNames,
|
||||
"levelNames cannot be null");
|
||||
Preconditions.checkArgument(registeredDimensions.size() > 0,
|
||||
"registeredDimensions needs to be populated");
|
||||
Preconditions.checkArgument(levelNames.size() > 0,
|
||||
"levelNames needs to populated");
|
||||
this.registeredDimensions = Maps.uniqueIndex(
|
||||
registeredDimensions, DimensionData::getRegistryIdentifier);
|
||||
this.levelNames = levelNames;
|
||||
}
|
||||
|
||||
public Map<String, DimensionData> getRegisteredDimensions() {
|
||||
return registeredDimensions;
|
||||
}
|
||||
|
||||
public Set<String> getLevelNames() {
|
||||
return levelNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the internal dimension data type as used by the game.
|
||||
* @param dimensionIdentifier how the dimension is identified by the connection
|
||||
* @return game dimension data or null if not registered
|
||||
*/
|
||||
public @Nullable DimensionData getDimensionData(String dimensionIdentifier) {
|
||||
return registeredDimensions.get(dimensionIdentifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks a {@link DimensionInfo} against this registry.
|
||||
* @param toValidate the {@link DimensionInfo} to validate
|
||||
* @return true: the dimension information is valid for this registry
|
||||
*/
|
||||
public boolean isValidFor(DimensionInfo toValidate) {
|
||||
if (toValidate == null) {
|
||||
return false;
|
||||
}
|
||||
return registeredDimensions.containsKey(toValidate.getRegistryIdentifier())
|
||||
&& levelNames.contains(toValidate.getLevelName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes the stored Dimension registry as CompoundTag.
|
||||
* @return the CompoundTag containing identifier:type mappings
|
||||
*/
|
||||
public CompoundTag encodeRegistry() {
|
||||
CompoundTag ret = new CompoundTag();
|
||||
ListTag list = new ListTag(TagType.COMPOUND);
|
||||
for (DimensionData iter : registeredDimensions.values()) {
|
||||
list.add(iter.encodeAsCompundTag());
|
||||
}
|
||||
ret.put("dimension", list);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes a CompoundTag storing a dimension registry.
|
||||
* @param toParse CompoundTag containing a dimension registry
|
||||
*/
|
||||
public static ImmutableSet<DimensionData> fromGameData(CompoundTag toParse) {
|
||||
Preconditions.checkNotNull(toParse, "CompoundTag cannot be null");
|
||||
Preconditions.checkArgument(toParse.contains("dimension", TagType.LIST),
|
||||
"CompoundTag does not contain a dimension list");
|
||||
ListTag dimensions = toParse.getList("dimension");
|
||||
ImmutableSet.Builder<DimensionData> mappings = ImmutableSet.builder();
|
||||
for (Tag iter : dimensions) {
|
||||
if (iter instanceof CompoundTag) {
|
||||
mappings.add(DimensionData.decodeCompoundTag((CompoundTag) iter));
|
||||
}
|
||||
}
|
||||
return mappings.build();
|
||||
}
|
||||
}
|
@ -9,13 +9,25 @@ import com.velocitypowered.api.util.GameProfile;
|
||||
import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder;
|
||||
import com.velocitypowered.proxy.util.except.QuietException;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufInputStream;
|
||||
import io.netty.buffer.ByteBufOutputStream;
|
||||
import io.netty.buffer.ByteBufUtil;
|
||||
import io.netty.handler.codec.CorruptedFrameException;
|
||||
import io.netty.handler.codec.DecoderException;
|
||||
import io.netty.handler.codec.EncoderException;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import net.kyori.nbt.CompoundTag;
|
||||
import net.kyori.nbt.TagIO;
|
||||
import net.kyori.nbt.TagType;
|
||||
|
||||
public enum ProtocolUtils {
|
||||
;
|
||||
private static final int DEFAULT_MAX_STRING_SIZE = 65536; // 64KiB
|
||||
@ -180,6 +192,100 @@ public enum ProtocolUtils {
|
||||
buf.writeLong(uuid.getLeastSignificantBits());
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an UUID stored as an Integer Array from the {@code buf}.
|
||||
* @param buf the buffer to read from
|
||||
* @return the UUID from the buffer
|
||||
*/
|
||||
public static UUID readUuidIntArray(ByteBuf buf) {
|
||||
long msbHigh = (long) buf.readInt() << 32;
|
||||
long msbLow = (long) buf.readInt() & 0xFFFFFFFFL;
|
||||
long msb = msbHigh | msbLow;
|
||||
long lsbHigh = (long) buf.readInt() << 32;
|
||||
long lsbLow = (long) buf.readInt() & 0xFFFFFFFFL;
|
||||
long lsb = lsbHigh | lsbLow;
|
||||
return new UUID(msb, lsb);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes an UUID as an Integer Array to the {@code buf}.
|
||||
* @param buf the buffer to write to
|
||||
* @param uuid the UUID to write
|
||||
*/
|
||||
public static void writeUuidIntArray(ByteBuf buf, UUID uuid) {
|
||||
buf.writeInt((int) (uuid.getMostSignificantBits() >> 32));
|
||||
buf.writeInt((int) uuid.getMostSignificantBits());
|
||||
buf.writeInt((int) (uuid.getLeastSignificantBits() >> 32));
|
||||
buf.writeInt((int) uuid.getLeastSignificantBits());
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a {@link net.kyori.nbt.CompoundTag} from the {@code buf}.
|
||||
* @param buf the buffer to read from
|
||||
* @return {@link net.kyori.nbt.CompoundTag} the CompoundTag from the buffer
|
||||
*/
|
||||
public static CompoundTag readCompoundTag(ByteBuf buf) {
|
||||
int indexBefore = buf.readerIndex();
|
||||
byte startType = buf.readByte();
|
||||
if (startType == 0) {
|
||||
throw new DecoderException("Invalid NBT start-type (end/empty)");
|
||||
}
|
||||
buf.readerIndex(indexBefore);
|
||||
try {
|
||||
return TagIO.readDataInput(new ByteBufInputStream(buf));
|
||||
} catch (IOException thrown) {
|
||||
throw new DecoderException(
|
||||
"Unable to parse NBT CompoundTag, full error: " + thrown.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a CompoundTag to the {@code buf}.
|
||||
* @param buf the buffer to write to
|
||||
* @param compoundTag the CompoundTag to write
|
||||
*/
|
||||
public static void writeCompoundTag(ByteBuf buf, CompoundTag compoundTag) {
|
||||
if (compoundTag == null) {
|
||||
buf.writeByte(0);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
TagIO.writeDataOutput(compoundTag, new ByteBufOutputStream(buf));
|
||||
} catch (IOException e) {
|
||||
throw new EncoderException("Unable to encode NBT CompoundTag");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a String array from the {@code buf}.
|
||||
* @param buf the buffer to read from
|
||||
* @return the String array from the buffer
|
||||
*/
|
||||
public static String[] readStringArray(ByteBuf buf) {
|
||||
int length = readVarInt(buf);
|
||||
String[] ret = new String[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
ret[i] = readString(buf);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a String Array to the {@code buf}.
|
||||
* @param buf the buffer to write to
|
||||
* @param stringArray the array to write
|
||||
*/
|
||||
public static void writeStringArray(ByteBuf buf, String[] stringArray) {
|
||||
if (stringArray == null) {
|
||||
writeVarInt(buf, 0);
|
||||
return;
|
||||
}
|
||||
writeVarInt(buf, stringArray.length);
|
||||
for (int i = 0; i < stringArray.length; i++) {
|
||||
writeString(buf, stringArray[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a list of {@link com.velocitypowered.api.util.GameProfile.Property} to the buffer.
|
||||
* @param buf the buffer to write to
|
||||
|
@ -6,7 +6,7 @@ import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_12_1;
|
||||
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_13;
|
||||
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_14;
|
||||
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_15;
|
||||
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_7_2;
|
||||
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_16;
|
||||
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_8;
|
||||
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_9;
|
||||
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_9_4;
|
||||
@ -112,54 +112,64 @@ public enum StateRegistry {
|
||||
map(0x0C, MINECRAFT_1_12, false),
|
||||
map(0x0B, MINECRAFT_1_12_1, false),
|
||||
map(0x0E, MINECRAFT_1_13, false),
|
||||
map(0x0F, MINECRAFT_1_14, false));
|
||||
map(0x0F, MINECRAFT_1_14, false),
|
||||
map(0x10, MINECRAFT_1_16, false));
|
||||
serverbound.register(ResourcePackResponse.class, ResourcePackResponse::new,
|
||||
map(0x19, MINECRAFT_1_8, false),
|
||||
map(0x16, MINECRAFT_1_9, false),
|
||||
map(0x18, MINECRAFT_1_12, false),
|
||||
map(0x1D, MINECRAFT_1_13, false),
|
||||
map(0x1F, MINECRAFT_1_14, false));
|
||||
map(0x1F, MINECRAFT_1_14, false),
|
||||
map(0x20, MINECRAFT_1_16, false));
|
||||
|
||||
clientbound.register(BossBar.class, BossBar::new,
|
||||
map(0x0C, MINECRAFT_1_9, false),
|
||||
map(0x0D, MINECRAFT_1_15, false));
|
||||
map(0x0D, MINECRAFT_1_15, false),
|
||||
map(0x0C, MINECRAFT_1_16, false));
|
||||
clientbound.register(Chat.class, Chat::new,
|
||||
map(0x02, MINECRAFT_1_7_2, true),
|
||||
map(0x0F, MINECRAFT_1_9, true),
|
||||
map(0x0E, MINECRAFT_1_13, true),
|
||||
map(0x0F, MINECRAFT_1_15, true));
|
||||
map(0x0F, MINECRAFT_1_15, true),
|
||||
map(0x0E, MINECRAFT_1_16, true));
|
||||
clientbound.register(TabCompleteResponse.class, TabCompleteResponse::new,
|
||||
map(0x3A, MINECRAFT_1_7_2, false),
|
||||
map(0x0E, MINECRAFT_1_9, false),
|
||||
map(0x10, MINECRAFT_1_13, false),
|
||||
map(0x11, MINECRAFT_1_15, false));
|
||||
map(0x11, MINECRAFT_1_15, false),
|
||||
map(0x10, MINECRAFT_1_16, false));
|
||||
clientbound.register(AvailableCommands.class, AvailableCommands::new,
|
||||
map(0x11, MINECRAFT_1_13, false),
|
||||
map(0x12, MINECRAFT_1_15, false));
|
||||
map(0x12, MINECRAFT_1_15, false),
|
||||
map(0x11, MINECRAFT_1_16, false));
|
||||
clientbound.register(PluginMessage.class, PluginMessage::new,
|
||||
map(0x3F, MINECRAFT_1_7_2, false),
|
||||
map(0x18, MINECRAFT_1_9, false),
|
||||
map(0x19, MINECRAFT_1_13, false),
|
||||
map(0x18, MINECRAFT_1_14, false),
|
||||
map(0x19, MINECRAFT_1_15, false));
|
||||
map(0x19, MINECRAFT_1_15, false),
|
||||
map(0x18, MINECRAFT_1_16, false));
|
||||
clientbound.register(Disconnect.class, Disconnect::new,
|
||||
map(0x40, MINECRAFT_1_7_2, false),
|
||||
map(0x1A, MINECRAFT_1_9, false),
|
||||
map(0x1B, MINECRAFT_1_13, false),
|
||||
map(0x1A, MINECRAFT_1_14, false),
|
||||
map(0x1B, MINECRAFT_1_15, false));
|
||||
map(0x1B, MINECRAFT_1_15, false),
|
||||
map(0x1A, MINECRAFT_1_16, false));
|
||||
clientbound.register(KeepAlive.class, KeepAlive::new,
|
||||
map(0x00, MINECRAFT_1_7_2, false),
|
||||
map(0x1F, MINECRAFT_1_9, false),
|
||||
map(0x21, MINECRAFT_1_13, false),
|
||||
map(0x20, MINECRAFT_1_14, false),
|
||||
map(0x21, MINECRAFT_1_15, false));
|
||||
map(0x21, MINECRAFT_1_15, false),
|
||||
map(0x20, MINECRAFT_1_16, false));
|
||||
clientbound.register(JoinGame.class, JoinGame::new,
|
||||
map(0x01, MINECRAFT_1_7_2, false),
|
||||
map(0x23, MINECRAFT_1_9, false),
|
||||
map(0x25, MINECRAFT_1_13, false),
|
||||
map(0x25, MINECRAFT_1_14, false),
|
||||
map(0x26, MINECRAFT_1_15, false));
|
||||
map(0x26, MINECRAFT_1_15, false),
|
||||
map(0x25, MINECRAFT_1_16, false));
|
||||
clientbound.register(Respawn.class, Respawn::new,
|
||||
map(0x07, MINECRAFT_1_7_2, true),
|
||||
map(0x33, MINECRAFT_1_9, true),
|
||||
@ -167,7 +177,8 @@ public enum StateRegistry {
|
||||
map(0x35, MINECRAFT_1_12_1, true),
|
||||
map(0x38, MINECRAFT_1_13, true),
|
||||
map(0x3A, MINECRAFT_1_14, true),
|
||||
map(0x3B, MINECRAFT_1_15, true));
|
||||
map(0x3B, MINECRAFT_1_15, true),
|
||||
map(0x3A, MINECRAFT_1_16, true));
|
||||
clientbound.register(ResourcePackRequest.class, ResourcePackRequest::new,
|
||||
map(0x48, MINECRAFT_1_8, true),
|
||||
map(0x32, MINECRAFT_1_9, true),
|
||||
@ -175,7 +186,8 @@ public enum StateRegistry {
|
||||
map(0x34, MINECRAFT_1_12_1, true),
|
||||
map(0x37, MINECRAFT_1_13, true),
|
||||
map(0x39, MINECRAFT_1_14, true),
|
||||
map(0x3A, MINECRAFT_1_15, true));
|
||||
map(0x3A, MINECRAFT_1_15, true),
|
||||
map(0x39, MINECRAFT_1_16, true));
|
||||
clientbound.register(HeaderAndFooter.class, HeaderAndFooter::new,
|
||||
map(0x47, MINECRAFT_1_8, true),
|
||||
map(0x48, MINECRAFT_1_9, true),
|
||||
@ -184,7 +196,8 @@ public enum StateRegistry {
|
||||
map(0x4A, MINECRAFT_1_12_1, true),
|
||||
map(0x4E, MINECRAFT_1_13, true),
|
||||
map(0x53, MINECRAFT_1_14, true),
|
||||
map(0x54, MINECRAFT_1_15, true));
|
||||
map(0x54, MINECRAFT_1_15, true),
|
||||
map(0x53, MINECRAFT_1_16, true));
|
||||
clientbound.register(TitlePacket.class, TitlePacket::new,
|
||||
map(0x45, MINECRAFT_1_8, true),
|
||||
map(0x45, MINECRAFT_1_9, true),
|
||||
@ -192,14 +205,16 @@ public enum StateRegistry {
|
||||
map(0x48, MINECRAFT_1_12_1, true),
|
||||
map(0x4B, MINECRAFT_1_13, true),
|
||||
map(0x4F, MINECRAFT_1_14, true),
|
||||
map(0x50, MINECRAFT_1_15, true));
|
||||
map(0x50, MINECRAFT_1_15, true),
|
||||
map(0x4F, MINECRAFT_1_16, true));
|
||||
clientbound.register(PlayerListItem.class, PlayerListItem::new,
|
||||
map(0x38, MINECRAFT_1_7_2, false),
|
||||
map(0x2D, MINECRAFT_1_9, false),
|
||||
map(0x2E, MINECRAFT_1_12_1, false),
|
||||
map(0x30, MINECRAFT_1_13, false),
|
||||
map(0x33, MINECRAFT_1_14, false),
|
||||
map(0x34, MINECRAFT_1_15, false));
|
||||
map(0x34, MINECRAFT_1_15, false),
|
||||
map(0x33, MINECRAFT_1_16, false));
|
||||
}
|
||||
},
|
||||
LOGIN {
|
||||
@ -395,8 +410,8 @@ public enum StateRegistry {
|
||||
/**
|
||||
* Creates a PacketMapping using the provided arguments.
|
||||
*
|
||||
* @param id Packet Id
|
||||
* @param version Protocol version
|
||||
* @param id Packet Id
|
||||
* @param version Protocol version
|
||||
* @param encodeOnly When true packet decoding will be disabled
|
||||
* @return PacketMapping with the provided arguments
|
||||
*/
|
||||
|
@ -10,20 +10,25 @@ import net.kyori.text.Component;
|
||||
import net.kyori.text.serializer.gson.GsonComponentSerializer;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class Chat implements MinecraftPacket {
|
||||
|
||||
public static final byte CHAT_TYPE = (byte) 0;
|
||||
public static final int MAX_SERVERBOUND_MESSAGE_LENGTH = 256;
|
||||
public static final UUID EMPTY_SENDER = new UUID(0, 0);
|
||||
|
||||
private @Nullable String message;
|
||||
private byte type;
|
||||
private @Nullable UUID sender;
|
||||
|
||||
public Chat() {
|
||||
}
|
||||
|
||||
public Chat(String message, byte type) {
|
||||
public Chat(String message, byte type, UUID sender) {
|
||||
this.message = message;
|
||||
this.type = type;
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
@ -45,11 +50,20 @@ public class Chat implements MinecraftPacket {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public UUID getSenderUuid() {
|
||||
return sender;
|
||||
}
|
||||
|
||||
public void setSenderUuid(UUID sender) {
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Chat{"
|
||||
+ "message='" + message + '\''
|
||||
+ ", type=" + type
|
||||
+ ", sender=" + sender
|
||||
+ '}';
|
||||
}
|
||||
|
||||
@ -58,6 +72,9 @@ public class Chat implements MinecraftPacket {
|
||||
message = ProtocolUtils.readString(buf);
|
||||
if (direction == ProtocolUtils.Direction.CLIENTBOUND && version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
|
||||
type = buf.readByte();
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
|
||||
sender = ProtocolUtils.readUuid(buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,6 +86,9 @@ public class Chat implements MinecraftPacket {
|
||||
ProtocolUtils.writeString(buf, message);
|
||||
if (direction == ProtocolUtils.Direction.CLIENTBOUND && version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
|
||||
buf.writeByte(type);
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
|
||||
ProtocolUtils.writeUuid(buf, sender == null ? EMPTY_SENDER : sender);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -78,15 +98,15 @@ public class Chat implements MinecraftPacket {
|
||||
}
|
||||
|
||||
public static Chat createClientbound(Component component) {
|
||||
return createClientbound(component, CHAT_TYPE);
|
||||
return createClientbound(component, CHAT_TYPE, EMPTY_SENDER);
|
||||
}
|
||||
|
||||
public static Chat createClientbound(Component component, byte type) {
|
||||
public static Chat createClientbound(Component component, byte type, UUID sender) {
|
||||
Preconditions.checkNotNull(component, "component");
|
||||
return new Chat(GsonComponentSerializer.INSTANCE.serialize(component), type);
|
||||
return new Chat(GsonComponentSerializer.INSTANCE.serialize(component), type, sender);
|
||||
}
|
||||
|
||||
public static Chat createServerbound(String message) {
|
||||
return new Chat(message, CHAT_TYPE);
|
||||
return new Chat(message, CHAT_TYPE, EMPTY_SENDER);
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,12 @@
|
||||
package com.velocitypowered.proxy.protocol.packet;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import com.velocitypowered.proxy.connection.registry.DimensionData;
|
||||
import com.velocitypowered.proxy.connection.registry.DimensionInfo;
|
||||
import com.velocitypowered.proxy.connection.registry.DimensionRegistry;
|
||||
import com.velocitypowered.proxy.protocol.*;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
@ -16,9 +19,12 @@ public class JoinGame implements MinecraftPacket {
|
||||
private short difficulty;
|
||||
private short maxPlayers;
|
||||
private @Nullable String levelType;
|
||||
private int viewDistance; //1.14+
|
||||
private int viewDistance; // 1.14+
|
||||
private boolean reducedDebugInfo;
|
||||
private boolean showRespawnScreen;
|
||||
private DimensionRegistry dimensionRegistry; // 1.16+
|
||||
private DimensionInfo dimensionInfo; // 1.16+
|
||||
private short previousGamemode; // 1.16+
|
||||
|
||||
public int getEntityId() {
|
||||
return entityId;
|
||||
@ -64,10 +70,7 @@ public class JoinGame implements MinecraftPacket {
|
||||
this.maxPlayers = maxPlayers;
|
||||
}
|
||||
|
||||
public String getLevelType() {
|
||||
if (levelType == null) {
|
||||
throw new IllegalStateException("No level type specified.");
|
||||
}
|
||||
public @Nullable String getLevelType() {
|
||||
return levelType;
|
||||
}
|
||||
|
||||
@ -91,6 +94,30 @@ public class JoinGame implements MinecraftPacket {
|
||||
this.reducedDebugInfo = reducedDebugInfo;
|
||||
}
|
||||
|
||||
public DimensionInfo getDimensionInfo() {
|
||||
return dimensionInfo;
|
||||
}
|
||||
|
||||
public void setDimensionInfo(DimensionInfo dimensionInfo) {
|
||||
this.dimensionInfo = dimensionInfo;
|
||||
}
|
||||
|
||||
public DimensionRegistry getDimensionRegistry() {
|
||||
return dimensionRegistry;
|
||||
}
|
||||
|
||||
public void setDimensionRegistry(DimensionRegistry dimensionRegistry) {
|
||||
this.dimensionRegistry = dimensionRegistry;
|
||||
}
|
||||
|
||||
public short getPreviousGamemode() {
|
||||
return previousGamemode;
|
||||
}
|
||||
|
||||
public void setPreviousGamemode(short previousGamemode) {
|
||||
this.previousGamemode = previousGamemode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "JoinGame{"
|
||||
@ -103,14 +130,26 @@ public class JoinGame implements MinecraftPacket {
|
||||
+ ", levelType='" + levelType + '\''
|
||||
+ ", viewDistance=" + viewDistance
|
||||
+ ", reducedDebugInfo=" + reducedDebugInfo
|
||||
+ ", dimensionRegistry='" + dimensionRegistry.toString() + '\''
|
||||
+ ", dimensionInfo='" + dimensionInfo.toString() + '\''
|
||||
+ ", previousGamemode=" + previousGamemode
|
||||
+ '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
|
||||
this.entityId = buf.readInt();
|
||||
this.gamemode = buf.readUnsignedByte();
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_9_1) >= 0) {
|
||||
this.gamemode = buf.readByte();
|
||||
String dimensionIdentifier = null;
|
||||
String levelName = null;
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
|
||||
this.previousGamemode = buf.readByte();
|
||||
ImmutableSet<String> levelNames = ImmutableSet.copyOf(ProtocolUtils.readStringArray(buf));
|
||||
ImmutableSet<DimensionData> readData = DimensionRegistry.fromGameData(ProtocolUtils.readCompoundTag(buf));
|
||||
this.dimensionRegistry = new DimensionRegistry(readData, levelNames);
|
||||
dimensionIdentifier = ProtocolUtils.readString(buf);
|
||||
levelName = ProtocolUtils.readString(buf);
|
||||
} else if (version.compareTo(ProtocolVersion.MINECRAFT_1_9_1) >= 0) {
|
||||
this.dimension = buf.readInt();
|
||||
} else {
|
||||
this.dimension = buf.readByte();
|
||||
@ -122,23 +161,35 @@ public class JoinGame implements MinecraftPacket {
|
||||
this.partialHashedSeed = buf.readLong();
|
||||
}
|
||||
this.maxPlayers = buf.readUnsignedByte();
|
||||
this.levelType = ProtocolUtils.readString(buf, 16);
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) < 0) {
|
||||
this.levelType = ProtocolUtils.readString(buf, 16);
|
||||
}
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_14) >= 0) {
|
||||
this.viewDistance = ProtocolUtils.readVarInt(buf);
|
||||
}
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
|
||||
this.reducedDebugInfo = buf.readBoolean();
|
||||
}
|
||||
this.reducedDebugInfo = buf.readBoolean();
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_15) >= 0) {
|
||||
this.showRespawnScreen = buf.readBoolean();
|
||||
}
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
|
||||
boolean isDebug = buf.readBoolean();
|
||||
boolean isFlat = buf.readBoolean();
|
||||
this.dimensionInfo = new DimensionInfo(dimensionIdentifier, levelName, isFlat, isDebug);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
|
||||
buf.writeInt(entityId);
|
||||
buf.writeByte(gamemode);
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_9_1) >= 0) {
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
|
||||
buf.writeByte(previousGamemode);
|
||||
ProtocolUtils.writeStringArray(buf, dimensionRegistry.getLevelNames().toArray(
|
||||
new String[dimensionRegistry.getLevelNames().size()]));
|
||||
ProtocolUtils.writeCompoundTag(buf, dimensionRegistry.encodeRegistry());
|
||||
ProtocolUtils.writeString(buf, dimensionInfo.getRegistryIdentifier());
|
||||
ProtocolUtils.writeString(buf, dimensionInfo.getLevelName());
|
||||
} else if (version.compareTo(ProtocolVersion.MINECRAFT_1_9_1) >= 0) {
|
||||
buf.writeInt(dimension);
|
||||
} else {
|
||||
buf.writeByte(dimension);
|
||||
@ -150,19 +201,23 @@ public class JoinGame implements MinecraftPacket {
|
||||
buf.writeLong(partialHashedSeed);
|
||||
}
|
||||
buf.writeByte(maxPlayers);
|
||||
if (levelType == null) {
|
||||
throw new IllegalStateException("No level type specified.");
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) < 0) {
|
||||
if (levelType == null) {
|
||||
throw new IllegalStateException("No level type specified.");
|
||||
}
|
||||
ProtocolUtils.writeString(buf, levelType);
|
||||
}
|
||||
ProtocolUtils.writeString(buf, levelType);
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_14) >= 0) {
|
||||
ProtocolUtils.writeVarInt(buf, viewDistance);
|
||||
}
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
|
||||
buf.writeBoolean(reducedDebugInfo);
|
||||
ProtocolUtils.writeVarInt(buf,viewDistance);
|
||||
}
|
||||
buf.writeBoolean(reducedDebugInfo);
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_15) >= 0) {
|
||||
buf.writeBoolean(showRespawnScreen);
|
||||
}
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
|
||||
buf.writeBoolean(dimensionInfo.isDebugType());
|
||||
buf.writeBoolean(dimensionInfo.isFlat());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -2,6 +2,7 @@ package com.velocitypowered.proxy.protocol.packet;
|
||||
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||
import com.velocitypowered.proxy.connection.registry.DimensionInfo;
|
||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
@ -13,17 +14,24 @@ public class Respawn implements MinecraftPacket {
|
||||
private short difficulty;
|
||||
private short gamemode;
|
||||
private String levelType = "";
|
||||
private boolean shouldKeepPlayerData; // 1.16+
|
||||
private DimensionInfo dimensionInfo; // 1.16+
|
||||
private short previousGamemode; // 1.16+
|
||||
|
||||
public Respawn() {
|
||||
}
|
||||
|
||||
public Respawn(int dimension, long partialHashedSeed, short difficulty, short gamemode,
|
||||
String levelType) {
|
||||
String levelType, boolean shouldKeepPlayerData, DimensionInfo dimensionInfo,
|
||||
short previousGamemode) {
|
||||
this.dimension = dimension;
|
||||
this.partialHashedSeed = partialHashedSeed;
|
||||
this.difficulty = difficulty;
|
||||
this.gamemode = gamemode;
|
||||
this.levelType = levelType;
|
||||
this.shouldKeepPlayerData = shouldKeepPlayerData;
|
||||
this.dimensionInfo = dimensionInfo;
|
||||
this.previousGamemode = previousGamemode;
|
||||
}
|
||||
|
||||
public int getDimension() {
|
||||
@ -66,6 +74,22 @@ public class Respawn implements MinecraftPacket {
|
||||
this.levelType = levelType;
|
||||
}
|
||||
|
||||
public boolean getShouldKeepPlayerData() {
|
||||
return shouldKeepPlayerData;
|
||||
}
|
||||
|
||||
public void setShouldKeepPlayerData(boolean shouldKeepPlayerData) {
|
||||
this.shouldKeepPlayerData = shouldKeepPlayerData;
|
||||
}
|
||||
|
||||
public short getPreviousGamemode() {
|
||||
return previousGamemode;
|
||||
}
|
||||
|
||||
public void setPreviousGamemode(short previousGamemode) {
|
||||
this.previousGamemode = previousGamemode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Respawn{"
|
||||
@ -74,25 +98,48 @@ public class Respawn implements MinecraftPacket {
|
||||
+ ", difficulty=" + difficulty
|
||||
+ ", gamemode=" + gamemode
|
||||
+ ", levelType='" + levelType + '\''
|
||||
+ ", shouldKeepPlayerData=" + shouldKeepPlayerData
|
||||
+ ", dimensionRegistryName='" + dimensionInfo.toString() + '\''
|
||||
+ ", previousGamemode=" + previousGamemode
|
||||
+ '}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
|
||||
this.dimension = buf.readInt();
|
||||
String dimensionIdentifier = null;
|
||||
String levelName = null;
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
|
||||
dimensionIdentifier = ProtocolUtils.readString(buf);
|
||||
levelName = ProtocolUtils.readString(buf);
|
||||
} else {
|
||||
this.dimension = buf.readInt();
|
||||
}
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_13_2) <= 0) {
|
||||
this.difficulty = buf.readUnsignedByte();
|
||||
}
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_15) >= 0) {
|
||||
this.partialHashedSeed = buf.readLong();
|
||||
}
|
||||
this.gamemode = buf.readUnsignedByte();
|
||||
this.levelType = ProtocolUtils.readString(buf, 16);
|
||||
this.gamemode = buf.readByte();
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
|
||||
this.previousGamemode = buf.readByte();
|
||||
boolean isDebug = buf.readBoolean();
|
||||
boolean isFlat = buf.readBoolean();
|
||||
this.dimensionInfo = new DimensionInfo(dimensionIdentifier, levelName, isFlat, isDebug);
|
||||
this.shouldKeepPlayerData = buf.readBoolean();
|
||||
} else {
|
||||
this.levelType = ProtocolUtils.readString(buf, 16);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
|
||||
buf.writeInt(dimension);
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
|
||||
ProtocolUtils.writeString(buf, dimensionInfo.getRegistryIdentifier());
|
||||
ProtocolUtils.writeString(buf, dimensionInfo.getLevelName());
|
||||
} else {
|
||||
buf.writeInt(dimension);
|
||||
}
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_13_2) <= 0) {
|
||||
buf.writeByte(difficulty);
|
||||
}
|
||||
@ -100,7 +147,14 @@ public class Respawn implements MinecraftPacket {
|
||||
buf.writeLong(partialHashedSeed);
|
||||
}
|
||||
buf.writeByte(gamemode);
|
||||
ProtocolUtils.writeString(buf, levelType);
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
|
||||
buf.writeByte(previousGamemode);
|
||||
buf.writeBoolean(dimensionInfo.isDebugType());
|
||||
buf.writeBoolean(dimensionInfo.isFlat());
|
||||
buf.writeBoolean(shouldKeepPlayerData);
|
||||
} else {
|
||||
ProtocolUtils.writeString(buf, levelType);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.velocitypowered.proxy.protocol.packet;
|
||||
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.api.util.UuidUtils;
|
||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||
@ -46,10 +45,10 @@ public class ServerLoginSuccess implements MinecraftPacket {
|
||||
|
||||
@Override
|
||||
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_7_6) >= 0) {
|
||||
uuid = UUID.fromString(ProtocolUtils.readString(buf, 36));
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
|
||||
uuid = ProtocolUtils.readUuidIntArray(buf);
|
||||
} else {
|
||||
uuid = UuidUtils.fromUndashed(ProtocolUtils.readString(buf, 32));
|
||||
uuid = UUID.fromString(ProtocolUtils.readString(buf, 36));
|
||||
}
|
||||
username = ProtocolUtils.readString(buf, 16);
|
||||
}
|
||||
@ -59,7 +58,11 @@ public class ServerLoginSuccess implements MinecraftPacket {
|
||||
if (uuid == null) {
|
||||
throw new IllegalStateException("No UUID specified!");
|
||||
}
|
||||
ProtocolUtils.writeString(buf, uuid.toString());
|
||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
|
||||
ProtocolUtils.writeUuidIntArray(buf, uuid);
|
||||
} else {
|
||||
ProtocolUtils.writeString(buf, uuid.toString());
|
||||
}
|
||||
if (username == null) {
|
||||
throw new IllegalStateException("No username specified!");
|
||||
}
|
||||
|
@ -134,5 +134,6 @@ public class ArgumentPropertyRegistry {
|
||||
dummy("minecraft:int_range", DUMMY);
|
||||
dummy("minecraft:float_range", DUMMY);
|
||||
dummy("minecraft:time", DUMMY); // added in 1.14
|
||||
dummy("minecraft:uuid", DUMMY); // added in 1.16
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren