13
0
geforkt von Mirrors/Velocity

Checkstyle-auto

Dieser Commit ist enthalten in:
Five (Xer) 2020-06-04 19:13:10 +02:00
Ursprung 18e5953976
Commit 6734ef3a08
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: A3F306B10E6330E7
4 geänderte Dateien mit 135 neuen und 125 gelöschten Zeilen

Datei anzeigen

@ -352,17 +352,18 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
boolean doubleSwitch; boolean doubleSwitch;
// This is not ONE if because this will all be null in < 1.16 // 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 && dimensionRegistry.getDimensionRegistry().size() > 1){ if (dimensionRegistry.getWorldNames().size() > 1
&& dimensionRegistry.getDimensionRegistry().size() > 1) {
String tmpDimLevelName = null; String tmpDimLevelName = null;
for(String s : dimensionRegistry.getWorldNames()){ for (String s : dimensionRegistry.getWorldNames()) {
if(!s.equals(dimensionInfo.getDimensionLevelName())){ if (!s.equals(dimensionInfo.getDimensionLevelName())) {
tmpDimLevelName = s; tmpDimLevelName = s;
break; break;
} }
} }
String tmpDimIdentifier = null; String tmpDimIdentifier = null;
for(String s : dimensionRegistry.getDimensionRegistry().keySet()){ for (String s : dimensionRegistry.getDimensionRegistry().keySet()) {
if(!s.equals(dimensionInfo.getDimensionIdentifier())){ if (!s.equals(dimensionInfo.getDimensionIdentifier())) {
tmpDimIdentifier = s; tmpDimIdentifier = s;
break; break;
} }
@ -376,7 +377,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
} else { } else {
doubleSwitch = true; doubleSwitch = true;
} }
if(doubleSwitch) { 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(),

Datei anzeigen

@ -9,12 +9,15 @@ public class DimensionInfo {
private final boolean isFlat; private final boolean isFlat;
private final boolean isDebugType; private final boolean isDebugType;
public DimensionInfo(@Nonnull String dimensionIdentifier, @Nonnull String dimensionLevelName, boolean isFlat, boolean isDebugType) { public DimensionInfo(@Nonnull String dimensionIdentifier, @Nonnull String dimensionLevelName,
if(dimensionIdentifier == null || dimensionIdentifier.isEmpty() || dimensionIdentifier.isBlank()) { boolean isFlat, boolean isDebugType) {
if (dimensionIdentifier == null || dimensionIdentifier.isEmpty()
|| 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() || dimensionLevelName.isBlank()) { if (dimensionLevelName == null || dimensionLevelName.isEmpty()
|| dimensionLevelName.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.dimensionLevelName = dimensionLevelName;

Datei anzeigen

@ -1,21 +1,26 @@
package com.velocitypowered.proxy.protocol; package com.velocitypowered.proxy.protocol;
import java.util.HashMap;
import java.util.Map;
import java.util.NoSuchElementException;
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 javax.annotation.Nonnull;
import java.util.*;
public class DimensionRegistry { public class DimensionRegistry {
private final @Nonnull Map<String, String> dimensionRegistry; private final @Nonnull Map<String, String> dimensionRegistry;
private final @Nonnull Set<String> worldNames; private final @Nonnull Set<String> worldNames;
public DimensionRegistry(Map<String, String> dimensionRegistry, Set<String> worldNames) { public DimensionRegistry(Map<String, String> dimensionRegistry,
if(dimensionRegistry == null || dimensionRegistry.isEmpty() || worldNames == null || worldNames.isEmpty()) { Set<String> worldNames) {
throw new IllegalArgumentException("DimensionRegistry requires valid arguments, not null and not empty"); 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.dimensionRegistry = dimensionRegistry;
this.worldNames = worldNames; this.worldNames = worldNames;
@ -34,7 +39,8 @@ public class DimensionRegistry {
throw new IllegalArgumentException("DimensionName cannot be null!"); throw new IllegalArgumentException("DimensionName cannot be null!");
} }
if (dimensionName == null || !dimensionRegistry.containsKey(dimensionName)) { if (dimensionName == null || !dimensionRegistry.containsKey(dimensionName)) {
throw new NoSuchElementException("DimensionName " + dimensionName + " doesn't exist in this Registry!"); throw new NoSuchElementException("DimensionName " + dimensionName
+ " doesn't exist in this Registry!");
} }
return dimensionRegistry.get(dimensionName); return dimensionRegistry.get(dimensionName);
} }
@ -43,35 +49,34 @@ public class DimensionRegistry {
if (dimensionIdentifier == null) { if (dimensionIdentifier == null) {
throw new IllegalArgumentException("DimensionIdentifier cannot be null!"); throw new IllegalArgumentException("DimensionIdentifier cannot be null!");
} }
for (Map.Entry<String, String> entry : dimensionRegistry.entrySet()){ for (Map.Entry<String, String> entry : dimensionRegistry.entrySet()) {
if(entry.getValue().equals(dimensionIdentifier)){ if (entry.getValue().equals(dimensionIdentifier)) {
return entry.getKey(); return entry.getKey();
} }
} }
throw new NoSuchElementException("DimensionIdentifier " + dimensionIdentifier + " doesn't exist in this Registry!"); throw new NoSuchElementException("DimensionIdentifier " + dimensionIdentifier
+ " doesn't exist in this Registry!");
} }
public boolean isValidFor(@Nonnull DimensionInfo toValidate) { public boolean isValidFor(@Nonnull DimensionInfo toValidate) {
if(toValidate == null) { if (toValidate == null) {
throw new IllegalArgumentException("DimensionInfo cannot be null"); throw new IllegalArgumentException("DimensionInfo cannot be null");
} }
try{ try {
if (!worldNames.contains(toValidate.getDimensionLevelName())){ if (!worldNames.contains(toValidate.getDimensionLevelName())) {
return false; return false;
} }
getDimensionName(toValidate.getDimensionIdentifier()); getDimensionName(toValidate.getDimensionIdentifier());
return true; return true;
} catch (NoSuchElementException thrown) {
} catch(NoSuchElementException thrown){
return false; return false;
} }
} }
public CompoundTag encodeToCompoundTag(){ public CompoundTag encodeToCompoundTag() {
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 (Map.Entry<String, String> entry : dimensionRegistry.entrySet()) {
CompoundTag item = new CompoundTag(); CompoundTag item = new CompoundTag();
item.putString("key", entry.getKey()); item.putString("key", entry.getKey());
item.putString("element", entry.getValue()); item.putString("element", entry.getValue());
@ -81,31 +86,32 @@ public class DimensionRegistry {
return ret; return ret;
} }
public static Map<String, String> parseToMapping(@Nonnull CompoundTag toParse){ public static Map<String, String> parseToMapping(@Nonnull CompoundTag toParse) {
if(toParse == null) { if (toParse == null) {
throw new IllegalArgumentException("CompoundTag cannot be null"); throw new IllegalArgumentException("CompoundTag cannot be null");
} }
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>(); Map<String, String> mappings = new HashMap<String, String>();
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; CompoundTag mapping = (CompoundTag) iter;
String key = mapping.getString("key", null); String key = mapping.getString("key", null);
String element = mapping.getString("element", null); String element = mapping.getString("element", null);
if(element == null || key == null){ if (element == null || key == null) {
throw new IllegalStateException("DimensionList in CompoundTag contains an mapping"); throw new IllegalStateException("DimensionList in CompoundTag contains an mapping");
} }
if(mappings.containsKey(key) || mappings.containsValue(element)) { if (mappings.containsKey(key) || mappings.containsValue(element)) {
throw new IllegalStateException("Dimension mappings may not have identifier/name duplicates"); throw new IllegalStateException(
"Dimension mappings may not have identifier/name duplicates");
} }
mappings.put(key, element); 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 mappings;

Datei anzeigen

@ -245,7 +245,7 @@ public enum ProtocolUtils {
public static String[] readStringArray(ByteBuf buf) { public static String[] readStringArray(ByteBuf buf) {
int length = readVarInt(buf); int length = readVarInt(buf);
String[] ret = new String[length]; String[] ret = new String[length];
for(int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
ret[i] = readString(buf); ret[i] = readString(buf);
} }
return ret; return ret;
@ -262,7 +262,7 @@ public enum ProtocolUtils {
return; return;
} }
writeVarInt(buf, stringArray.length); writeVarInt(buf, stringArray.length);
for(int i = 0; i < stringArray.length; i++) { for (int i = 0; i < stringArray.length; i++) {
writeString(buf, stringArray[i]); writeString(buf, stringArray[i]);
} }
} }