13
0
geforkt von Mirrors/Velocity

Merge Cleanup from indev

Cleanup
Dieser Commit ist enthalten in:
FivePB (Xer) 2020-06-07 00:36:47 +02:00 committet von GitHub
Commit c004e5769d
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
5 geänderte Dateien mit 104 neuen und 110 gelöschten Zeilen

Datei anzeigen

@ -21,8 +21,8 @@ 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.util.ConnectionRequestResults.Impl;
import com.velocitypowered.proxy.connection.registry.DimensionRegistry; import com.velocitypowered.proxy.connection.registry.DimensionRegistry;
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;
import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder; import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder;
@ -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,7 +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 @Nullable DimensionRegistry activeDimensionRegistry; private @MonotonicNonNull DimensionRegistry activeDimensionRegistry;
/** /**
* Initializes a new server connection. * Initializes a new server connection.

Datei anzeigen

@ -1,19 +1,19 @@
package com.velocitypowered.proxy.connection.registry; package com.velocitypowered.proxy.connection.registry;
import javax.annotation.Nonnull; import com.google.common.base.Optional;
import javax.annotation.Nullable; import com.google.common.base.Preconditions;
import net.kyori.nbt.CompoundTag; import net.kyori.nbt.CompoundTag;
public class DimensionData { public final class DimensionData {
private final @Nonnull String registryIdentifier; private final String registryIdentifier;
private final boolean isNatural; private final boolean isNatural;
private final float ambientLight; private final float ambientLight;
private final boolean isShrunk; private final boolean isShrunk;
private final boolean isUltrawarm; private final boolean isUltrawarm;
private final boolean hasCeiling; private final boolean hasCeiling;
private final boolean hasSkylight; private final boolean hasSkylight;
private final @Nullable Long fixedTime; private final Optional<Long> fixedTime;
private final @Nullable Boolean hasEnderdragonFight; private final Optional<Boolean> hasEnderdragonFight;
/** /**
* Initializes a new {@link DimensionData} instance. * Initializes a new {@link DimensionData} instance.
@ -27,10 +27,14 @@ public class DimensionData {
* @param fixedTime optional. If set to any game daytime value will deactivate time cycle * @param fixedTime optional. If set to any game daytime value will deactivate time cycle
* @param hasEnderdragonFight optional. Internal flag used in the end dimension * @param hasEnderdragonFight optional. Internal flag used in the end dimension
*/ */
public DimensionData(@Nonnull String registryIdentifier, boolean isNatural, public DimensionData(String registryIdentifier, boolean isNatural,
float ambientLight, boolean isShrunk, boolean isUltrawarm, float ambientLight, boolean isShrunk, boolean isUltrawarm,
boolean hasCeiling, boolean hasSkylight, boolean hasCeiling, boolean hasSkylight,
@Nullable Long fixedTime, @Nullable Boolean hasEnderdragonFight) { Optional<Long> fixedTime, Optional<Boolean> hasEnderdragonFight) {
Preconditions.checkNotNull(
registryIdentifier, "registryIdentifier cannot be null");
Preconditions.checkArgument(registryIdentifier.length() > 0 && !registryIdentifier.isBlank(),
"registryIdentifier cannot be empty");
this.registryIdentifier = registryIdentifier; this.registryIdentifier = registryIdentifier;
this.isNatural = isNatural; this.isNatural = isNatural;
this.ambientLight = ambientLight; this.ambientLight = ambientLight;
@ -38,11 +42,13 @@ public class DimensionData {
this.isUltrawarm = isUltrawarm; this.isUltrawarm = isUltrawarm;
this.hasCeiling = hasCeiling; this.hasCeiling = hasCeiling;
this.hasSkylight = hasSkylight; this.hasSkylight = hasSkylight;
this.fixedTime = fixedTime; this.fixedTime = Preconditions.checkNotNull(
this.hasEnderdragonFight = hasEnderdragonFight; fixedTime, "fixedTime optional object cannot be null");
this.hasEnderdragonFight = Preconditions.checkNotNull(
hasEnderdragonFight, "hasEnderdragonFight optional object cannot be null");
} }
public @Nonnull String getRegistryIdentifier() { public String getRegistryIdentifier() {
return registryIdentifier; return registryIdentifier;
} }
@ -70,11 +76,11 @@ public class DimensionData {
return hasSkylight; return hasSkylight;
} }
public @Nullable Long getFixedTime() { public Optional<Long> getFixedTime() {
return fixedTime; return fixedTime;
} }
public @Nullable Boolean getHasEnderdragonFight() { public Optional<Boolean> getHasEnderdragonFight() {
return hasEnderdragonFight; return hasEnderdragonFight;
} }
@ -83,10 +89,8 @@ public class DimensionData {
* @param toRead the compound from the registry to read * @param toRead the compound from the registry to read
* @return game dimension data * @return game dimension data
*/ */
public static DimensionData fromCompoundTag(@Nonnull CompoundTag toRead) { public static DimensionData decodeCompoundTag(CompoundTag toRead) {
if (toRead == null) { Preconditions.checkNotNull(toRead, "CompoundTag cannot be null");
throw new IllegalArgumentException("CompoundTag cannot be null");
}
String registryIdentifier = toRead.getString("key"); String registryIdentifier = toRead.getString("key");
CompoundTag values = toRead.getCompound("element"); CompoundTag values = toRead.getCompound("element");
boolean isNatural = values.getBoolean("natural"); boolean isNatural = values.getBoolean("natural");
@ -95,9 +99,12 @@ public class DimensionData {
boolean isUltrawarm = values.getBoolean("ultrawarm"); boolean isUltrawarm = values.getBoolean("ultrawarm");
boolean hasCeiling = values.getBoolean("has_ceiling"); boolean hasCeiling = values.getBoolean("has_ceiling");
boolean hasSkylight = values.getBoolean("has_skylight"); boolean hasSkylight = values.getBoolean("has_skylight");
Long fixedTime = values.contains("fixed_time") ? values.getLong("fixed_time") : null; Optional<Long> fixedTime = Optional.fromNullable(
Boolean hasEnderdragonFight = values.contains("has_enderdragon_fight") values.contains("fixed_time")
? values.getBoolean("has_enderdragon_fight") : null; ? values.getLong("fixed_time") : null);
Optional<Boolean> hasEnderdragonFight = Optional.fromNullable(
values.contains("has_enderdragon_fight")
? values.getBoolean("has_enderdragon_fight") : null);
return new DimensionData( return new DimensionData(
registryIdentifier, isNatural, ambientLight, isShrunk, registryIdentifier, isNatural, ambientLight, isShrunk,
isUltrawarm, hasCeiling, hasSkylight, fixedTime, hasEnderdragonFight); isUltrawarm, hasCeiling, hasSkylight, fixedTime, hasEnderdragonFight);
@ -117,11 +124,11 @@ public class DimensionData {
values.putBoolean("ultrawarm", isUltrawarm); values.putBoolean("ultrawarm", isUltrawarm);
values.putBoolean("has_ceiling", hasCeiling); values.putBoolean("has_ceiling", hasCeiling);
values.putBoolean("has_skylight", hasSkylight); values.putBoolean("has_skylight", hasSkylight);
if (fixedTime != null) { if (fixedTime.isPresent()) {
values.putLong("fixed_time", fixedTime); values.putLong("fixed_time", fixedTime.get());
} }
if (hasEnderdragonFight != null) { if (hasEnderdragonFight.isPresent()) {
values.putBoolean("has_enderdragon_fight", hasEnderdragonFight); values.putBoolean("has_enderdragon_fight", hasEnderdragonFight.get());
} }
ret.put("element", values); ret.put("element", values);
return ret; return ret;

Datei anzeigen

@ -1,11 +1,11 @@
package com.velocitypowered.proxy.connection.registry; package com.velocitypowered.proxy.connection.registry;
import javax.annotation.Nonnull; import com.google.common.base.Preconditions;
public class DimensionInfo { public final class DimensionInfo {
private final @Nonnull String registryIdentifier; private final String registryIdentifier;
private final @Nonnull String levelName; private final String levelName;
private final boolean isFlat; private final boolean isFlat;
private final boolean isDebugType; private final boolean isDebugType;
@ -16,18 +16,18 @@ public class DimensionInfo {
* @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 registryIdentifier, @Nonnull String levelName, public DimensionInfo(String registryIdentifier, String levelName,
boolean isFlat, boolean isDebugType) { boolean isFlat, boolean isDebugType) {
if (registryIdentifier == null || registryIdentifier.isEmpty() this.registryIdentifier = Preconditions.checkNotNull(
|| registryIdentifier.isBlank()) { registryIdentifier, "registryIdentifier cannot be null");
throw new IllegalArgumentException("Dimension registry identifier may not be empty or null"); Preconditions.checkArgument(
} registryIdentifier.length() > 0 && !registryIdentifier.isBlank(),
this.registryIdentifier = registryIdentifier; "registryIdentifier cannot be empty");
if (levelName == null || levelName.isEmpty() this.levelName = Preconditions.checkNotNull(
|| levelName.isBlank()) { levelName, "levelName cannot be null");
throw new IllegalArgumentException("dimensions level name may not be empty or null"); Preconditions.checkArgument(
} levelName.length() > 0 && !levelName.isBlank(),
this.levelName = levelName; "registryIdentifier cannot be empty");
this.isFlat = isFlat; this.isFlat = isFlat;
this.isDebugType = isDebugType; this.isDebugType = isDebugType;
} }
@ -40,11 +40,11 @@ public class DimensionInfo {
return isFlat; return isFlat;
} }
public @Nonnull String getLevelName() { public String getLevelName() {
return levelName; return levelName;
} }
public @Nonnull String getRegistryIdentifier() { public String getRegistryIdentifier() {
return registryIdentifier; return registryIdentifier;
} }
} }

Datei anzeigen

@ -1,63 +1,65 @@
package com.velocitypowered.proxy.connection.registry; package com.velocitypowered.proxy.connection.registry;
import java.util.HashSet; import com.google.common.base.Preconditions;
import java.util.NoSuchElementException; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import java.util.Map;
import java.util.Set; import java.util.Set;
import javax.annotation.Nonnull;
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;
import net.kyori.nbt.TagType; import net.kyori.nbt.TagType;
import org.checkerframework.checker.nullness.qual.Nullable;
public class DimensionRegistry {
private final @Nonnull Set<DimensionData> dimensionRegistry; public final class DimensionRegistry {
private final @Nonnull String[] levelNames;
private final Map<String, DimensionData> registeredDimensions;
private final ImmutableSet<String> levelNames;
/** /**
* 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 set containing dimension data types * This WILL raise an IllegalArgumentException if the following is not met:
* @param levelNames a populated {@link Set} of the dimension level names the server offers * - 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(Set<DimensionData> dimensionRegistry, public DimensionRegistry(ImmutableSet<DimensionData> registeredDimensions,
String[] levelNames) { ImmutableSet<String> levelNames) {
if (dimensionRegistry == null || dimensionRegistry.isEmpty() Preconditions.checkNotNull(registeredDimensions,
|| levelNames == null || levelNames.length == 0) { "registeredDimensions cannot be null");
throw new IllegalArgumentException( Preconditions.checkNotNull(levelNames,
"Dimension registry requires valid arguments, not null and not empty"); "levelNames cannot be null");
} Preconditions.checkArgument(registeredDimensions.size() > 0,
this.dimensionRegistry = dimensionRegistry; "registeredDimensions needs to be populated");
Preconditions.checkArgument(levelNames.size() > 0,
"levelNames needs to populated");
this.registeredDimensions = Maps.uniqueIndex(
registeredDimensions, DimensionData::getRegistryIdentifier);
this.levelNames = levelNames; this.levelNames = levelNames;
} }
public @Nonnull Set<DimensionData> getDimensionRegistry() { public Map<String, DimensionData> getRegisteredDimensions() {
return dimensionRegistry; return registeredDimensions;
} }
public @Nonnull String[] getLevelNames() { public Set<String> getLevelNames() {
return levelNames; return levelNames;
} }
/** /**
* Returns the internal dimension data type as used by the game. * Returns the internal dimension data type as used by the game.
* @param dimensionIdentifier how the dimension is identified by the connection * @param dimensionIdentifier how the dimension is identified by the connection
* @return game dimension data * @return game dimension data or null if not registered
*/ */
public @Nonnull DimensionData getDimensionData(@Nonnull String dimensionIdentifier) { public @Nullable DimensionData getDimensionData(String dimensionIdentifier) {
if (dimensionIdentifier == null) { return registeredDimensions.getOrDefault(dimensionIdentifier, null);
throw new IllegalArgumentException("Dimension identifier cannot be null!");
}
for (DimensionData iter : dimensionRegistry) {
if (iter.getRegistryIdentifier().equals(dimensionIdentifier)) {
return iter;
}
}
throw new NoSuchElementException("Dimension with identifier " + dimensionIdentifier
+ " doesn't exist in this Registry!");
} }
/** /**
@ -65,21 +67,12 @@ public class DimensionRegistry {
* @param toValidate the {@link DimensionInfo} to validate * @param toValidate the {@link DimensionInfo} to validate
* @return true: the dimension information is valid for this registry * @return true: the dimension information is valid for this registry
*/ */
public boolean isValidFor(@Nonnull DimensionInfo toValidate) { public boolean isValidFor(DimensionInfo toValidate) {
if (toValidate == null) { if (toValidate == null) {
throw new IllegalArgumentException("Dimension info cannot be null");
}
try {
getDimensionData(toValidate.getRegistryIdentifier());
for (int i = 0; i < levelNames.length; i++) {
if (levelNames[i].equals(toValidate.getRegistryIdentifier())) {
return true;
}
}
return false;
} catch (NoSuchElementException thrown) {
return false; return false;
} }
return registeredDimensions.containsKey(toValidate.getRegistryIdentifier())
&& levelNames.contains(toValidate.getLevelName());
} }
/** /**
@ -89,7 +82,7 @@ public class DimensionRegistry {
public CompoundTag encodeRegistry() { public CompoundTag encodeRegistry() {
CompoundTag ret = new CompoundTag(); CompoundTag ret = new CompoundTag();
ListTag list = new ListTag(TagType.COMPOUND); ListTag list = new ListTag(TagType.COMPOUND);
for (DimensionData iter : dimensionRegistry) { for (DimensionData iter : registeredDimensions.values()) {
list.add(iter.encodeAsCompundTag()); list.add(iter.encodeAsCompundTag());
} }
ret.put("dimension", list); ret.put("dimension", list);
@ -99,30 +92,18 @@ public class DimensionRegistry {
/** /**
* Decodes a CompoundTag storing a dimension registry. * 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 DimensionRegistry fromGameData( public static ImmutableSet<DimensionData> fromGameData(CompoundTag toParse) {
@Nonnull CompoundTag toParse, @Nonnull String[] levelNames) { Preconditions.checkNotNull(toParse, "CompoundTag cannot be null");
if (toParse == null) { Preconditions.checkArgument(toParse.contains("dimension", TagType.LIST),
throw new IllegalArgumentException("CompoundTag cannot be null"); "CompoundTag does not contain a dimension list");
}
if (levelNames == null || levelNames.length == 0) {
throw new IllegalArgumentException("Level names cannot be null or empty");
}
if (!toParse.contains("dimension", TagType.LIST)) {
throw new IllegalStateException("CompoundTag does not contain a dimension List");
}
ListTag dimensions = toParse.getList("dimension"); ListTag dimensions = toParse.getList("dimension");
Set<DimensionData> mappings = new HashSet<DimensionData>(); ImmutableSet.Builder<DimensionData> mappings = ImmutableSet.builder();
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"); mappings.add(DimensionData.decodeCompoundTag((CompoundTag) iter));
} }
mappings.add(DimensionData.fromCompoundTag((CompoundTag) iter));
} }
if (mappings.isEmpty()) { return mappings.build();
throw new IllegalStateException("Dimension mapping cannot be empty");
}
return new DimensionRegistry(mappings, levelNames);
} }
} }

Datei anzeigen

@ -1,7 +1,9 @@
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.connection.registry.DimensionData;
import com.velocitypowered.proxy.connection.registry.DimensionInfo; import com.velocitypowered.proxy.connection.registry.DimensionInfo;
import com.velocitypowered.proxy.connection.registry.DimensionRegistry; import com.velocitypowered.proxy.connection.registry.DimensionRegistry;
import com.velocitypowered.proxy.protocol.*; import com.velocitypowered.proxy.protocol.*;
@ -134,8 +136,9 @@ public class JoinGame implements MinecraftPacket {
String dimensionIdentifier = null; String dimensionIdentifier = null;
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); ImmutableSet<String> levelNames = ImmutableSet.copyOf(ProtocolUtils.readStringArray(buf));
this.dimensionRegistry = DimensionRegistry.fromGameData(ProtocolUtils.readCompoundTag(buf), levelNames); ImmutableSet<DimensionData> readData = DimensionRegistry.fromGameData(ProtocolUtils.readCompoundTag(buf));
this.dimensionRegistry = new DimensionRegistry(readData, 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) {
@ -174,7 +177,8 @@ 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.getLevelNames()); ProtocolUtils.writeStringArray(buf, dimensionRegistry.getLevelNames().toArray(
new String[dimensionRegistry.getLevelNames().size()]));
ProtocolUtils.writeCompoundTag(buf, dimensionRegistry.encodeRegistry()); ProtocolUtils.writeCompoundTag(buf, dimensionRegistry.encodeRegistry());
ProtocolUtils.writeString(buf, dimensionInfo.getRegistryIdentifier()); ProtocolUtils.writeString(buf, dimensionInfo.getRegistryIdentifier());
ProtocolUtils.writeString(buf, dimensionInfo.getLevelName()); ProtocolUtils.writeString(buf, dimensionInfo.getLevelName());