Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-06 00:00:47 +01:00
Rework Dimension Registry
Dieser Commit ist enthalten in:
Ursprung
009f207883
Commit
368d50b455
@ -35,7 +35,7 @@ public enum ProtocolVersion {
|
|||||||
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(721, "1.16");
|
MINECRAFT_1_16(722, "1.16");
|
||||||
|
|
||||||
private final int protocol;
|
private final int protocol;
|
||||||
private final String name;
|
private final String name;
|
||||||
|
@ -34,11 +34,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;
|
||||||
@ -336,58 +334,20 @@ 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);
|
||||||
int tempDim = joinGame.getDimension() == 0 ? -1 : 0;
|
|
||||||
// Since 1.16 this dynamic changed:
|
// Since 1.16 this dynamic changed:
|
||||||
// The respawn packet has a keepMetadata flag which should
|
// We don't need to send two dimension swiches anymore!
|
||||||
// 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 (player.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_16) < 0) {
|
||||||
if (dimensionRegistry.getWorldNames().size() > 1
|
int tempDim = joinGame.getDimension() == 0 ? -1 : 0;
|
||||||
&& 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(),
|
||||||
false, dimensionInfo));
|
false, joinGame.getDimensionInfo()));
|
||||||
}
|
}
|
||||||
|
|
||||||
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(),
|
||||||
doubleSwitch, joinGame.getDimensionInfo()));
|
false, joinGame.getDimensionInfo()));
|
||||||
|
|
||||||
destination.setActiveDimensionRegistry(joinGame.getDimensionRegistry()); // 1.16
|
destination.setActiveDimensionRegistry(joinGame.getDimensionRegistry()); // 1.16
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,106 @@
|
|||||||
|
package com.velocitypowered.proxy.protocol;
|
||||||
|
|
||||||
|
import net.kyori.nbt.CompoundTag;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
public class DimensionData {
|
||||||
|
private final @Nonnull 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 @Nullable Long fixedTime;
|
||||||
|
private final @Nullable Boolean hasEnderdragonFight;
|
||||||
|
|
||||||
|
public DimensionData(@Nonnull String registryIdentifier, boolean isNatural,
|
||||||
|
float ambientLight, boolean isShrunk, boolean isUltrawarm,
|
||||||
|
boolean hasCeiling, boolean hasSkylight,
|
||||||
|
@Nullable Long fixedTime, @Nullable Boolean hasEnderdragonFight) {
|
||||||
|
this.registryIdentifier = registryIdentifier;
|
||||||
|
this.isNatural = isNatural;
|
||||||
|
this.ambientLight = ambientLight;
|
||||||
|
this.isShrunk = isShrunk;
|
||||||
|
this.isUltrawarm = isUltrawarm;
|
||||||
|
this.hasCeiling = hasCeiling;
|
||||||
|
this.hasSkylight = hasSkylight;
|
||||||
|
this.fixedTime = fixedTime;
|
||||||
|
this.hasEnderdragonFight = hasEnderdragonFight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nonnull 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 isHasCeiling() {
|
||||||
|
return hasCeiling;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isHasSkylight() {
|
||||||
|
return hasSkylight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable Long getFixedTime() {
|
||||||
|
return fixedTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable Boolean getHasEnderdragonFight() {
|
||||||
|
return hasEnderdragonFight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DimensionData fromNBT(@Nonnull CompoundTag toRead) {
|
||||||
|
if (toRead == null){
|
||||||
|
throw new IllegalArgumentException("CompoundTag cannot be null");
|
||||||
|
}
|
||||||
|
String registryIdentifier = toRead.getString("key");
|
||||||
|
CompoundTag values = toRead.getCompound("element");
|
||||||
|
boolean isNatural = values.getBoolean("natural");
|
||||||
|
float ambientLight = values.getFloat("ambient_light");
|
||||||
|
boolean isShrunk = values.getBoolean("shrunk");
|
||||||
|
boolean isUltrawarm = values.getBoolean("ultrawarm");
|
||||||
|
boolean hasCeiling = values.getBoolean("has_ceiling");
|
||||||
|
boolean hasSkylight = values.getBoolean("has_skylight");
|
||||||
|
Long fixedTime = values.contains("fixed_time") ? values.getLong("fixed_time") : null;
|
||||||
|
Boolean hasEnderdragonFight = values.contains("has_enderdragon_fight") ? values.getBoolean("has_enderdragon_fight") : null;
|
||||||
|
return new DimensionData(registryIdentifier, isNatural, ambientLight, isShrunk, isUltrawarm, hasCeiling, hasSkylight, fixedTime, hasEnderdragonFight);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompoundTag encode() {
|
||||||
|
CompoundTag ret = new CompoundTag();
|
||||||
|
ret.putString("key", registryIdentifier);
|
||||||
|
CompoundTag values = new CompoundTag();
|
||||||
|
values.putBoolean("natural", isNatural);
|
||||||
|
values.putFloat("ambient_light", ambientLight);
|
||||||
|
values.putBoolean("shrunk", isShrunk);
|
||||||
|
values.putBoolean("ultrawarm", isUltrawarm);
|
||||||
|
values.putBoolean("has_ceiling", hasCeiling);
|
||||||
|
values.putBoolean("has_skylight", hasSkylight);
|
||||||
|
if (fixedTime != null) {
|
||||||
|
values.putLong("fixed_time", fixedTime);
|
||||||
|
}
|
||||||
|
if (hasEnderdragonFight != null) {
|
||||||
|
values.putBoolean("has_enderdragon_fight", hasEnderdragonFight);
|
||||||
|
}
|
||||||
|
ret.put("element", values);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
@ -1,35 +1,33 @@
|
|||||||
package com.velocitypowered.proxy.protocol;
|
package com.velocitypowered.proxy.protocol;
|
||||||
|
|
||||||
import com.velocitypowered.proxy.connection.MinecraftConnection;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
public class DimensionInfo {
|
public class DimensionInfo {
|
||||||
|
|
||||||
private final @Nonnull String dimensionIdentifier;
|
private final @Nonnull String dimensionIdentifier;
|
||||||
private final @Nonnull String dimensionLevelName;
|
private final @Nonnull String levelName;
|
||||||
private final boolean isFlat;
|
private final boolean isFlat;
|
||||||
private final boolean isDebugType;
|
private final boolean isDebugType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes a new {@link DimensionInfo} instance.
|
* Initializes a new {@link DimensionInfo} instance.
|
||||||
* @param dimensionIdentifier the identifier for the dimension from the registry
|
* @param dimensionIdentifier the identifier for the dimension from the registry
|
||||||
* @param dimensionLevelName the level name as displayed in the F3 menu and logs
|
* @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 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
|
* @param isDebugType if true constrains the world to the very limited debug-type world
|
||||||
*/
|
*/
|
||||||
public DimensionInfo(@Nonnull String dimensionIdentifier, @Nonnull String dimensionLevelName,
|
public DimensionInfo(@Nonnull String dimensionIdentifier, @Nonnull String levelName,
|
||||||
boolean isFlat, boolean isDebugType) {
|
boolean isFlat, boolean isDebugType) {
|
||||||
if (dimensionIdentifier == null || dimensionIdentifier.isEmpty()
|
if (dimensionIdentifier == null || dimensionIdentifier.isEmpty()
|
||||||
|| dimensionIdentifier.isBlank()) {
|
|| dimensionIdentifier.isBlank()) {
|
||||||
throw new IllegalArgumentException("DimensionRegistryName may not be empty or null");
|
throw new IllegalArgumentException("DimensionRegistryName may not be empty or null");
|
||||||
}
|
}
|
||||||
this.dimensionIdentifier = dimensionIdentifier;
|
this.dimensionIdentifier = dimensionIdentifier;
|
||||||
if (dimensionLevelName == null || dimensionLevelName.isEmpty()
|
if (levelName == null || levelName.isEmpty()
|
||||||
|| dimensionLevelName.isBlank()) {
|
|| levelName.isBlank()) {
|
||||||
throw new IllegalArgumentException("DimensionLevelName may not be empty or null");
|
throw new IllegalArgumentException("DimensionLevelName may not be empty or null");
|
||||||
}
|
}
|
||||||
this.dimensionLevelName = dimensionLevelName;
|
this.levelName = levelName;
|
||||||
this.isFlat = isFlat;
|
this.isFlat = isFlat;
|
||||||
this.isDebugType = isDebugType;
|
this.isDebugType = isDebugType;
|
||||||
}
|
}
|
||||||
@ -42,8 +40,8 @@ public class DimensionInfo {
|
|||||||
return isFlat;
|
return isFlat;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nonnull String getDimensionLevelName() {
|
public @Nonnull String getLevelName() {
|
||||||
return dimensionLevelName;
|
return levelName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nonnull String getDimensionIdentifier() {
|
public @Nonnull String getDimensionIdentifier() {
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
package com.velocitypowered.proxy.protocol;
|
package com.velocitypowered.proxy.protocol;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.NoSuchElementException;
|
|
||||||
import java.util.Set;
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
import com.google.inject.internal.asm.$TypePath;
|
||||||
import net.kyori.nbt.CompoundTag;
|
import net.kyori.nbt.CompoundTag;
|
||||||
import net.kyori.nbt.ListTag;
|
import net.kyori.nbt.ListTag;
|
||||||
import net.kyori.nbt.Tag;
|
import net.kyori.nbt.Tag;
|
||||||
@ -12,72 +11,53 @@ import net.kyori.nbt.TagType;
|
|||||||
|
|
||||||
public class DimensionRegistry {
|
public class DimensionRegistry {
|
||||||
|
|
||||||
// Mapping:
|
private final @Nonnull Set<DimensionData> dimensionRegistry;
|
||||||
// dimensionIdentifier (Client connection refers to this),
|
private final @Nonnull String[] levelNames;
|
||||||
// dimensionType (The game refers to this).
|
|
||||||
private final @Nonnull Map<String, String> dimensionRegistry;
|
|
||||||
private final @Nonnull Set<String> worldNames;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes a new {@link DimensionRegistry} instance.
|
* Initializes a new {@link DimensionRegistry} instance.
|
||||||
* This registry is required for 1.16+ clients/servers to communicate,
|
* This registry is required for 1.16+ clients/servers to communicate,
|
||||||
* it constrains the dimension types and names the client can be sent
|
* it constrains the dimension types and names the client can be sent
|
||||||
* in a Respawn action (dimension change).
|
* in a Respawn action (dimension change).
|
||||||
* @param dimensionRegistry a populated map containing dimensionIdentifier and dimensionType sets
|
* @param dimensionRegistry a populated set containing dimension data types
|
||||||
* @param worldNames a populated {@link Set} of the dimension level names the server offers
|
* @param levelNames a populated {@link Set} of the dimension level names the server offers
|
||||||
*/
|
*/
|
||||||
public DimensionRegistry(Map<String, String> dimensionRegistry,
|
public DimensionRegistry(Set<DimensionData> dimensionRegistry,
|
||||||
Set<String> worldNames) {
|
String[] levelNames) {
|
||||||
if (dimensionRegistry == null || dimensionRegistry.isEmpty()
|
if (dimensionRegistry == null || dimensionRegistry.isEmpty()
|
||||||
|| worldNames == null || worldNames.isEmpty()) {
|
|| levelNames == null || levelNames.length == 0) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Dimension registry requires valid arguments, not null and not empty");
|
"Dimension registry requires valid arguments, not null and not empty");
|
||||||
}
|
}
|
||||||
this.dimensionRegistry = dimensionRegistry;
|
this.dimensionRegistry = dimensionRegistry;
|
||||||
this.worldNames = worldNames;
|
this.levelNames = levelNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nonnull Map<String, String> getDimensionRegistry() {
|
public @Nonnull Set<DimensionData> getDimensionRegistry() {
|
||||||
return dimensionRegistry;
|
return dimensionRegistry;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nonnull Set<String> getWorldNames() {
|
public @Nonnull String[] getLevelNames() {
|
||||||
return worldNames;
|
return levelNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the internal dimension type as used by the game.
|
* Returns the internal dimension data type as used by the game.
|
||||||
* @param dimensionIdentifier how the type is identified by the connection
|
* @param dimensionIdentifier how the dimension is identified by the connection
|
||||||
* @return game internal dimension type
|
* @return game dimension data
|
||||||
*/
|
*/
|
||||||
public @Nonnull String getDimensionType(@Nonnull String dimensionIdentifier) {
|
public @Nonnull DimensionData getDimensionData(@Nonnull String dimensionIdentifier) {
|
||||||
if (dimensionIdentifier == null) {
|
if (dimensionIdentifier == null) {
|
||||||
throw new IllegalArgumentException("Dimension identifier cannot be null!");
|
throw new IllegalArgumentException("Dimension identifier cannot be null!");
|
||||||
}
|
}
|
||||||
if (dimensionIdentifier == null || !dimensionRegistry.containsKey(dimensionIdentifier)) {
|
for (DimensionData iter : dimensionRegistry) {
|
||||||
|
if(iter.getRegistryIdentifier().equals(dimensionIdentifier)) {
|
||||||
|
return iter;
|
||||||
|
}
|
||||||
|
}
|
||||||
throw new NoSuchElementException("Dimension with identifier " + dimensionIdentifier
|
throw new NoSuchElementException("Dimension with identifier " + dimensionIdentifier
|
||||||
+ " doesn't exist in this Registry!");
|
+ " doesn't exist in this Registry!");
|
||||||
}
|
}
|
||||||
return dimensionRegistry.get(dimensionIdentifier);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the dimension identifier as used by the client.
|
|
||||||
* @param dimensionType the internal dimension type
|
|
||||||
* @return game dimension identifier
|
|
||||||
*/
|
|
||||||
public @Nonnull String getDimensionIdentifier(@Nonnull String dimensionType) {
|
|
||||||
if (dimensionType == null) {
|
|
||||||
throw new IllegalArgumentException("Dimension type cannot be null!");
|
|
||||||
}
|
|
||||||
for (Map.Entry<String, String> entry : dimensionRegistry.entrySet()) {
|
|
||||||
if (entry.getValue().equals(dimensionType)) {
|
|
||||||
return entry.getKey();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new NoSuchElementException("Dimension type " + dimensionType
|
|
||||||
+ " doesn't exist in this Registry!");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks a {@link DimensionInfo} against this registry.
|
* Checks a {@link DimensionInfo} against this registry.
|
||||||
@ -89,11 +69,13 @@ public class DimensionRegistry {
|
|||||||
throw new IllegalArgumentException("Dimension info cannot be null");
|
throw new IllegalArgumentException("Dimension info cannot be null");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (!worldNames.contains(toValidate.getDimensionLevelName())) {
|
getDimensionData(toValidate.getDimensionIdentifier());
|
||||||
return false;
|
for(int i = 0; i < levelNames.length; i++) {
|
||||||
}
|
if(levelNames[i].equals(toValidate.getDimensionIdentifier())) {
|
||||||
getDimensionType(toValidate.getDimensionIdentifier());
|
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
} catch (NoSuchElementException thrown) {
|
} catch (NoSuchElementException thrown) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -103,51 +85,42 @@ public class DimensionRegistry {
|
|||||||
* Encodes the stored Dimension registry as CompoundTag.
|
* Encodes the stored Dimension registry as CompoundTag.
|
||||||
* @return the CompoundTag containing identifier:type mappings
|
* @return the CompoundTag containing identifier:type mappings
|
||||||
*/
|
*/
|
||||||
public CompoundTag encodeToCompoundTag() {
|
public CompoundTag encodeRegistry() {
|
||||||
CompoundTag ret = new CompoundTag();
|
CompoundTag ret = new CompoundTag();
|
||||||
ListTag list = new ListTag(TagType.COMPOUND);
|
ListTag list = new ListTag(TagType.COMPOUND);
|
||||||
for (Map.Entry<String, String> entry : dimensionRegistry.entrySet()) {
|
for (DimensionData iter : dimensionRegistry) {
|
||||||
CompoundTag item = new CompoundTag();
|
list.add(iter.encode());
|
||||||
item.putString("key", entry.getKey());
|
|
||||||
item.putString("element", entry.getValue());
|
|
||||||
list.add(item);
|
|
||||||
}
|
}
|
||||||
ret.put("dimension", list);
|
ret.put("dimension", list);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decodes a CompoundTag storing dimension mappings to a Map identifier:type.
|
* Decodes a CompoundTag storing a dimension registry
|
||||||
* @param toParse CompoundTag containing a dimension registry
|
* @param toParse CompoundTag containing a dimension registry
|
||||||
|
* @param levelNames world level names
|
||||||
*/
|
*/
|
||||||
public static Map<String, String> parseToMapping(@Nonnull CompoundTag toParse) {
|
public static DimensionRegistry fromGameData(@Nonnull CompoundTag toParse, @Nonnull String[] levelNames) {
|
||||||
if (toParse == null) {
|
if (toParse == null) {
|
||||||
throw new IllegalArgumentException("CompoundTag cannot be null");
|
throw new IllegalArgumentException("CompoundTag cannot be null");
|
||||||
}
|
}
|
||||||
|
if (levelNames == null || levelNames.length == 0) {
|
||||||
|
throw new IllegalArgumentException("Level names cannot be null or empty");
|
||||||
|
}
|
||||||
if (!toParse.contains("dimension", TagType.LIST)) {
|
if (!toParse.contains("dimension", TagType.LIST)) {
|
||||||
throw new IllegalStateException("CompoundTag does not contain a dimension List");
|
throw new IllegalStateException("CompoundTag does not contain a dimension List");
|
||||||
}
|
}
|
||||||
ListTag dimensions = toParse.getList("dimension");
|
ListTag dimensions = toParse.getList("dimension");
|
||||||
Map<String, String> mappings = new HashMap<String, String>();
|
Set<DimensionData> mappings = new HashSet<DimensionData>();
|
||||||
for (Tag iter : dimensions) {
|
for (Tag iter : dimensions) {
|
||||||
if (iter instanceof CompoundTag) {
|
if (!(iter instanceof CompoundTag)) {
|
||||||
throw new IllegalStateException("DimensionList in CompoundTag contains an invalid entry");
|
throw new IllegalStateException("DimensionList in CompoundTag contains an invalid entry");
|
||||||
}
|
}
|
||||||
CompoundTag mapping = (CompoundTag) iter;
|
mappings.add(DimensionData.fromNBT((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()) {
|
if (mappings.isEmpty()) {
|
||||||
throw new IllegalStateException("Dimension mapping cannot be empty");
|
throw new IllegalStateException("Dimension mapping cannot be empty");
|
||||||
}
|
}
|
||||||
return mappings;
|
return new DimensionRegistry(mappings, levelNames);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,8 @@ 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.*;
|
||||||
import com.velocitypowered.proxy.protocol.DimensionRegistry;
|
|
||||||
import com.velocitypowered.proxy.protocol.MinecraftPacket;
|
|
||||||
import com.velocitypowered.proxy.protocol.ProtocolUtils;
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
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.Map;
|
||||||
@ -140,8 +136,7 @@ public class JoinGame implements MinecraftPacket {
|
|||||||
String levelName = null;
|
String levelName = null;
|
||||||
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
|
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
|
||||||
String levelNames[] = ProtocolUtils.readStringArray(buf);
|
String levelNames[] = ProtocolUtils.readStringArray(buf);
|
||||||
Map<String, String> dimensionMapping = DimensionRegistry.parseToMapping(ProtocolUtils.readCompoundTag(buf));
|
this.dimensionRegistry = DimensionRegistry.fromGameData(ProtocolUtils.readCompoundTag(buf), levelNames);
|
||||||
this.dimensionRegistry = new DimensionRegistry(dimensionMapping, Set.of(levelNames));
|
|
||||||
dimensionIdentifier = ProtocolUtils.readString(buf);
|
dimensionIdentifier = ProtocolUtils.readString(buf);
|
||||||
levelName = 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) {
|
||||||
@ -180,10 +175,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.writeStringArray(buf, dimensionRegistry.getWorldNames().toArray(new String[dimensionRegistry.getWorldNames().size()]));
|
ProtocolUtils.writeStringArray(buf, dimensionRegistry.getLevelNames());
|
||||||
ProtocolUtils.writeCompoundTag(buf, dimensionRegistry.encodeToCompoundTag());
|
ProtocolUtils.writeCompoundTag(buf, dimensionRegistry.encodeRegistry());
|
||||||
ProtocolUtils.writeString(buf, dimensionInfo.getDimensionIdentifier());
|
ProtocolUtils.writeString(buf, dimensionInfo.getDimensionIdentifier());
|
||||||
ProtocolUtils.writeString(buf, dimensionInfo.getDimensionLevelName());
|
ProtocolUtils.writeString(buf, dimensionInfo.getLevelName());
|
||||||
} 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 {
|
||||||
|
@ -123,7 +123,7 @@ public class Respawn implements MinecraftPacket {
|
|||||||
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, dimensionInfo.getDimensionIdentifier());
|
ProtocolUtils.writeString(buf, dimensionInfo.getDimensionIdentifier());
|
||||||
ProtocolUtils.writeString(buf, dimensionInfo.getDimensionLevelName());
|
ProtocolUtils.writeString(buf, dimensionInfo.getLevelName());
|
||||||
} else {
|
} else {
|
||||||
buf.writeInt(dimension);
|
buf.writeInt(dimension);
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren