geforkt von Mirrors/Velocity
Merge branch 'future/1.16' of https://github.com/Xernium/Velocity into Xernium-future/1.16
Dieser Commit ist enthalten in:
Commit
cd9bb61f20
@ -34,7 +34,8 @@ public enum ProtocolVersion {
|
|||||||
MINECRAFT_1_14_4(498, "1.14.4"),
|
MINECRAFT_1_14_4(498, "1.14.4"),
|
||||||
MINECRAFT_1_15(573, "1.15"),
|
MINECRAFT_1_15(573, "1.15"),
|
||||||
MINECRAFT_1_15_1(575, "1.15.1"),
|
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 int protocol;
|
||||||
private final String name;
|
private final String name;
|
||||||
|
@ -63,6 +63,7 @@ dependencies {
|
|||||||
|
|
||||||
compile 'it.unimi.dsi:fastutil:8.2.2'
|
compile 'it.unimi.dsi:fastutil:8.2.2'
|
||||||
compile 'net.kyori:event-method-asm:3.0.0'
|
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 'com.mojang:brigadier:1.0.17'
|
||||||
|
|
||||||
|
@ -12,7 +12,6 @@ import static com.velocitypowered.proxy.network.Connections.READ_TIMEOUT;
|
|||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
import com.velocitypowered.api.network.ProtocolVersion;
|
import com.velocitypowered.api.network.ProtocolVersion;
|
||||||
import com.velocitypowered.api.proxy.ConnectionRequestBuilder;
|
|
||||||
import com.velocitypowered.api.proxy.ServerConnection;
|
import com.velocitypowered.api.proxy.ServerConnection;
|
||||||
import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
|
import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
|
||||||
import com.velocitypowered.api.proxy.server.ServerInfo;
|
import com.velocitypowered.api.proxy.server.ServerInfo;
|
||||||
@ -22,6 +21,7 @@ import com.velocitypowered.proxy.connection.ConnectionTypes;
|
|||||||
import com.velocitypowered.proxy.connection.MinecraftConnection;
|
import com.velocitypowered.proxy.connection.MinecraftConnection;
|
||||||
import com.velocitypowered.proxy.connection.MinecraftConnectionAssociation;
|
import com.velocitypowered.proxy.connection.MinecraftConnectionAssociation;
|
||||||
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
|
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.connection.util.ConnectionRequestResults.Impl;
|
||||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||||
import com.velocitypowered.proxy.protocol.StateRegistry;
|
import com.velocitypowered.proxy.protocol.StateRegistry;
|
||||||
@ -40,6 +40,8 @@ import io.netty.handler.flow.FlowControlHandler;
|
|||||||
import io.netty.handler.timeout.ReadTimeoutHandler;
|
import io.netty.handler.timeout.ReadTimeoutHandler;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
public class VelocityServerConnection implements MinecraftConnectionAssociation, ServerConnection {
|
public class VelocityServerConnection implements MinecraftConnectionAssociation, ServerConnection {
|
||||||
@ -53,6 +55,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
|
|||||||
private BackendConnectionPhase connectionPhase = BackendConnectionPhases.UNKNOWN;
|
private BackendConnectionPhase connectionPhase = BackendConnectionPhases.UNKNOWN;
|
||||||
private long lastPingId;
|
private long lastPingId;
|
||||||
private long lastPingSent;
|
private long lastPingSent;
|
||||||
|
private @MonotonicNonNull DimensionRegistry activeDimensionRegistry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes a new server connection.
|
* Initializes a new server connection.
|
||||||
@ -297,4 +300,11 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
|
|||||||
return hasCompletedJoin;
|
return hasCompletedJoin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DimensionRegistry getActiveDimensionRegistry() {
|
||||||
|
return activeDimensionRegistry;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setActiveDimensionRegistry(DimensionRegistry activeDimensionRegistry) {
|
||||||
|
this.activeDimensionRegistry = activeDimensionRegistry;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,11 +32,9 @@ import io.netty.buffer.ByteBuf;
|
|||||||
import java.util.ArrayDeque;
|
import java.util.ArrayDeque;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import net.kyori.text.TextComponent;
|
import net.kyori.text.TextComponent;
|
||||||
import net.kyori.text.format.TextColor;
|
import net.kyori.text.format.TextColor;
|
||||||
@ -313,8 +311,8 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
if (!spawned) {
|
if (!spawned) {
|
||||||
// Nothing special to do with regards to spawning the player
|
// Nothing special to do with regards to spawning the player
|
||||||
spawned = true;
|
spawned = true;
|
||||||
|
destination.setActiveDimensionRegistry(joinGame.getDimensionRegistry()); // 1.16
|
||||||
player.getMinecraftConnection().delayedWrite(joinGame);
|
player.getMinecraftConnection().delayedWrite(joinGame);
|
||||||
|
|
||||||
// Required for Legacy Forge
|
// Required for Legacy Forge
|
||||||
player.getPhase().onFirstJoin(player);
|
player.getPhase().onFirstJoin(player);
|
||||||
} else {
|
} else {
|
||||||
@ -334,13 +332,22 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
// to perform entity ID rewrites, eliminating potential issues from rewriting packets and
|
// to perform entity ID rewrites, eliminating potential issues from rewriting packets and
|
||||||
// improving compatibility with mods.
|
// improving compatibility with mods.
|
||||||
player.getMinecraftConnection().delayedWrite(joinGame);
|
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;
|
int tempDim = joinGame.getDimension() == 0 ? -1 : 0;
|
||||||
player.getMinecraftConnection().delayedWrite(
|
player.getMinecraftConnection().delayedWrite(
|
||||||
new Respawn(tempDim, joinGame.getPartialHashedSeed(), joinGame.getDifficulty(),
|
new Respawn(tempDim, joinGame.getPartialHashedSeed(), joinGame.getDifficulty(),
|
||||||
joinGame.getGamemode(), joinGame.getLevelType()));
|
joinGame.getGamemode(), joinGame.getLevelType(),
|
||||||
|
false, joinGame.getDimensionInfo(), joinGame.getPreviousGamemode()));
|
||||||
|
}
|
||||||
|
|
||||||
player.getMinecraftConnection().delayedWrite(
|
player.getMinecraftConnection().delayedWrite(
|
||||||
new Respawn(joinGame.getDimension(), joinGame.getPartialHashedSeed(),
|
new Respawn(joinGame.getDimension(), joinGame.getPartialHashedSeed(),
|
||||||
joinGame.getDifficulty(), joinGame.getGamemode(), joinGame.getLevelType()));
|
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
|
// Remove previous boss bars. These don't get cleared when sending JoinGame, thus the need to
|
||||||
|
@ -18,7 +18,10 @@ import com.velocitypowered.api.event.permission.PermissionsSetupEvent;
|
|||||||
import com.velocitypowered.api.event.player.GameProfileRequestEvent;
|
import com.velocitypowered.api.event.player.GameProfileRequestEvent;
|
||||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||||
import com.velocitypowered.api.util.GameProfile;
|
import com.velocitypowered.api.util.GameProfile;
|
||||||
|
import com.velocitypowered.api.util.UuidUtils;
|
||||||
import com.velocitypowered.proxy.VelocityServer;
|
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.MinecraftConnection;
|
||||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||||
|
|
||||||
@ -41,6 +44,7 @@ import java.security.GeneralSecurityException;
|
|||||||
import java.security.KeyPair;
|
import java.security.KeyPair;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
import net.kyori.text.Component;
|
import net.kyori.text.Component;
|
||||||
@ -253,10 +257,14 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
|
|||||||
mcConnection.write(new SetCompression(threshold));
|
mcConnection.write(new SetCompression(threshold));
|
||||||
mcConnection.setCompressionThreshold(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();
|
ServerLoginSuccess success = new ServerLoginSuccess();
|
||||||
success.setUsername(player.getUsername());
|
success.setUsername(player.getUsername());
|
||||||
success.setUuid(player.getUniqueId());
|
success.setUuid(playerUniqueId);
|
||||||
mcConnection.write(success);
|
mcConnection.write(success);
|
||||||
|
|
||||||
mcConnection.setAssociation(player);
|
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();
|
||||||
|
}
|
||||||
|
}
|
@ -6,13 +6,24 @@ import static com.google.common.base.Preconditions.checkState;
|
|||||||
import com.velocitypowered.api.network.ProtocolVersion;
|
import com.velocitypowered.api.network.ProtocolVersion;
|
||||||
import com.velocitypowered.api.util.GameProfile;
|
import com.velocitypowered.api.util.GameProfile;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import io.netty.buffer.ByteBufInputStream;
|
||||||
|
import io.netty.buffer.ByteBufOutputStream;
|
||||||
import io.netty.buffer.ByteBufUtil;
|
import io.netty.buffer.ByteBufUtil;
|
||||||
|
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.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import net.kyori.nbt.CompoundTag;
|
||||||
|
import net.kyori.nbt.TagIO;
|
||||||
|
import net.kyori.nbt.TagType;
|
||||||
|
|
||||||
public enum ProtocolUtils {
|
public enum ProtocolUtils {
|
||||||
;
|
;
|
||||||
private static final int DEFAULT_MAX_STRING_SIZE = 65536; // 64KiB
|
private static final int DEFAULT_MAX_STRING_SIZE = 65536; // 64KiB
|
||||||
@ -153,6 +164,100 @@ public enum ProtocolUtils {
|
|||||||
buf.writeLong(uuid.getLeastSignificantBits());
|
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.
|
* Writes a list of {@link com.velocitypowered.api.util.GameProfile.Property} to the buffer.
|
||||||
* @param buf the buffer to write to
|
* @param buf the buffer to write to
|
||||||
|
@ -6,6 +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_13;
|
||||||
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_14;
|
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_15;
|
||||||
|
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_8;
|
||||||
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_9;
|
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_9;
|
||||||
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_9_4;
|
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_9_4;
|
||||||
@ -113,54 +114,64 @@ public enum StateRegistry {
|
|||||||
map(0x0C, MINECRAFT_1_12, false),
|
map(0x0C, MINECRAFT_1_12, false),
|
||||||
map(0x0B, MINECRAFT_1_12_1, false),
|
map(0x0B, MINECRAFT_1_12_1, false),
|
||||||
map(0x0E, MINECRAFT_1_13, 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,
|
serverbound.register(ResourcePackResponse.class, ResourcePackResponse::new,
|
||||||
map(0x19, MINECRAFT_1_8, false),
|
map(0x19, MINECRAFT_1_8, false),
|
||||||
map(0x16, MINECRAFT_1_9, false),
|
map(0x16, MINECRAFT_1_9, false),
|
||||||
map(0x18, MINECRAFT_1_12, false),
|
map(0x18, MINECRAFT_1_12, false),
|
||||||
map(0x1D, MINECRAFT_1_13, 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,
|
clientbound.register(BossBar.class, BossBar::new,
|
||||||
map(0x0C, MINECRAFT_1_9, false),
|
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,
|
clientbound.register(Chat.class, Chat::new,
|
||||||
map(0x02, MINECRAFT_1_8, true),
|
map(0x02, MINECRAFT_1_8, true),
|
||||||
map(0x0F, MINECRAFT_1_9, true),
|
map(0x0F, MINECRAFT_1_9, true),
|
||||||
map(0x0E, MINECRAFT_1_13, 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,
|
clientbound.register(TabCompleteResponse.class, TabCompleteResponse::new,
|
||||||
map(0x3A, MINECRAFT_1_8, false),
|
map(0x3A, MINECRAFT_1_8, false),
|
||||||
map(0x0E, MINECRAFT_1_9, false),
|
map(0x0E, MINECRAFT_1_9, false),
|
||||||
map(0x10, MINECRAFT_1_13, 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,
|
clientbound.register(AvailableCommands.class, AvailableCommands::new,
|
||||||
map(0x11, MINECRAFT_1_13, false),
|
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,
|
clientbound.register(PluginMessage.class, PluginMessage::new,
|
||||||
map(0x3F, MINECRAFT_1_8, false),
|
map(0x3F, MINECRAFT_1_8, false),
|
||||||
map(0x18, MINECRAFT_1_9, false),
|
map(0x18, MINECRAFT_1_9, false),
|
||||||
map(0x19, MINECRAFT_1_13, false),
|
map(0x19, MINECRAFT_1_13, false),
|
||||||
map(0x18, MINECRAFT_1_14, 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,
|
clientbound.register(Disconnect.class, Disconnect::new,
|
||||||
map(0x40, MINECRAFT_1_8, false),
|
map(0x40, MINECRAFT_1_8, false),
|
||||||
map(0x1A, MINECRAFT_1_9, false),
|
map(0x1A, MINECRAFT_1_9, false),
|
||||||
map(0x1B, MINECRAFT_1_13, false),
|
map(0x1B, MINECRAFT_1_13, false),
|
||||||
map(0x1A, MINECRAFT_1_14, 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,
|
clientbound.register(KeepAlive.class, KeepAlive::new,
|
||||||
map(0x00, MINECRAFT_1_8, false),
|
map(0x00, MINECRAFT_1_8, false),
|
||||||
map(0x1F, MINECRAFT_1_9, false),
|
map(0x1F, MINECRAFT_1_9, false),
|
||||||
map(0x21, MINECRAFT_1_13, false),
|
map(0x21, MINECRAFT_1_13, false),
|
||||||
map(0x20, MINECRAFT_1_14, 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,
|
clientbound.register(JoinGame.class, JoinGame::new,
|
||||||
map(0x01, MINECRAFT_1_8, false),
|
map(0x01, MINECRAFT_1_8, false),
|
||||||
map(0x23, MINECRAFT_1_9, false),
|
map(0x23, MINECRAFT_1_9, false),
|
||||||
map(0x25, MINECRAFT_1_13, false),
|
map(0x25, MINECRAFT_1_13, false),
|
||||||
map(0x25, MINECRAFT_1_14, 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,
|
clientbound.register(Respawn.class, Respawn::new,
|
||||||
map(0x07, MINECRAFT_1_8, true),
|
map(0x07, MINECRAFT_1_8, true),
|
||||||
map(0x33, MINECRAFT_1_9, true),
|
map(0x33, MINECRAFT_1_9, true),
|
||||||
@ -168,7 +179,8 @@ public enum StateRegistry {
|
|||||||
map(0x35, MINECRAFT_1_12_1, true),
|
map(0x35, MINECRAFT_1_12_1, true),
|
||||||
map(0x38, MINECRAFT_1_13, true),
|
map(0x38, MINECRAFT_1_13, true),
|
||||||
map(0x3A, MINECRAFT_1_14, 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,
|
clientbound.register(ResourcePackRequest.class, ResourcePackRequest::new,
|
||||||
map(0x48, MINECRAFT_1_8, true),
|
map(0x48, MINECRAFT_1_8, true),
|
||||||
map(0x32, MINECRAFT_1_9, true),
|
map(0x32, MINECRAFT_1_9, true),
|
||||||
@ -176,7 +188,8 @@ public enum StateRegistry {
|
|||||||
map(0x34, MINECRAFT_1_12_1, true),
|
map(0x34, MINECRAFT_1_12_1, true),
|
||||||
map(0x37, MINECRAFT_1_13, true),
|
map(0x37, MINECRAFT_1_13, true),
|
||||||
map(0x39, MINECRAFT_1_14, 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,
|
clientbound.register(HeaderAndFooter.class, HeaderAndFooter::new,
|
||||||
map(0x47, MINECRAFT_1_8, true),
|
map(0x47, MINECRAFT_1_8, true),
|
||||||
map(0x48, MINECRAFT_1_9, true),
|
map(0x48, MINECRAFT_1_9, true),
|
||||||
@ -185,7 +198,8 @@ public enum StateRegistry {
|
|||||||
map(0x4A, MINECRAFT_1_12_1, true),
|
map(0x4A, MINECRAFT_1_12_1, true),
|
||||||
map(0x4E, MINECRAFT_1_13, true),
|
map(0x4E, MINECRAFT_1_13, true),
|
||||||
map(0x53, MINECRAFT_1_14, 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,
|
clientbound.register(TitlePacket.class, TitlePacket::new,
|
||||||
map(0x45, MINECRAFT_1_8, true),
|
map(0x45, MINECRAFT_1_8, true),
|
||||||
map(0x45, MINECRAFT_1_9, true),
|
map(0x45, MINECRAFT_1_9, true),
|
||||||
@ -193,14 +207,16 @@ public enum StateRegistry {
|
|||||||
map(0x48, MINECRAFT_1_12_1, true),
|
map(0x48, MINECRAFT_1_12_1, true),
|
||||||
map(0x4B, MINECRAFT_1_13, true),
|
map(0x4B, MINECRAFT_1_13, true),
|
||||||
map(0x4F, MINECRAFT_1_14, 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,
|
clientbound.register(PlayerListItem.class, PlayerListItem::new,
|
||||||
map(0x38, MINECRAFT_1_8, false),
|
map(0x38, MINECRAFT_1_8, false),
|
||||||
map(0x2D, MINECRAFT_1_9, false),
|
map(0x2D, MINECRAFT_1_9, false),
|
||||||
map(0x2E, MINECRAFT_1_12_1, false),
|
map(0x2E, MINECRAFT_1_12_1, false),
|
||||||
map(0x30, MINECRAFT_1_13, false),
|
map(0x30, MINECRAFT_1_13, false),
|
||||||
map(0x33, MINECRAFT_1_14, 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 {
|
LOGIN {
|
||||||
|
@ -10,20 +10,25 @@ import net.kyori.text.Component;
|
|||||||
import net.kyori.text.serializer.gson.GsonComponentSerializer;
|
import net.kyori.text.serializer.gson.GsonComponentSerializer;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class Chat implements MinecraftPacket {
|
public class Chat implements MinecraftPacket {
|
||||||
|
|
||||||
public static final byte CHAT_TYPE = (byte) 0;
|
public static final byte CHAT_TYPE = (byte) 0;
|
||||||
public static final int MAX_SERVERBOUND_MESSAGE_LENGTH = 256;
|
public static final int MAX_SERVERBOUND_MESSAGE_LENGTH = 256;
|
||||||
|
public static final UUID EMPTY_SENDER = new UUID(0, 0);
|
||||||
|
|
||||||
private @Nullable String message;
|
private @Nullable String message;
|
||||||
private byte type;
|
private byte type;
|
||||||
|
private @Nullable UUID sender;
|
||||||
|
|
||||||
public Chat() {
|
public Chat() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Chat(String message, byte type) {
|
public Chat(String message, byte type, UUID sender) {
|
||||||
this.message = message;
|
this.message = message;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
this.sender = sender;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMessage() {
|
public String getMessage() {
|
||||||
@ -45,11 +50,20 @@ public class Chat implements MinecraftPacket {
|
|||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UUID getSenderUuid() {
|
||||||
|
return sender;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSenderUuid(UUID sender) {
|
||||||
|
this.sender = sender;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Chat{"
|
return "Chat{"
|
||||||
+ "message='" + message + '\''
|
+ "message='" + message + '\''
|
||||||
+ ", type=" + type
|
+ ", type=" + type
|
||||||
|
+ ", sender=" + sender
|
||||||
+ '}';
|
+ '}';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,6 +72,9 @@ public class Chat implements MinecraftPacket {
|
|||||||
message = ProtocolUtils.readString(buf);
|
message = ProtocolUtils.readString(buf);
|
||||||
if (direction == ProtocolUtils.Direction.CLIENTBOUND) {
|
if (direction == ProtocolUtils.Direction.CLIENTBOUND) {
|
||||||
type = buf.readByte();
|
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);
|
ProtocolUtils.writeString(buf, message);
|
||||||
if (direction == ProtocolUtils.Direction.CLIENTBOUND) {
|
if (direction == ProtocolUtils.Direction.CLIENTBOUND) {
|
||||||
buf.writeByte(type);
|
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) {
|
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");
|
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) {
|
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;
|
package com.velocitypowered.proxy.protocol.packet;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.velocitypowered.api.network.ProtocolVersion;
|
import com.velocitypowered.api.network.ProtocolVersion;
|
||||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
import com.velocitypowered.proxy.connection.registry.DimensionData;
|
||||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
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 io.netty.buffer.ByteBuf;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
@ -16,9 +19,12 @@ public class JoinGame implements MinecraftPacket {
|
|||||||
private short difficulty;
|
private short difficulty;
|
||||||
private short maxPlayers;
|
private short maxPlayers;
|
||||||
private @Nullable String levelType;
|
private @Nullable String levelType;
|
||||||
private int viewDistance; //1.14+
|
private int viewDistance; // 1.14+
|
||||||
private boolean reducedDebugInfo;
|
private boolean reducedDebugInfo;
|
||||||
private boolean showRespawnScreen;
|
private boolean showRespawnScreen;
|
||||||
|
private DimensionRegistry dimensionRegistry; // 1.16+
|
||||||
|
private DimensionInfo dimensionInfo; // 1.16+
|
||||||
|
private short previousGamemode; // 1.16+
|
||||||
|
|
||||||
public int getEntityId() {
|
public int getEntityId() {
|
||||||
return entityId;
|
return entityId;
|
||||||
@ -64,10 +70,7 @@ public class JoinGame implements MinecraftPacket {
|
|||||||
this.maxPlayers = maxPlayers;
|
this.maxPlayers = maxPlayers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLevelType() {
|
public @Nullable String getLevelType() {
|
||||||
if (levelType == null) {
|
|
||||||
throw new IllegalStateException("No level type specified.");
|
|
||||||
}
|
|
||||||
return levelType;
|
return levelType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,6 +94,30 @@ public class JoinGame implements MinecraftPacket {
|
|||||||
this.reducedDebugInfo = reducedDebugInfo;
|
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
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "JoinGame{"
|
return "JoinGame{"
|
||||||
@ -103,14 +130,26 @@ public class JoinGame implements MinecraftPacket {
|
|||||||
+ ", levelType='" + levelType + '\''
|
+ ", levelType='" + levelType + '\''
|
||||||
+ ", viewDistance=" + viewDistance
|
+ ", viewDistance=" + viewDistance
|
||||||
+ ", reducedDebugInfo=" + reducedDebugInfo
|
+ ", reducedDebugInfo=" + reducedDebugInfo
|
||||||
|
+ ", dimensionRegistry='" + dimensionRegistry.toString() + '\''
|
||||||
|
+ ", dimensionInfo='" + dimensionInfo.toString() + '\''
|
||||||
|
+ ", previousGamemode=" + previousGamemode
|
||||||
+ '}';
|
+ '}';
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
|
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
|
||||||
this.entityId = buf.readInt();
|
this.entityId = buf.readInt();
|
||||||
this.gamemode = buf.readUnsignedByte();
|
this.gamemode = buf.readByte();
|
||||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_9_1) >= 0) {
|
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();
|
this.dimension = buf.readInt();
|
||||||
} else {
|
} else {
|
||||||
this.dimension = buf.readByte();
|
this.dimension = buf.readByte();
|
||||||
@ -122,7 +161,9 @@ public class JoinGame implements MinecraftPacket {
|
|||||||
this.partialHashedSeed = buf.readLong();
|
this.partialHashedSeed = buf.readLong();
|
||||||
}
|
}
|
||||||
this.maxPlayers = buf.readUnsignedByte();
|
this.maxPlayers = buf.readUnsignedByte();
|
||||||
|
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) < 0) {
|
||||||
this.levelType = ProtocolUtils.readString(buf, 16);
|
this.levelType = ProtocolUtils.readString(buf, 16);
|
||||||
|
}
|
||||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_14) >= 0) {
|
if (version.compareTo(ProtocolVersion.MINECRAFT_1_14) >= 0) {
|
||||||
this.viewDistance = ProtocolUtils.readVarInt(buf);
|
this.viewDistance = ProtocolUtils.readVarInt(buf);
|
||||||
}
|
}
|
||||||
@ -130,13 +171,25 @@ public class JoinGame implements MinecraftPacket {
|
|||||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_15) >= 0) {
|
if (version.compareTo(ProtocolVersion.MINECRAFT_1_15) >= 0) {
|
||||||
this.showRespawnScreen = buf.readBoolean();
|
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
|
@Override
|
||||||
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
|
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
|
||||||
buf.writeInt(entityId);
|
buf.writeInt(entityId);
|
||||||
buf.writeByte(gamemode);
|
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);
|
buf.writeInt(dimension);
|
||||||
} else {
|
} else {
|
||||||
buf.writeByte(dimension);
|
buf.writeByte(dimension);
|
||||||
@ -148,10 +201,12 @@ public class JoinGame implements MinecraftPacket {
|
|||||||
buf.writeLong(partialHashedSeed);
|
buf.writeLong(partialHashedSeed);
|
||||||
}
|
}
|
||||||
buf.writeByte(maxPlayers);
|
buf.writeByte(maxPlayers);
|
||||||
|
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) < 0) {
|
||||||
if (levelType == null) {
|
if (levelType == null) {
|
||||||
throw new IllegalStateException("No level type specified.");
|
throw new IllegalStateException("No level type specified.");
|
||||||
}
|
}
|
||||||
ProtocolUtils.writeString(buf, levelType);
|
ProtocolUtils.writeString(buf, levelType);
|
||||||
|
}
|
||||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_14) >= 0) {
|
if (version.compareTo(ProtocolVersion.MINECRAFT_1_14) >= 0) {
|
||||||
ProtocolUtils.writeVarInt(buf,viewDistance);
|
ProtocolUtils.writeVarInt(buf,viewDistance);
|
||||||
}
|
}
|
||||||
@ -159,6 +214,10 @@ public class JoinGame implements MinecraftPacket {
|
|||||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_15) >= 0) {
|
if (version.compareTo(ProtocolVersion.MINECRAFT_1_15) >= 0) {
|
||||||
buf.writeBoolean(showRespawnScreen);
|
buf.writeBoolean(showRespawnScreen);
|
||||||
}
|
}
|
||||||
|
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
|
||||||
|
buf.writeBoolean(dimensionInfo.isDebugType());
|
||||||
|
buf.writeBoolean(dimensionInfo.isFlat());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -2,6 +2,7 @@ package com.velocitypowered.proxy.protocol.packet;
|
|||||||
|
|
||||||
import com.velocitypowered.api.network.ProtocolVersion;
|
import com.velocitypowered.api.network.ProtocolVersion;
|
||||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||||
|
import com.velocitypowered.proxy.connection.registry.DimensionInfo;
|
||||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
@ -13,17 +14,24 @@ public class Respawn implements MinecraftPacket {
|
|||||||
private short difficulty;
|
private short difficulty;
|
||||||
private short gamemode;
|
private short gamemode;
|
||||||
private String levelType = "";
|
private String levelType = "";
|
||||||
|
private boolean shouldKeepPlayerData; // 1.16+
|
||||||
|
private DimensionInfo dimensionInfo; // 1.16+
|
||||||
|
private short previousGamemode; // 1.16+
|
||||||
|
|
||||||
public Respawn() {
|
public Respawn() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Respawn(int dimension, long partialHashedSeed, short difficulty, short gamemode,
|
public Respawn(int dimension, long partialHashedSeed, short difficulty, short gamemode,
|
||||||
String levelType) {
|
String levelType, boolean shouldKeepPlayerData, DimensionInfo dimensionInfo,
|
||||||
|
short previousGamemode) {
|
||||||
this.dimension = dimension;
|
this.dimension = dimension;
|
||||||
this.partialHashedSeed = partialHashedSeed;
|
this.partialHashedSeed = partialHashedSeed;
|
||||||
this.difficulty = difficulty;
|
this.difficulty = difficulty;
|
||||||
this.gamemode = gamemode;
|
this.gamemode = gamemode;
|
||||||
this.levelType = levelType;
|
this.levelType = levelType;
|
||||||
|
this.shouldKeepPlayerData = shouldKeepPlayerData;
|
||||||
|
this.dimensionInfo = dimensionInfo;
|
||||||
|
this.previousGamemode = previousGamemode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDimension() {
|
public int getDimension() {
|
||||||
@ -66,6 +74,22 @@ public class Respawn implements MinecraftPacket {
|
|||||||
this.levelType = levelType;
|
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
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Respawn{"
|
return "Respawn{"
|
||||||
@ -74,25 +98,48 @@ public class Respawn implements MinecraftPacket {
|
|||||||
+ ", difficulty=" + difficulty
|
+ ", difficulty=" + difficulty
|
||||||
+ ", gamemode=" + gamemode
|
+ ", gamemode=" + gamemode
|
||||||
+ ", levelType='" + levelType + '\''
|
+ ", levelType='" + levelType + '\''
|
||||||
|
+ ", shouldKeepPlayerData=" + shouldKeepPlayerData
|
||||||
|
+ ", dimensionRegistryName='" + dimensionInfo.toString() + '\''
|
||||||
|
+ ", previousGamemode=" + previousGamemode
|
||||||
+ '}';
|
+ '}';
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
|
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
|
||||||
|
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();
|
this.dimension = buf.readInt();
|
||||||
|
}
|
||||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_13_2) <= 0) {
|
if (version.compareTo(ProtocolVersion.MINECRAFT_1_13_2) <= 0) {
|
||||||
this.difficulty = buf.readUnsignedByte();
|
this.difficulty = buf.readUnsignedByte();
|
||||||
}
|
}
|
||||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_15) >= 0) {
|
if (version.compareTo(ProtocolVersion.MINECRAFT_1_15) >= 0) {
|
||||||
this.partialHashedSeed = buf.readLong();
|
this.partialHashedSeed = buf.readLong();
|
||||||
}
|
}
|
||||||
this.gamemode = buf.readUnsignedByte();
|
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);
|
this.levelType = ProtocolUtils.readString(buf, 16);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
|
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
|
||||||
|
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
|
||||||
|
ProtocolUtils.writeString(buf, dimensionInfo.getRegistryIdentifier());
|
||||||
|
ProtocolUtils.writeString(buf, dimensionInfo.getLevelName());
|
||||||
|
} else {
|
||||||
buf.writeInt(dimension);
|
buf.writeInt(dimension);
|
||||||
|
}
|
||||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_13_2) <= 0) {
|
if (version.compareTo(ProtocolVersion.MINECRAFT_1_13_2) <= 0) {
|
||||||
buf.writeByte(difficulty);
|
buf.writeByte(difficulty);
|
||||||
}
|
}
|
||||||
@ -100,8 +147,15 @@ public class Respawn implements MinecraftPacket {
|
|||||||
buf.writeLong(partialHashedSeed);
|
buf.writeLong(partialHashedSeed);
|
||||||
}
|
}
|
||||||
buf.writeByte(gamemode);
|
buf.writeByte(gamemode);
|
||||||
|
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);
|
ProtocolUtils.writeString(buf, levelType);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean handle(MinecraftSessionHandler handler) {
|
public boolean handle(MinecraftSessionHandler handler) {
|
||||||
|
@ -45,7 +45,11 @@ public class ServerLoginSuccess implements MinecraftPacket {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
|
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
|
||||||
|
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
|
||||||
|
uuid = ProtocolUtils.readUuidIntArray(buf);
|
||||||
|
} else {
|
||||||
uuid = UUID.fromString(ProtocolUtils.readString(buf, 36));
|
uuid = UUID.fromString(ProtocolUtils.readString(buf, 36));
|
||||||
|
}
|
||||||
username = ProtocolUtils.readString(buf, 16);
|
username = ProtocolUtils.readString(buf, 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,7 +58,11 @@ public class ServerLoginSuccess implements MinecraftPacket {
|
|||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
throw new IllegalStateException("No UUID specified!");
|
throw new IllegalStateException("No UUID specified!");
|
||||||
}
|
}
|
||||||
|
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
|
||||||
|
ProtocolUtils.writeUuidIntArray(buf, uuid);
|
||||||
|
} else {
|
||||||
ProtocolUtils.writeString(buf, uuid.toString());
|
ProtocolUtils.writeString(buf, uuid.toString());
|
||||||
|
}
|
||||||
if (username == null) {
|
if (username == null) {
|
||||||
throw new IllegalStateException("No username specified!");
|
throw new IllegalStateException("No username specified!");
|
||||||
}
|
}
|
||||||
|
@ -134,5 +134,6 @@ public class ArgumentPropertyRegistry {
|
|||||||
dummy("minecraft:int_range", DUMMY);
|
dummy("minecraft:int_range", DUMMY);
|
||||||
dummy("minecraft:float_range", DUMMY);
|
dummy("minecraft:float_range", DUMMY);
|
||||||
dummy("minecraft:time", DUMMY); // added in 1.14
|
dummy("minecraft:time", DUMMY); // added in 1.14
|
||||||
|
dummy("minecraft:uuid", DUMMY); // added in 1.16
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren