Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-17 05:20:14 +01:00
Save progress
Dieser Commit ist enthalten in:
Ursprung
38487c5bba
Commit
18e5953976
@ -23,6 +23,7 @@ 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.util.ConnectionRequestResults.Impl;
|
import com.velocitypowered.proxy.connection.util.ConnectionRequestResults.Impl;
|
||||||
|
import com.velocitypowered.proxy.protocol.DimensionRegistry;
|
||||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
||||||
import com.velocitypowered.proxy.protocol.StateRegistry;
|
import com.velocitypowered.proxy.protocol.StateRegistry;
|
||||||
import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder;
|
import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder;
|
||||||
@ -53,6 +54,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 @Nullable DimensionRegistry activeDimensionRegistry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes a new server connection.
|
* Initializes a new server connection.
|
||||||
@ -297,4 +299,11 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
|
|||||||
return hasCompletedJoin;
|
return hasCompletedJoin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DimensionRegistry getActiveDimensionRegistry() {
|
||||||
|
return activeDimensionRegistry;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setActiveDimensionRegistry(DimensionRegistry activeDimensionRegistry) {
|
||||||
|
this.activeDimensionRegistry = activeDimensionRegistry;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,8 @@ import com.velocitypowered.proxy.connection.MinecraftConnection;
|
|||||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||||
import com.velocitypowered.proxy.connection.backend.BackendConnectionPhases;
|
import com.velocitypowered.proxy.connection.backend.BackendConnectionPhases;
|
||||||
import com.velocitypowered.proxy.connection.backend.VelocityServerConnection;
|
import com.velocitypowered.proxy.connection.backend.VelocityServerConnection;
|
||||||
|
import com.velocitypowered.proxy.protocol.DimensionInfo;
|
||||||
|
import com.velocitypowered.proxy.protocol.DimensionRegistry;
|
||||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
||||||
import com.velocitypowered.proxy.protocol.StateRegistry;
|
import com.velocitypowered.proxy.protocol.StateRegistry;
|
||||||
import com.velocitypowered.proxy.protocol.packet.BossBar;
|
import com.velocitypowered.proxy.protocol.packet.BossBar;
|
||||||
@ -313,8 +315,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,20 +336,59 @@ 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);
|
||||||
if (player.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_16) < 0) {
|
|
||||||
int tempDim = joinGame.getDimension() == 0 ? -1 : 0;
|
int tempDim = joinGame.getDimension() == 0 ? -1 : 0;
|
||||||
|
// Since 1.16 this dynamic changed:
|
||||||
|
// The respawn packet has a keepMetadata flag which should
|
||||||
|
// be true for dimension switches, so by double switching
|
||||||
|
// we can keep the flow of the game
|
||||||
|
// There is a problem here though: By only sending one dimension
|
||||||
|
// in the registry we can't do that, so we need to run an *unclean* switch.
|
||||||
|
// NOTE! We can't just send a fake dimension in the registry either
|
||||||
|
// to get two dimensions, as modded games will break with this.
|
||||||
|
final DimensionRegistry dimensionRegistry = joinGame.getDimensionRegistry();
|
||||||
|
DimensionInfo dimensionInfo = joinGame.getDimensionInfo(); // 1.16+
|
||||||
|
// The doubleSwitch variable doubles as keepMetadata flag for an unclean switch as
|
||||||
|
// well as to indicate the second switch.
|
||||||
|
boolean doubleSwitch;
|
||||||
|
// This is not ONE if because this will all be null in < 1.16
|
||||||
|
if (player.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_16) < 0) {
|
||||||
|
if(dimensionRegistry.getWorldNames().size() > 1 && dimensionRegistry.getDimensionRegistry().size() > 1){
|
||||||
|
String tmpDimLevelName = null;
|
||||||
|
for(String s : dimensionRegistry.getWorldNames()){
|
||||||
|
if(!s.equals(dimensionInfo.getDimensionLevelName())){
|
||||||
|
tmpDimLevelName = s;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String tmpDimIdentifier = null;
|
||||||
|
for(String s : dimensionRegistry.getDimensionRegistry().keySet()){
|
||||||
|
if(!s.equals(dimensionInfo.getDimensionIdentifier())){
|
||||||
|
tmpDimIdentifier = s;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dimensionInfo = new DimensionInfo(tmpDimIdentifier, tmpDimLevelName, true, false);
|
||||||
|
doubleSwitch = true;
|
||||||
|
} else {
|
||||||
|
doubleSwitch = false;
|
||||||
|
// We should add a warning here.
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
doubleSwitch = true;
|
||||||
|
}
|
||||||
|
if(doubleSwitch) {
|
||||||
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(),
|
||||||
joinGame.getShouldKeepPlayerData(),
|
false, dimensionInfo));
|
||||||
joinGame.getIsDebug(), joinGame.getIsFlat(),
|
|
||||||
joinGame.getDimensionRegistryName()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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(),
|
||||||
joinGame.getShouldKeepPlayerData(), joinGame.getIsDebug(), joinGame.getIsFlat(),
|
doubleSwitch, joinGame.getDimensionInfo()));
|
||||||
joinGame.getDimensionRegistryName()));
|
|
||||||
|
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
|
||||||
|
@ -0,0 +1,40 @@
|
|||||||
|
package com.velocitypowered.proxy.protocol;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
public class DimensionInfo {
|
||||||
|
|
||||||
|
private final @Nonnull String dimensionIdentifier;
|
||||||
|
private final @Nonnull String dimensionLevelName;
|
||||||
|
private final boolean isFlat;
|
||||||
|
private final boolean isDebugType;
|
||||||
|
|
||||||
|
public DimensionInfo(@Nonnull String dimensionIdentifier, @Nonnull String dimensionLevelName, boolean isFlat, boolean isDebugType) {
|
||||||
|
if(dimensionIdentifier == null || dimensionIdentifier.isEmpty() || dimensionIdentifier.isBlank()) {
|
||||||
|
throw new IllegalArgumentException("DimensionRegistryName may not be empty or null");
|
||||||
|
}
|
||||||
|
this.dimensionIdentifier = dimensionIdentifier;
|
||||||
|
if(dimensionLevelName == null || dimensionLevelName.isEmpty() || dimensionLevelName.isBlank()) {
|
||||||
|
throw new IllegalArgumentException("DimensionLevelName may not be empty or null");
|
||||||
|
}
|
||||||
|
this.dimensionLevelName = dimensionLevelName;
|
||||||
|
this.isFlat = isFlat;
|
||||||
|
this.isDebugType = isDebugType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDebugType() {
|
||||||
|
return isDebugType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isFlat() {
|
||||||
|
return isFlat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nonnull String getDimensionLevelName() {
|
||||||
|
return dimensionLevelName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nonnull String getDimensionIdentifier() {
|
||||||
|
return dimensionIdentifier;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,113 @@
|
|||||||
|
package com.velocitypowered.proxy.protocol;
|
||||||
|
|
||||||
|
import net.kyori.nbt.CompoundTag;
|
||||||
|
import net.kyori.nbt.ListTag;
|
||||||
|
import net.kyori.nbt.Tag;
|
||||||
|
import net.kyori.nbt.TagType;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class DimensionRegistry {
|
||||||
|
|
||||||
|
private final @Nonnull Map<String, String> dimensionRegistry;
|
||||||
|
private final @Nonnull Set<String> worldNames;
|
||||||
|
|
||||||
|
public DimensionRegistry(Map<String, String> dimensionRegistry, Set<String> worldNames) {
|
||||||
|
if(dimensionRegistry == null || dimensionRegistry.isEmpty() || worldNames == null || worldNames.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("DimensionRegistry requires valid arguments, not null and not empty");
|
||||||
|
}
|
||||||
|
this.dimensionRegistry = dimensionRegistry;
|
||||||
|
this.worldNames = worldNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nonnull Map<String, String> getDimensionRegistry() {
|
||||||
|
return dimensionRegistry;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nonnull Set<String> getWorldNames() {
|
||||||
|
return worldNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nonnull String getDimensionIdentifier(@Nonnull String dimensionName) {
|
||||||
|
if (dimensionName == null) {
|
||||||
|
throw new IllegalArgumentException("DimensionName cannot be null!");
|
||||||
|
}
|
||||||
|
if (dimensionName == null || !dimensionRegistry.containsKey(dimensionName)) {
|
||||||
|
throw new NoSuchElementException("DimensionName " + dimensionName + " doesn't exist in this Registry!");
|
||||||
|
}
|
||||||
|
return dimensionRegistry.get(dimensionName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nonnull String getDimensionName(@Nonnull String dimensionIdentifier) {
|
||||||
|
if (dimensionIdentifier == null) {
|
||||||
|
throw new IllegalArgumentException("DimensionIdentifier cannot be null!");
|
||||||
|
}
|
||||||
|
for (Map.Entry<String, String> entry : dimensionRegistry.entrySet()){
|
||||||
|
if(entry.getValue().equals(dimensionIdentifier)){
|
||||||
|
return entry.getKey();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new NoSuchElementException("DimensionIdentifier " + dimensionIdentifier + " doesn't exist in this Registry!");
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isValidFor(@Nonnull DimensionInfo toValidate) {
|
||||||
|
if(toValidate == null) {
|
||||||
|
throw new IllegalArgumentException("DimensionInfo cannot be null");
|
||||||
|
}
|
||||||
|
try{
|
||||||
|
if (!worldNames.contains(toValidate.getDimensionLevelName())){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
getDimensionName(toValidate.getDimensionIdentifier());
|
||||||
|
return true;
|
||||||
|
|
||||||
|
} catch(NoSuchElementException thrown){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompoundTag encodeToCompoundTag(){
|
||||||
|
CompoundTag ret = new CompoundTag();
|
||||||
|
ListTag list = new ListTag(TagType.COMPOUND);
|
||||||
|
for(Map.Entry<String, String> entry : dimensionRegistry.entrySet()){
|
||||||
|
CompoundTag item = new CompoundTag();
|
||||||
|
item.putString("key", entry.getKey());
|
||||||
|
item.putString("element", entry.getValue());
|
||||||
|
list.add(item);
|
||||||
|
}
|
||||||
|
ret.put("dimension", list);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<String, String> parseToMapping(@Nonnull CompoundTag toParse){
|
||||||
|
if(toParse == null) {
|
||||||
|
throw new IllegalArgumentException("CompoundTag cannot be null");
|
||||||
|
}
|
||||||
|
if(!toParse.contains("dimension", TagType.LIST)){
|
||||||
|
throw new IllegalStateException("CompoundTag does not contain a dimension List");
|
||||||
|
}
|
||||||
|
ListTag dimensions = toParse.getList("dimension");
|
||||||
|
Map<String, String> mappings = new HashMap<String, String>();
|
||||||
|
for(Tag iter : dimensions){
|
||||||
|
if(iter instanceof CompoundTag){
|
||||||
|
throw new IllegalStateException("DimensionList in CompoundTag contains an invalid entry");
|
||||||
|
}
|
||||||
|
CompoundTag mapping = (CompoundTag) iter;
|
||||||
|
String key = mapping.getString("key", null);
|
||||||
|
String element = mapping.getString("element", null);
|
||||||
|
if(element == null || key == null){
|
||||||
|
throw new IllegalStateException("DimensionList in CompoundTag contains an mapping");
|
||||||
|
}
|
||||||
|
if(mappings.containsKey(key) || mappings.containsValue(element)) {
|
||||||
|
throw new IllegalStateException("Dimension mappings may not have identifier/name duplicates");
|
||||||
|
}
|
||||||
|
mappings.put(key, element);
|
||||||
|
}
|
||||||
|
if(mappings.isEmpty()){
|
||||||
|
throw new IllegalStateException("Dimension mapping cannot be empty");
|
||||||
|
}
|
||||||
|
return mappings;
|
||||||
|
}
|
||||||
|
}
|
@ -21,6 +21,7 @@ import java.util.List;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import net.kyori.nbt.CompoundTag;
|
import net.kyori.nbt.CompoundTag;
|
||||||
|
import net.kyori.nbt.TagType;
|
||||||
|
|
||||||
public enum ProtocolUtils {
|
public enum ProtocolUtils {
|
||||||
;
|
;
|
||||||
@ -204,7 +205,7 @@ public enum ProtocolUtils {
|
|||||||
try {
|
try {
|
||||||
DataInput input = new ByteBufInputStream(buf);
|
DataInput input = new ByteBufInputStream(buf);
|
||||||
byte type = input.readByte();
|
byte type = input.readByte();
|
||||||
if (type != 10) {
|
if (type != TagType.COMPOUND.id()) {
|
||||||
throw new DecoderException("NBTTag is not a CompoundTag");
|
throw new DecoderException("NBTTag is not a CompoundTag");
|
||||||
}
|
}
|
||||||
input.readUTF(); // Head-padding
|
input.readUTF(); // Head-padding
|
||||||
@ -236,6 +237,36 @@ public enum ProtocolUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
@ -2,12 +2,17 @@ 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.protocol.DimensionInfo;
|
||||||
|
import com.velocitypowered.proxy.protocol.DimensionRegistry;
|
||||||
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;
|
||||||
import net.kyori.nbt.CompoundTag;
|
import net.kyori.nbt.CompoundTag;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class JoinGame implements MinecraftPacket {
|
public class JoinGame implements MinecraftPacket {
|
||||||
|
|
||||||
private int entityId;
|
private int entityId;
|
||||||
@ -20,11 +25,8 @@ public class JoinGame implements MinecraftPacket {
|
|||||||
private int viewDistance; // 1.14+
|
private int viewDistance; // 1.14+
|
||||||
private boolean reducedDebugInfo;
|
private boolean reducedDebugInfo;
|
||||||
private boolean showRespawnScreen;
|
private boolean showRespawnScreen;
|
||||||
private boolean shouldKeepPlayerData; // 1.16+
|
private DimensionRegistry dimensionRegistry; // 1.16+
|
||||||
private boolean isDebug; // 1.16+
|
private DimensionInfo dimensionInfo; // 1.16+
|
||||||
private boolean isFlat; // 1.16+
|
|
||||||
private String dimensionRegistryName; // 1.16+
|
|
||||||
private CompoundTag dimensionRegistry; // 1.16+
|
|
||||||
|
|
||||||
public int getEntityId() {
|
public int getEntityId() {
|
||||||
return entityId;
|
return entityId;
|
||||||
@ -97,43 +99,19 @@ public class JoinGame implements MinecraftPacket {
|
|||||||
this.reducedDebugInfo = reducedDebugInfo;
|
this.reducedDebugInfo = reducedDebugInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getShouldKeepPlayerData() {
|
public DimensionInfo getDimensionInfo() {
|
||||||
return shouldKeepPlayerData;
|
return dimensionInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setShouldKeepPlayerData(boolean shouldKeepPlayerData) {
|
public void setDimensionInfo(DimensionInfo dimensionInfo) {
|
||||||
this.shouldKeepPlayerData = shouldKeepPlayerData;
|
this.dimensionInfo = dimensionInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getIsDebug() {
|
public DimensionRegistry getDimensionRegistry() {
|
||||||
return isDebug;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIsDebug(boolean isDebug) {
|
|
||||||
this.isDebug = isDebug;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean getIsFlat() {
|
|
||||||
return isFlat;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIsFlat(boolean isFlat) {
|
|
||||||
this.isFlat = isFlat;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDimensionRegistryName() {
|
|
||||||
return dimensionRegistryName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDimensionRegistryName(String dimensionRegistryName) {
|
|
||||||
this.dimensionRegistryName = dimensionRegistryName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompoundTag getDimensionRegistry() {
|
|
||||||
return dimensionRegistry;
|
return dimensionRegistry;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDimensionRegistry(CompoundTag dimensionRegistry) {
|
public void setDimensionRegistry(DimensionRegistry dimensionRegistry) {
|
||||||
this.dimensionRegistry = dimensionRegistry;
|
this.dimensionRegistry = dimensionRegistry;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,10 +127,8 @@ public class JoinGame implements MinecraftPacket {
|
|||||||
+ ", levelType='" + levelType + '\''
|
+ ", levelType='" + levelType + '\''
|
||||||
+ ", viewDistance=" + viewDistance
|
+ ", viewDistance=" + viewDistance
|
||||||
+ ", reducedDebugInfo=" + reducedDebugInfo
|
+ ", reducedDebugInfo=" + reducedDebugInfo
|
||||||
+ ", shouldKeepPlayerData=" + shouldKeepPlayerData
|
+ ", dimensionRegistry='" + dimensionRegistry.toString() + '\''
|
||||||
+ ", isDebug=" + isDebug
|
+ ", dimensionInfo='" + dimensionInfo.toString() + '\''
|
||||||
+ ", isFlat='" + isFlat
|
|
||||||
+ ", dimensionRegistryName='" + dimensionRegistryName + '\''
|
|
||||||
+ '}';
|
+ '}';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,9 +136,14 @@ public class JoinGame implements MinecraftPacket {
|
|||||||
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.readUnsignedByte();
|
||||||
|
String dimensionIdentifier = null;
|
||||||
|
String levelName = null;
|
||||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
|
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
|
||||||
this.dimensionRegistry = ProtocolUtils.readCompoundTag(buf);
|
String levelNames[] = ProtocolUtils.readStringArray(buf);
|
||||||
this.dimensionRegistryName = ProtocolUtils.readString(buf);
|
Map<String, String> dimensionMapping = DimensionRegistry.parseToMapping(ProtocolUtils.readCompoundTag(buf));
|
||||||
|
this.dimensionRegistry = new DimensionRegistry(dimensionMapping, Set.of(levelNames));
|
||||||
|
dimensionIdentifier = ProtocolUtils.readString(buf);
|
||||||
|
levelName = ProtocolUtils.readString(buf);
|
||||||
} else if (version.compareTo(ProtocolVersion.MINECRAFT_1_9_1) >= 0) {
|
} else if (version.compareTo(ProtocolVersion.MINECRAFT_1_9_1) >= 0) {
|
||||||
this.dimension = buf.readInt();
|
this.dimension = buf.readInt();
|
||||||
} else {
|
} else {
|
||||||
@ -188,8 +169,9 @@ public class JoinGame implements MinecraftPacket {
|
|||||||
this.showRespawnScreen = buf.readBoolean();
|
this.showRespawnScreen = buf.readBoolean();
|
||||||
}
|
}
|
||||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
|
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
|
||||||
isDebug = buf.readBoolean();
|
boolean isDebug = buf.readBoolean();
|
||||||
isFlat = buf.readBoolean();
|
boolean isFlat = buf.readBoolean();
|
||||||
|
this.dimensionInfo = new DimensionInfo(dimensionIdentifier, levelName, isFlat, isDebug);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,8 +180,10 @@ public class JoinGame implements MinecraftPacket {
|
|||||||
buf.writeInt(entityId);
|
buf.writeInt(entityId);
|
||||||
buf.writeByte(gamemode);
|
buf.writeByte(gamemode);
|
||||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
|
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
|
||||||
ProtocolUtils.writeCompoundTag(buf, dimensionRegistry);
|
ProtocolUtils.writeStringArray(buf, dimensionRegistry.getWorldNames().toArray(new String[dimensionRegistry.getWorldNames().size()]));
|
||||||
ProtocolUtils.writeString(buf, dimensionRegistryName);
|
ProtocolUtils.writeCompoundTag(buf, dimensionRegistry.encodeToCompoundTag());
|
||||||
|
ProtocolUtils.writeString(buf, dimensionInfo.getDimensionIdentifier());
|
||||||
|
ProtocolUtils.writeString(buf, dimensionInfo.getDimensionLevelName());
|
||||||
} else if (version.compareTo(ProtocolVersion.MINECRAFT_1_9_1) >= 0) {
|
} else if (version.compareTo(ProtocolVersion.MINECRAFT_1_9_1) >= 0) {
|
||||||
buf.writeInt(dimension);
|
buf.writeInt(dimension);
|
||||||
} else {
|
} else {
|
||||||
@ -226,8 +210,8 @@ public class JoinGame implements MinecraftPacket {
|
|||||||
buf.writeBoolean(showRespawnScreen);
|
buf.writeBoolean(showRespawnScreen);
|
||||||
}
|
}
|
||||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
|
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
|
||||||
buf.writeBoolean(isDebug);
|
buf.writeBoolean(dimensionInfo.isDebugType());
|
||||||
buf.writeBoolean(isFlat);
|
buf.writeBoolean(dimensionInfo.isFlat());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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.protocol.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;
|
||||||
@ -14,24 +15,20 @@ public class Respawn implements MinecraftPacket {
|
|||||||
private short gamemode;
|
private short gamemode;
|
||||||
private String levelType = "";
|
private String levelType = "";
|
||||||
private boolean shouldKeepPlayerData; // 1.16+
|
private boolean shouldKeepPlayerData; // 1.16+
|
||||||
private boolean isDebug; // 1.16+
|
private DimensionInfo dimensionInfo;
|
||||||
private boolean isFlat; // 1.16+
|
|
||||||
private String dimensionRegistryName; // 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, boolean shouldKeepPlayerData, boolean isDebug, boolean isFlat, String dimensionRegistryName) {
|
String levelType, boolean shouldKeepPlayerData, DimensionInfo dimensionInfo) {
|
||||||
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.shouldKeepPlayerData = shouldKeepPlayerData;
|
||||||
this.isDebug = isDebug;
|
this.dimensionInfo = dimensionInfo;
|
||||||
this.isFlat = isFlat;
|
|
||||||
this.dimensionRegistryName = dimensionRegistryName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDimension() {
|
public int getDimension() {
|
||||||
@ -82,30 +79,6 @@ public class Respawn implements MinecraftPacket {
|
|||||||
this.shouldKeepPlayerData = shouldKeepPlayerData;
|
this.shouldKeepPlayerData = shouldKeepPlayerData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getIsDebug() {
|
|
||||||
return isDebug;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIsDebug(boolean isDebug) {
|
|
||||||
this.isDebug = isDebug;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean getIsFlat() {
|
|
||||||
return isFlat;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setIsFlat(boolean isFlat) {
|
|
||||||
this.isFlat = isFlat;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDimensionRegistryName() {
|
|
||||||
return dimensionRegistryName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDimensionRegistryName(String dimensionRegistryName) {
|
|
||||||
this.dimensionRegistryName = dimensionRegistryName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Respawn{"
|
return "Respawn{"
|
||||||
@ -115,16 +88,17 @@ public class Respawn implements MinecraftPacket {
|
|||||||
+ ", gamemode=" + gamemode
|
+ ", gamemode=" + gamemode
|
||||||
+ ", levelType='" + levelType + '\''
|
+ ", levelType='" + levelType + '\''
|
||||||
+ ", shouldKeepPlayerData=" + shouldKeepPlayerData
|
+ ", shouldKeepPlayerData=" + shouldKeepPlayerData
|
||||||
+ ", isDebug=" + isDebug
|
+ ", dimensionRegistryName='" + dimensionInfo.toString() + '\''
|
||||||
+ ", isFlat='" + isFlat
|
|
||||||
+ ", dimensionRegistryName='" + dimensionRegistryName + '\''
|
|
||||||
+ '}';
|
+ '}';
|
||||||
}
|
}
|
||||||
|
|
||||||
@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) {
|
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
|
||||||
this.dimensionRegistryName = ProtocolUtils.readString(buf); // Not sure what the cap on that is
|
dimensionIdentifier = ProtocolUtils.readString(buf);
|
||||||
|
levelName = ProtocolUtils.readString(buf);
|
||||||
} else {
|
} else {
|
||||||
this.dimension = buf.readInt();
|
this.dimension = buf.readInt();
|
||||||
}
|
}
|
||||||
@ -136,8 +110,9 @@ public class Respawn implements MinecraftPacket {
|
|||||||
}
|
}
|
||||||
this.gamemode = buf.readUnsignedByte();
|
this.gamemode = buf.readUnsignedByte();
|
||||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
|
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
|
||||||
isDebug = buf.readBoolean();
|
boolean isDebug = buf.readBoolean();
|
||||||
isFlat = buf.readBoolean();
|
boolean isFlat = buf.readBoolean();
|
||||||
|
this.dimensionInfo = new DimensionInfo(dimensionIdentifier, levelName, isFlat, isDebug);
|
||||||
shouldKeepPlayerData = buf.readBoolean();
|
shouldKeepPlayerData = buf.readBoolean();
|
||||||
} else {
|
} else {
|
||||||
this.levelType = ProtocolUtils.readString(buf, 16);
|
this.levelType = ProtocolUtils.readString(buf, 16);
|
||||||
@ -147,7 +122,8 @@ public class Respawn implements MinecraftPacket {
|
|||||||
@Override
|
@Override
|
||||||
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
|
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
|
||||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
|
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
|
||||||
ProtocolUtils.writeString(buf, dimensionRegistryName);
|
ProtocolUtils.writeString(buf, dimensionInfo.getDimensionIdentifier());
|
||||||
|
ProtocolUtils.writeString(buf, dimensionInfo.getDimensionLevelName());
|
||||||
} else {
|
} else {
|
||||||
buf.writeInt(dimension);
|
buf.writeInt(dimension);
|
||||||
}
|
}
|
||||||
@ -159,8 +135,8 @@ public class Respawn implements MinecraftPacket {
|
|||||||
}
|
}
|
||||||
buf.writeByte(gamemode);
|
buf.writeByte(gamemode);
|
||||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
|
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
|
||||||
buf.writeBoolean(isDebug);
|
buf.writeBoolean(dimensionInfo.isDebugType());
|
||||||
buf.writeBoolean(isFlat);
|
buf.writeBoolean(dimensionInfo.isFlat());
|
||||||
buf.writeBoolean(shouldKeepPlayerData);
|
buf.writeBoolean(shouldKeepPlayerData);
|
||||||
} else {
|
} else {
|
||||||
ProtocolUtils.writeString(buf, levelType);
|
ProtocolUtils.writeString(buf, levelType);
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren