From 6734ef3a087ed3f068ee9ce809d93ce31ce844bc Mon Sep 17 00:00:00 2001 From: "Five (Xer)" Date: Thu, 4 Jun 2020 19:13:10 +0200 Subject: [PATCH] Checkstyle-auto --- .../client/ClientPlaySessionHandler.java | 13 +- .../proxy/protocol/DimensionInfo.java | 57 +++--- .../proxy/protocol/DimensionRegistry.java | 186 +++++++++--------- .../proxy/protocol/ProtocolUtils.java | 4 +- 4 files changed, 135 insertions(+), 125 deletions(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java index 5a0820cd9..7dc865355 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ClientPlaySessionHandler.java @@ -352,17 +352,18 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { 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){ + if (dimensionRegistry.getWorldNames().size() > 1 + && dimensionRegistry.getDimensionRegistry().size() > 1) { String tmpDimLevelName = null; - for(String s : dimensionRegistry.getWorldNames()){ - if(!s.equals(dimensionInfo.getDimensionLevelName())){ + 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())){ + for (String s : dimensionRegistry.getDimensionRegistry().keySet()) { + if (!s.equals(dimensionInfo.getDimensionIdentifier())) { tmpDimIdentifier = s; break; } @@ -376,7 +377,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler { } else { doubleSwitch = true; } - if(doubleSwitch) { + if (doubleSwitch) { player.getMinecraftConnection().delayedWrite( new Respawn(tempDim, joinGame.getPartialHashedSeed(), joinGame.getDifficulty(), joinGame.getGamemode(), joinGame.getLevelType(), diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/DimensionInfo.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/DimensionInfo.java index 3e98da366..1a5a5245b 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/DimensionInfo.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/DimensionInfo.java @@ -4,37 +4,40 @@ 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; + 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 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 isDebugType() { + return isDebugType; + } - public boolean isFlat() { - return isFlat; - } + public boolean isFlat() { + return isFlat; + } - public @Nonnull String getDimensionLevelName() { - return dimensionLevelName; - } + public @Nonnull String getDimensionLevelName() { + return dimensionLevelName; + } - public @Nonnull String getDimensionIdentifier() { - return dimensionIdentifier; - } + public @Nonnull String getDimensionIdentifier() { + return dimensionIdentifier; + } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/DimensionRegistry.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/DimensionRegistry.java index d4305f540..70ea76e26 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/DimensionRegistry.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/DimensionRegistry.java @@ -1,113 +1,119 @@ 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.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 dimensionRegistry; - private final @Nonnull Set worldNames; + private final @Nonnull Map dimensionRegistry; + private final @Nonnull Set worldNames; - public DimensionRegistry(Map dimensionRegistry, Set 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 DimensionRegistry(Map dimensionRegistry, + Set 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 getDimensionRegistry() { - return dimensionRegistry; + public @Nonnull Map getDimensionRegistry() { + return dimensionRegistry; + } + + public @Nonnull Set getWorldNames() { + return worldNames; + } + + public @Nonnull String getDimensionIdentifier(@Nonnull String dimensionName) { + if (dimensionName == null) { + throw new IllegalArgumentException("DimensionName cannot be null!"); } - - public @Nonnull Set getWorldNames() { - return worldNames; + if (dimensionName == null || !dimensionRegistry.containsKey(dimensionName)) { + throw new NoSuchElementException("DimensionName " + dimensionName + + " doesn't exist in this Registry!"); } + return dimensionRegistry.get(dimensionName); + } - 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!"); } - - public @Nonnull String getDimensionName(@Nonnull String dimensionIdentifier) { - if (dimensionIdentifier == null) { - throw new IllegalArgumentException("DimensionIdentifier cannot be null!"); - } - for (Map.Entry entry : dimensionRegistry.entrySet()){ - if(entry.getValue().equals(dimensionIdentifier)){ - return entry.getKey(); - } - } - throw new NoSuchElementException("DimensionIdentifier " + dimensionIdentifier + " doesn't exist in this Registry!"); + for (Map.Entry 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 boolean isValidFor(@Nonnull DimensionInfo toValidate) { + if (toValidate == null) { + throw new IllegalArgumentException("DimensionInfo cannot be null"); } - - public CompoundTag encodeToCompoundTag(){ - CompoundTag ret = new CompoundTag(); - ListTag list = new ListTag(TagType.COMPOUND); - for(Map.Entry 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; + try { + if (!worldNames.contains(toValidate.getDimensionLevelName())) { + return false; + } + getDimensionName(toValidate.getDimensionIdentifier()); + return true; + } catch (NoSuchElementException thrown) { + return false; } + } - public static Map 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 mappings = new HashMap(); - 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; + public CompoundTag encodeToCompoundTag() { + CompoundTag ret = new CompoundTag(); + ListTag list = new ListTag(TagType.COMPOUND); + for (Map.Entry 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 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 mappings = new HashMap(); + 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; + } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java index e2b55c544..a272c8023 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/ProtocolUtils.java @@ -245,7 +245,7 @@ public enum ProtocolUtils { public static String[] readStringArray(ByteBuf buf) { int length = readVarInt(buf); String[] ret = new String[length]; - for(int i = 0; i < length; i++) { + for (int i = 0; i < length; i++) { ret[i] = readString(buf); } return ret; @@ -262,7 +262,7 @@ public enum ProtocolUtils { return; } writeVarInt(buf, stringArray.length); - for(int i = 0; i < stringArray.length; i++) { + for (int i = 0; i < stringArray.length; i++) { writeString(buf, stringArray[i]); } }