From 070c7f5808dce5ddbf3e38140a2d2341a1c8755b Mon Sep 17 00:00:00 2001 From: KennyTV Date: Fri, 2 Apr 2021 14:15:30 +0200 Subject: [PATCH] Move to checker qual nullability annotations --- api/build.gradle.kts | 2 +- .../java/us/myles/ViaVersion/api/Pair.java | 2 +- .../java/us/myles/ViaVersion/api/Triple.java | 11 +++---- .../api/command/ViaVersionCommand.java | 5 ++- .../ViaVersion/api/data/MappingData.java | 26 +++++---------- .../api/data/MappingDataLoader.java | 14 +++----- .../myles/ViaVersion/api/data/Mappings.java | 2 +- .../ViaVersion/api/data/UserConnection.java | 14 +++----- .../ViaVersion/api/entities/EntityType.java | 8 ++--- .../api/minecraft/chunks/BaseChunk.java | 12 +++---- .../api/minecraft/chunks/Chunk.java | 10 +++--- .../api/minecraft/chunks/ChunkSection.java | 14 +++----- .../ViaVersion/api/minecraft/item/Item.java | 5 ++- .../api/minecraft/nbt/BinaryTagIO.java | 33 ++++++++----------- .../api/platform/ViaConnectionManager.java | 16 +++++---- .../api/platform/providers/ViaProviders.java | 5 ++- .../ViaVersion/api/protocol/Protocol.java | 8 ++--- .../api/protocol/ProtocolManager.java | 11 +++---- .../api/protocol/ProtocolRegistry.java | 8 ++--- .../api/protocol/ProtocolVersion.java | 14 ++++---- .../api/protocol/ServerProtocolVersion.java | 2 +- .../api/remapper/ValueTransformer.java | 5 ++- .../us/myles/ViaVersion/api/type/Type.java | 23 ++++++++++++- .../ViaVersion/api/type/types/StringType.java | 2 +- .../ViaVersion/util/CompactArrayUtil.java | 3 +- .../myles/ViaVersion/util/Int2IntBiMap.java | 10 +++--- buildSrc/src/main/kotlin/Versions.kt | 2 +- .../bukkit/handlers/BukkitEncodeHandler.java | 2 +- .../multiversion/PlayerSneakListener.java | 6 +++- .../us/myles/ViaVersion/BungeePlugin.java | 2 +- .../bungee/handlers/BungeeDecodeHandler.java | 2 +- .../bungee/handlers/BungeeEncodeHandler.java | 2 +- .../bungee/platform/BungeeViaConfig.java | 6 +++- .../us/myles/ViaVersion/api/ViaListener.java | 5 ++- .../api/protocol/ProtocolManagerImpl.java | 14 +++----- .../api/rewriters/CommandRewriter.java | 5 ++- .../api/rewriters/MetadataRewriter.java | 5 ++- .../api/rewriters/RegistryType.java | 5 ++- .../api/rewriters/StatisticsRewriter.java | 8 ++--- .../ViaVersion/api/rewriters/TagRewriter.java | 8 ++--- .../ViaVersion/api/storage/EntityTracker.java | 5 ++- .../commands/defaultsubs/PPSSubCmd.java | 6 +++- .../ChannelHandlerContextWrapper.java | 8 ++++- .../packets/InventoryPackets.java | 3 +- .../packets/InventoryPackets.java | 3 +- .../packets/InventoryPackets.java | 4 +-- .../packets/InventoryPackets.java | 2 +- .../Protocol1_13To1_12_2.java | 2 +- .../data/MappingData.java | 2 +- .../blockentities/BannerHandler.java | 9 +++-- .../data/CommandRewriter1_14.java | 5 ++- .../packets/InventoryPackets.java | 6 +++- .../data/MappingData.java | 2 +- .../packets/EntityPackets.java | 2 +- .../Protocol1_17To1_16_4.java | 5 ++- .../storage/BiomeStorage.java | 8 ++--- .../packets/EntityPackets.java | 2 +- .../types/Chunk1_9to1_8Type.java | 2 +- .../myles/ViaVersion/update/UpdateUtil.java | 8 ++--- .../myles/ViaVersion/util/CommentStore.java | 6 +++- .../java/us/myles/ViaVersion/util/Config.java | 14 ++++---- .../sponge/commands/SpongeCommandHandler.java | 2 +- 62 files changed, 219 insertions(+), 224 deletions(-) diff --git a/api/build.gradle.kts b/api/build.gradle.kts index 8265d0532..8c7b6857c 100644 --- a/api/build.gradle.kts +++ b/api/build.gradle.kts @@ -16,5 +16,5 @@ dependencies { compileOnlyApi("org.yaml", "snakeyaml", Versions.snakeYaml) compileOnlyApi("io.netty", "netty-all", Versions.netty) compileOnlyApi("com.google.guava", "guava", Versions.guava) - compileOnlyApi("org.jetbrains", "annotations", Versions.jetbrainsAnnotations) + compileOnlyApi("org.checkerframework", "checker-qual", Versions.checkerQual) } diff --git a/api/src/main/java/us/myles/ViaVersion/api/Pair.java b/api/src/main/java/us/myles/ViaVersion/api/Pair.java index 69fa61efe..eb502791b 100644 --- a/api/src/main/java/us/myles/ViaVersion/api/Pair.java +++ b/api/src/main/java/us/myles/ViaVersion/api/Pair.java @@ -22,7 +22,7 @@ */ package us.myles.ViaVersion.api; -import org.jetbrains.annotations.Nullable; +import org.checkerframework.checker.nullness.qual.Nullable; import java.util.Objects; diff --git a/api/src/main/java/us/myles/ViaVersion/api/Triple.java b/api/src/main/java/us/myles/ViaVersion/api/Triple.java index ccb43ada6..d2013bc23 100644 --- a/api/src/main/java/us/myles/ViaVersion/api/Triple.java +++ b/api/src/main/java/us/myles/ViaVersion/api/Triple.java @@ -22,7 +22,7 @@ */ package us.myles.ViaVersion.api; -import org.jetbrains.annotations.Nullable; +import org.checkerframework.checker.nullness.qual.Nullable; import java.util.Objects; @@ -37,18 +37,15 @@ public class Triple { this.third = third; } - @Nullable - public A getFirst() { + public @Nullable A getFirst() { return first; } - @Nullable - public B getSecond() { + public @Nullable B getSecond() { return second; } - @Nullable - public C getThird() { + public @Nullable C getThird() { return third; } diff --git a/api/src/main/java/us/myles/ViaVersion/api/command/ViaVersionCommand.java b/api/src/main/java/us/myles/ViaVersion/api/command/ViaVersionCommand.java index 7961708a4..23a9c8cf2 100644 --- a/api/src/main/java/us/myles/ViaVersion/api/command/ViaVersionCommand.java +++ b/api/src/main/java/us/myles/ViaVersion/api/command/ViaVersionCommand.java @@ -22,7 +22,7 @@ */ package us.myles.ViaVersion.api.command; -import org.jetbrains.annotations.Nullable; +import org.checkerframework.checker.nullness.qual.Nullable; import java.util.List; @@ -49,8 +49,7 @@ public interface ViaVersionCommand { * @param name subcommand name * @return ViaSubCommand instance */ - @Nullable - ViaSubCommand getSubCommand(String name); + @Nullable ViaSubCommand getSubCommand(String name); /** * Executed when the Command sender executes the commands diff --git a/api/src/main/java/us/myles/ViaVersion/api/data/MappingData.java b/api/src/main/java/us/myles/ViaVersion/api/data/MappingData.java index 1967a6a5a..2006ad5cc 100644 --- a/api/src/main/java/us/myles/ViaVersion/api/data/MappingData.java +++ b/api/src/main/java/us/myles/ViaVersion/api/data/MappingData.java @@ -23,7 +23,7 @@ package us.myles.ViaVersion.api.data; import com.google.gson.JsonObject; -import org.jetbrains.annotations.Nullable; +import org.checkerframework.checker.nullness.qual.Nullable; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.util.Int2IntBiMap; @@ -97,46 +97,38 @@ public class MappingData { return checkValidity(id, particleMappings.getMappings().getNewId(id), "particles"); } - @Nullable - public Int2IntBiMap getItemMappings() { + public @Nullable Int2IntBiMap getItemMappings() { return itemMappings; } - @Nullable - public ParticleMappings getParticleMappings() { + public @Nullable ParticleMappings getParticleMappings() { return particleMappings; } - @Nullable - public Mappings getBlockMappings() { + public @Nullable Mappings getBlockMappings() { return blockMappings; } - @Nullable - public Mappings getBlockStateMappings() { + public @Nullable Mappings getBlockStateMappings() { return blockStateMappings; } - @Nullable - public Mappings getSoundMappings() { + public @Nullable Mappings getSoundMappings() { return soundMappings; } - @Nullable - public Mappings getStatisticsMappings() { + public @Nullable Mappings getStatisticsMappings() { return statisticsMappings; } - @Nullable - protected Mappings loadFromArray(JsonObject oldMappings, JsonObject newMappings, @Nullable JsonObject diffMappings, String key) { + protected @Nullable Mappings loadFromArray(JsonObject oldMappings, JsonObject newMappings, @Nullable JsonObject diffMappings, String key) { if (!oldMappings.has(key) || !newMappings.has(key)) return null; JsonObject diff = diffMappings != null ? diffMappings.getAsJsonObject(key) : null; return new Mappings(oldMappings.getAsJsonArray(key), newMappings.getAsJsonArray(key), diff); } - @Nullable - protected Mappings loadFromObject(JsonObject oldMappings, JsonObject newMappings, @Nullable JsonObject diffMappings, String key) { + protected @Nullable Mappings loadFromObject(JsonObject oldMappings, JsonObject newMappings, @Nullable JsonObject diffMappings, String key) { if (!oldMappings.has(key) || !newMappings.has(key)) return null; JsonObject diff = diffMappings != null ? diffMappings.getAsJsonObject(key) : null; diff --git a/api/src/main/java/us/myles/ViaVersion/api/data/MappingDataLoader.java b/api/src/main/java/us/myles/ViaVersion/api/data/MappingDataLoader.java index b09e7c484..bdfc4e3af 100644 --- a/api/src/main/java/us/myles/ViaVersion/api/data/MappingDataLoader.java +++ b/api/src/main/java/us/myles/ViaVersion/api/data/MappingDataLoader.java @@ -29,7 +29,7 @@ import com.google.gson.JsonObject; import com.google.gson.JsonSyntaxException; import it.unimi.dsi.fastutil.objects.Object2IntMap; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; -import org.jetbrains.annotations.Nullable; +import org.checkerframework.checker.nullness.qual.Nullable; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.util.GsonUtil; import us.myles.ViaVersion.util.Int2IntBiMap; @@ -73,8 +73,7 @@ public class MappingDataLoader { /** * Loads the file from the plugin folder if present, else from the bundled resources. */ - @Nullable - public static JsonObject loadFromDataDir(String name) { + public static @Nullable JsonObject loadFromDataDir(String name) { File file = new File(Via.getPlatform().getDataFolder(), name); if (!file.exists()) return loadData(name); @@ -94,8 +93,7 @@ public class MappingDataLoader { /** * Loads the file from the bundled resources. Uses the cache if enabled. */ - @Nullable - public static JsonObject loadData(String name) { + public static @Nullable JsonObject loadData(String name) { return loadData(name, false); } @@ -104,8 +102,7 @@ public class MappingDataLoader { * * @param cacheIfEnabled whether loaded files should be cached */ - @Nullable - public static JsonObject loadData(String name, boolean cacheIfEnabled) { + public static @Nullable JsonObject loadData(String name, boolean cacheIfEnabled) { if (cacheJsonMappings) { JsonObject cached = MAPPINGS_CACHE.get(name); if (cached != null) { @@ -233,8 +230,7 @@ public class MappingDataLoader { return map; } - @Nullable - public static InputStream getResource(String name) { + public static @Nullable InputStream getResource(String name) { return MappingDataLoader.class.getClassLoader().getResourceAsStream("assets/viaversion/data/" + name); } } diff --git a/api/src/main/java/us/myles/ViaVersion/api/data/Mappings.java b/api/src/main/java/us/myles/ViaVersion/api/data/Mappings.java index fb798502d..fbe402d1c 100644 --- a/api/src/main/java/us/myles/ViaVersion/api/data/Mappings.java +++ b/api/src/main/java/us/myles/ViaVersion/api/data/Mappings.java @@ -24,7 +24,7 @@ package us.myles.ViaVersion.api.data; import com.google.gson.JsonArray; import com.google.gson.JsonObject; -import org.jetbrains.annotations.Nullable; +import org.checkerframework.checker.nullness.qual.Nullable; import java.util.Arrays; diff --git a/api/src/main/java/us/myles/ViaVersion/api/data/UserConnection.java b/api/src/main/java/us/myles/ViaVersion/api/data/UserConnection.java index b3c1adee7..8606850ea 100644 --- a/api/src/main/java/us/myles/ViaVersion/api/data/UserConnection.java +++ b/api/src/main/java/us/myles/ViaVersion/api/data/UserConnection.java @@ -27,7 +27,7 @@ import io.netty.buffer.ByteBuf; import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelHandlerContext; -import org.jetbrains.annotations.Nullable; +import org.checkerframework.checker.nullness.qual.Nullable; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.ViaVersionConfig; @@ -96,8 +96,7 @@ public class UserConnection { * @param The type of the class you want to get. * @return The requested object */ - @Nullable - public T get(Class objectClass) { + public @Nullable T get(Class objectClass) { return (T) storedObjects.get(objectClass); } @@ -453,13 +452,11 @@ public class UserConnection { return id; } - @Nullable - public Channel getChannel() { + public @Nullable Channel getChannel() { return channel; } - @Nullable - public ProtocolInfo getProtocolInfo() { + public @Nullable ProtocolInfo getProtocolInfo() { return protocolInfo; } @@ -492,8 +489,7 @@ public class UserConnection { this.pendingDisconnect = pendingDisconnect; } - @Nullable - public Object getLastPacket() { + public @Nullable Object getLastPacket() { return lastPacket; } diff --git a/api/src/main/java/us/myles/ViaVersion/api/entities/EntityType.java b/api/src/main/java/us/myles/ViaVersion/api/entities/EntityType.java index 248cbe68c..17c77c4e2 100644 --- a/api/src/main/java/us/myles/ViaVersion/api/entities/EntityType.java +++ b/api/src/main/java/us/myles/ViaVersion/api/entities/EntityType.java @@ -22,7 +22,7 @@ */ package us.myles.ViaVersion.api.entities; -import org.jetbrains.annotations.Nullable; +import org.checkerframework.checker.nullness.qual.Nullable; public interface EntityType { @@ -34,16 +34,16 @@ public interface EntityType { /** * @return parent entity type if present */ - @Nullable - EntityType getParent(); + @Nullable EntityType getParent(); String name(); default boolean is(EntityType... types) { - for (EntityType type : types) + for (EntityType type : types) { if (this == type) { return true; } + } return false; } diff --git a/api/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/BaseChunk.java b/api/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/BaseChunk.java index 85d410e13..5663f1a8b 100644 --- a/api/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/BaseChunk.java +++ b/api/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/BaseChunk.java @@ -23,7 +23,7 @@ package us.myles.ViaVersion.api.minecraft.chunks; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; -import org.jetbrains.annotations.Nullable; +import org.checkerframework.checker.nullness.qual.Nullable; import java.util.BitSet; import java.util.List; @@ -42,7 +42,7 @@ public class BaseChunk implements Chunk { protected final List blockEntities; public BaseChunk(int x, int z, boolean fullChunk, boolean ignoreOldLightData, @Nullable BitSet chunkSectionBitSet, - ChunkSection[] sections, @Nullable int[] biomeData, @Nullable CompoundTag heightMap, List blockEntities) { + ChunkSection[] sections, int @Nullable [] biomeData, @Nullable CompoundTag heightMap, List blockEntities) { this.x = x; this.z = z; this.fullChunk = fullChunk; @@ -104,8 +104,7 @@ public class BaseChunk implements Chunk { } @Override - @Nullable - public BitSet getChunkMask() { + public @Nullable BitSet getChunkMask() { return chunkSectionBitSet; } @@ -125,13 +124,12 @@ public class BaseChunk implements Chunk { } @Override - @Nullable - public int[] getBiomeData() { + public int @Nullable [] getBiomeData() { return biomeData; } @Override - public void setBiomeData(final int[] biomeData) { + public void setBiomeData(int @Nullable [] biomeData) { this.biomeData = biomeData; } diff --git a/api/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/Chunk.java b/api/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/Chunk.java index 14cec0f35..dd9a55d20 100644 --- a/api/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/Chunk.java +++ b/api/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/Chunk.java @@ -23,7 +23,7 @@ package us.myles.ViaVersion.api.minecraft.chunks; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; -import org.jetbrains.annotations.Nullable; +import org.checkerframework.checker.nullness.qual.Nullable; import java.util.BitSet; import java.util.List; @@ -65,8 +65,7 @@ public interface Chunk { * @return chunk section bit mask, only non-null available for 1.17+ chunks * @see #getBitmask() */ - @Nullable - BitSet getChunkMask(); + @Nullable BitSet getChunkMask(); void setChunkMask(BitSet chunkSectionMask); @@ -74,10 +73,9 @@ public interface Chunk { void setSections(ChunkSection[] sections); - @Nullable - int[] getBiomeData(); + int @Nullable [] getBiomeData(); - void setBiomeData(int[] biomeData); + void setBiomeData(int @Nullable [] biomeData); CompoundTag getHeightMap(); diff --git a/api/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/ChunkSection.java b/api/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/ChunkSection.java index d3f55d818..10c697fb2 100644 --- a/api/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/ChunkSection.java +++ b/api/src/main/java/us/myles/ViaVersion/api/minecraft/chunks/ChunkSection.java @@ -27,7 +27,7 @@ import it.unimi.dsi.fastutil.ints.Int2IntMap; import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntList; -import org.jetbrains.annotations.Nullable; +import org.checkerframework.checker.nullness.qual.Nullable; public class ChunkSection { @@ -207,23 +207,19 @@ public class ChunkSection { } } - @Nullable - public byte[] getBlockLight() { + public @Nullable byte[] getBlockLight() { return blockLight == null ? null : blockLight.getHandle(); } - @Nullable - public NibbleArray getBlockLightNibbleArray() { + public @Nullable NibbleArray getBlockLightNibbleArray() { return blockLight; } - @Nullable - public byte[] getSkyLight() { + public @Nullable byte[] getSkyLight() { return skyLight == null ? null : skyLight.getHandle(); } - @Nullable - public NibbleArray getSkyLightNibbleArray() { + public @Nullable NibbleArray getSkyLightNibbleArray() { return skyLight; } diff --git a/api/src/main/java/us/myles/ViaVersion/api/minecraft/item/Item.java b/api/src/main/java/us/myles/ViaVersion/api/minecraft/item/Item.java index c21b2ab43..be2c5ca5a 100644 --- a/api/src/main/java/us/myles/ViaVersion/api/minecraft/item/Item.java +++ b/api/src/main/java/us/myles/ViaVersion/api/minecraft/item/Item.java @@ -24,7 +24,7 @@ package us.myles.ViaVersion.api.minecraft.item; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.google.gson.annotations.SerializedName; -import org.jetbrains.annotations.Nullable; +import org.checkerframework.checker.nullness.qual.Nullable; import java.util.Objects; @@ -73,8 +73,7 @@ public class Item { this.data = data; } - @Nullable - public CompoundTag getTag() { + public @Nullable CompoundTag getTag() { return tag; } diff --git a/api/src/main/java/us/myles/ViaVersion/api/minecraft/nbt/BinaryTagIO.java b/api/src/main/java/us/myles/ViaVersion/api/minecraft/nbt/BinaryTagIO.java index 129ae556b..53652353a 100644 --- a/api/src/main/java/us/myles/ViaVersion/api/minecraft/nbt/BinaryTagIO.java +++ b/api/src/main/java/us/myles/ViaVersion/api/minecraft/nbt/BinaryTagIO.java @@ -24,7 +24,7 @@ package us.myles.ViaVersion.api.minecraft.nbt; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; -import org.jetbrains.annotations.NotNull; +import org.checkerframework.checker.nullness.qual.NonNull; import java.io.BufferedInputStream; import java.io.DataInput; @@ -53,8 +53,7 @@ public final class BinaryTagIO { * @return the compound tag * @throws IOException if an exception was encountered while reading a compound tag */ - @NotNull - public static CompoundTag readPath(final @NotNull Path path) throws IOException { + public static @NonNull CompoundTag readPath(final @NonNull Path path) throws IOException { return readInputStream(Files.newInputStream(path)); } @@ -65,8 +64,7 @@ public final class BinaryTagIO { * @return the compound tag * @throws IOException if an exception was encountered while reading a compound tag */ - @NotNull - public static CompoundTag readInputStream(final @NotNull InputStream input) throws IOException { + public static @NonNull CompoundTag readInputStream(final @NonNull InputStream input) throws IOException { try (final DataInputStream dis = new DataInputStream(input)) { return readDataInput(dis); } @@ -79,8 +77,7 @@ public final class BinaryTagIO { * @return the compound tag * @throws IOException if an exception was encountered while reading a compound tag */ - @NotNull - public static CompoundTag readCompressedPath(final @NotNull Path path) throws IOException { + public static @NonNull CompoundTag readCompressedPath(final @NonNull Path path) throws IOException { return readCompressedInputStream(Files.newInputStream(path)); } @@ -91,8 +88,7 @@ public final class BinaryTagIO { * @return the compound tag * @throws IOException if an exception was encountered while reading a compound tag */ - @NotNull - public static CompoundTag readCompressedInputStream(final @NotNull InputStream input) throws IOException { + public static @NonNull CompoundTag readCompressedInputStream(final @NonNull InputStream input) throws IOException { try (final DataInputStream dis = new DataInputStream(new BufferedInputStream(new GZIPInputStream(input)))) { return readDataInput(dis); } @@ -105,8 +101,7 @@ public final class BinaryTagIO { * @return the compound tag * @throws IOException if an exception was encountered while reading a compound tag */ - @NotNull - public static CompoundTag readDataInput(final @NotNull DataInput input) throws IOException { + public static @NonNull CompoundTag readDataInput(final @NonNull DataInput input) throws IOException { byte type = input.readByte(); if (type != CompoundTag.ID) { throw new IOException(String.format("Expected root tag to be a CompoundTag, was %s", type)); @@ -125,7 +120,7 @@ public final class BinaryTagIO { * @param path the path * @throws IOException if an exception was encountered while writing the compound tag */ - public static void writePath(final @NotNull CompoundTag tag, final @NotNull Path path) throws IOException { + public static void writePath(final @NonNull CompoundTag tag, final @NonNull Path path) throws IOException { writeOutputStream(tag, Files.newOutputStream(path)); } @@ -136,7 +131,7 @@ public final class BinaryTagIO { * @param output the output stream * @throws IOException if an exception was encountered while writing the compound tag */ - public static void writeOutputStream(final @NotNull CompoundTag tag, final @NotNull OutputStream output) throws IOException { + public static void writeOutputStream(final @NonNull CompoundTag tag, final @NonNull OutputStream output) throws IOException { try (final DataOutputStream dos = new DataOutputStream(output)) { writeDataOutput(tag, dos); } @@ -149,7 +144,7 @@ public final class BinaryTagIO { * @param path the path * @throws IOException if an exception was encountered while writing the compound tag */ - public static void writeCompressedPath(final @NotNull CompoundTag tag, final @NotNull Path path) throws IOException { + public static void writeCompressedPath(final @NonNull CompoundTag tag, final @NonNull Path path) throws IOException { writeCompressedOutputStream(tag, Files.newOutputStream(path)); } @@ -160,7 +155,7 @@ public final class BinaryTagIO { * @param output the output stream * @throws IOException if an exception was encountered while writing the compound tag */ - public static void writeCompressedOutputStream(final @NotNull CompoundTag tag, final @NotNull OutputStream output) throws IOException { + public static void writeCompressedOutputStream(final @NonNull CompoundTag tag, final @NonNull OutputStream output) throws IOException { try (final DataOutputStream dos = new DataOutputStream(new GZIPOutputStream(output))) { writeDataOutput(tag, dos); } @@ -173,7 +168,7 @@ public final class BinaryTagIO { * @param output the output * @throws IOException if an exception was encountered while writing the compound tag */ - public static void writeDataOutput(final @NotNull CompoundTag tag, final @NotNull DataOutput output) throws IOException { + public static void writeDataOutput(final @NonNull CompoundTag tag, final @NonNull DataOutput output) throws IOException { output.writeByte(CompoundTag.ID); output.writeUTF(""); // write empty name tag.write(output); @@ -186,8 +181,7 @@ public final class BinaryTagIO { * @return the compound tag * @throws IOException if an exception was encountered while reading a compound tag */ - @NotNull - public static CompoundTag readString(final @NotNull String input) throws IOException { + public static @NonNull CompoundTag readString(final @NonNull String input) throws IOException { try { final CharBuffer buffer = new CharBuffer(input); final TagStringReader parser = new TagStringReader(buffer); @@ -208,8 +202,7 @@ public final class BinaryTagIO { * @return the string * @throws IOException if an exception was encountered while writing the compound tag */ - @NotNull - public static String writeString(final @NotNull CompoundTag tag) throws IOException { + public static @NonNull String writeString(final @NonNull CompoundTag tag) throws IOException { final StringBuilder sb = new StringBuilder(); try (final TagStringWriter emit = new TagStringWriter(sb)) { emit.writeTag(tag); diff --git a/api/src/main/java/us/myles/ViaVersion/api/platform/ViaConnectionManager.java b/api/src/main/java/us/myles/ViaVersion/api/platform/ViaConnectionManager.java index d36f6004e..2712493f0 100644 --- a/api/src/main/java/us/myles/ViaVersion/api/platform/ViaConnectionManager.java +++ b/api/src/main/java/us/myles/ViaVersion/api/platform/ViaConnectionManager.java @@ -23,11 +23,15 @@ package us.myles.ViaVersion.api.platform; import io.netty.channel.ChannelFutureListener; -import org.jetbrains.annotations.Nullable; +import org.checkerframework.checker.nullness.qual.Nullable; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.data.UserConnection; -import java.util.*; +import java.util.Collections; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; /** @@ -44,7 +48,7 @@ public class ViaConnectionManager { if (isFrontEnd(connection)) { UUID id = connection.getProtocolInfo().getUuid(); if (clients.put(id, connection) != null) { - Via.getPlatform().getLogger().warning("Duplicate UUID on frontend connection! ("+id+")"); + Via.getPlatform().getLogger().warning("Duplicate UUID on frontend connection! (" + id + ")"); } } @@ -90,8 +94,7 @@ public class ViaConnectionManager { * Note that connections are removed as soon as their channel is closed, * so avoid using this method during player quits for example. */ - @Nullable - public UserConnection getConnectedClient(UUID clientIdentifier) { + public @Nullable UserConnection getConnectedClient(UUID clientIdentifier) { return clients.get(clientIdentifier); } @@ -104,8 +107,7 @@ public class ViaConnectionManager { * Note that connections are removed as soon as their channel is closed, * so avoid using this method during player quits for example. */ - @Nullable - public UUID getConnectedClientId(UserConnection conn) { + public @Nullable UUID getConnectedClientId(UserConnection conn) { if (conn.getProtocolInfo() == null) return null; UUID uuid = conn.getProtocolInfo().getUuid(); UserConnection client = clients.get(uuid); diff --git a/api/src/main/java/us/myles/ViaVersion/api/platform/providers/ViaProviders.java b/api/src/main/java/us/myles/ViaVersion/api/platform/providers/ViaProviders.java index 8407425bb..42d5738dc 100644 --- a/api/src/main/java/us/myles/ViaVersion/api/platform/providers/ViaProviders.java +++ b/api/src/main/java/us/myles/ViaVersion/api/platform/providers/ViaProviders.java @@ -22,7 +22,7 @@ */ package us.myles.ViaVersion.api.platform.providers; -import org.jetbrains.annotations.Nullable; +import org.checkerframework.checker.nullness.qual.Nullable; import java.util.ArrayList; import java.util.HashMap; @@ -46,8 +46,7 @@ public class ViaProviders { providers.put(provider, value); } - @Nullable - public T get(Class provider) { + public @Nullable T get(Class provider) { Provider rawProvider = providers.get(provider); if (rawProvider != null) { return (T) rawProvider; diff --git a/api/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java b/api/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java index 77f69a8c9..31b9ec7c9 100644 --- a/api/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java +++ b/api/src/main/java/us/myles/ViaVersion/api/protocol/Protocol.java @@ -23,7 +23,7 @@ package us.myles.ViaVersion.api.protocol; import com.google.common.base.Preconditions; -import org.jetbrains.annotations.Nullable; +import org.checkerframework.checker.nullness.qual.Nullable; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.data.MappingData; @@ -472,8 +472,7 @@ public abstract class Protocol T get(Class objectClass) { + public @Nullable T get(Class objectClass) { return (T) storedObjects.get(objectClass); } @@ -493,8 +492,7 @@ public abstract class Protocol protocolClass); + @Nullable Protocol getProtocol(Class protocolClass); Protocol getBaseProtocol(); @@ -87,8 +86,7 @@ public interface ProtocolManager { * @param serverVersion desired output server version * @return path it generated, null if not supported */ - @Nullable - List getProtocolPath(int clientVersion, int serverVersion); + @Nullable List getProtocolPath(int clientVersion, int serverVersion); /** * Returns the maximum protocol path size applied to {@link #getProtocolPath(int, int)}. @@ -159,6 +157,5 @@ public interface ProtocolManager { * @param protocolClass protocol class * @return data loading future bound to the protocol, or null if all loading is complete */ - @Nullable - CompletableFuture getMappingLoaderFuture(Class protocolClass); + @Nullable CompletableFuture getMappingLoaderFuture(Class protocolClass); } diff --git a/api/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java b/api/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java index b4dc3e5ad..3e73ed185 100644 --- a/api/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java +++ b/api/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolRegistry.java @@ -23,7 +23,7 @@ package us.myles.ViaVersion.api.protocol; import com.google.common.collect.Range; -import org.jetbrains.annotations.Nullable; +import org.checkerframework.checker.nullness.qual.Nullable; import us.myles.ViaVersion.ViaManager; import us.myles.ViaVersion.api.Pair; import us.myles.ViaVersion.api.Via; @@ -103,8 +103,7 @@ public class ProtocolRegistry { * @param serverVersion The desired output server version * @return The path it generated, null if it failed. */ - @Nullable - public static List> getProtocolPath(int clientVersion, int serverVersion) { + public static @Nullable List> getProtocolPath(int clientVersion, int serverVersion) { List pathList = Via.getManager().getProtocolManager().getProtocolPath(clientVersion, serverVersion); if (pathList == null) { return null; @@ -123,8 +122,7 @@ public class ProtocolRegistry { * @param protocolClass class of the protocol * @return protocol if present */ - @Nullable - public static Protocol getProtocol(Class protocolClass) { + public static @Nullable Protocol getProtocol(Class protocolClass) { return Via.getManager().getProtocolManager().getProtocol(protocolClass); } diff --git a/api/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java b/api/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java index 759419223..ce2aafd97 100644 --- a/api/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java +++ b/api/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolVersion.java @@ -25,8 +25,8 @@ package us.myles.ViaVersion.api.protocol; import com.google.common.base.Preconditions; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; import java.util.ArrayList; import java.util.Collections; @@ -105,8 +105,7 @@ public class ProtocolVersion { return versions.containsKey(id); } - @NotNull - public static ProtocolVersion getProtocol(int id) { + public static @NonNull ProtocolVersion getProtocol(int id) { ProtocolVersion protocolVersion = versions.get(id); if (protocolVersion != null) { return protocolVersion; @@ -123,8 +122,7 @@ public class ProtocolVersion { return Collections.unmodifiableList(new ArrayList<>(versions.values())); } - @Nullable - public static ProtocolVersion getClosest(String protocol) { + public static @Nullable ProtocolVersion getClosest(String protocol) { for (ProtocolVersion version : versions.values()) { String name = version.getName(); if (name.equals(protocol)) { @@ -211,6 +209,10 @@ public class ProtocolVersion { return snapshotVersion == -1 ? version : ((1 << 30) | snapshotVersion); } + public boolean isKnown() { + return version != -1; + } + /** * @return true if the protocol includes a range of versions (but not an entire major version range), for example 1.7-1.7.5 * @see #getIncludedVersions() diff --git a/api/src/main/java/us/myles/ViaVersion/api/protocol/ServerProtocolVersion.java b/api/src/main/java/us/myles/ViaVersion/api/protocol/ServerProtocolVersion.java index 3026ea80b..654916d18 100644 --- a/api/src/main/java/us/myles/ViaVersion/api/protocol/ServerProtocolVersion.java +++ b/api/src/main/java/us/myles/ViaVersion/api/protocol/ServerProtocolVersion.java @@ -49,7 +49,7 @@ public interface ServerProtocolVersion { * Returns true if the actual protocol version has not yet been identified. * In that case, all methods above will returns -1. * - * @return true if unset + * @return true if set, false if unknown (yet) */ default boolean isKnown() { return lowestSupportedVersion() != -1 && highestSupportedVersion() != -1; diff --git a/api/src/main/java/us/myles/ViaVersion/api/remapper/ValueTransformer.java b/api/src/main/java/us/myles/ViaVersion/api/remapper/ValueTransformer.java index 6eb59edfb..4089c57ed 100644 --- a/api/src/main/java/us/myles/ViaVersion/api/remapper/ValueTransformer.java +++ b/api/src/main/java/us/myles/ViaVersion/api/remapper/ValueTransformer.java @@ -22,7 +22,7 @@ */ package us.myles.ViaVersion.api.remapper; -import org.jetbrains.annotations.Nullable; +import org.checkerframework.checker.nullness.qual.Nullable; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.exception.InformativeException; @@ -60,8 +60,7 @@ public abstract class ValueTransformer implements ValueWriter { } } - @Nullable - public Type getInputType() { + public @Nullable Type getInputType() { return inputType; } diff --git a/api/src/main/java/us/myles/ViaVersion/api/type/Type.java b/api/src/main/java/us/myles/ViaVersion/api/type/Type.java index 96c4e0dcf..24e51235b 100644 --- a/api/src/main/java/us/myles/ViaVersion/api/type/Type.java +++ b/api/src/main/java/us/myles/ViaVersion/api/type/Type.java @@ -31,7 +31,28 @@ import us.myles.ViaVersion.api.minecraft.Position; import us.myles.ViaVersion.api.minecraft.Vector; import us.myles.ViaVersion.api.minecraft.VillagerData; import us.myles.ViaVersion.api.minecraft.item.Item; -import us.myles.ViaVersion.api.type.types.*; +import us.myles.ViaVersion.api.type.types.ArrayType; +import us.myles.ViaVersion.api.type.types.BooleanType; +import us.myles.ViaVersion.api.type.types.ByteArrayType; +import us.myles.ViaVersion.api.type.types.ByteType; +import us.myles.ViaVersion.api.type.types.ComponentType; +import us.myles.ViaVersion.api.type.types.DoubleType; +import us.myles.ViaVersion.api.type.types.FloatType; +import us.myles.ViaVersion.api.type.types.IntType; +import us.myles.ViaVersion.api.type.types.LongArrayType; +import us.myles.ViaVersion.api.type.types.LongType; +import us.myles.ViaVersion.api.type.types.RemainingBytesType; +import us.myles.ViaVersion.api.type.types.ShortByteArrayType; +import us.myles.ViaVersion.api.type.types.ShortType; +import us.myles.ViaVersion.api.type.types.StringType; +import us.myles.ViaVersion.api.type.types.UUIDIntArrayType; +import us.myles.ViaVersion.api.type.types.UUIDType; +import us.myles.ViaVersion.api.type.types.UnsignedByteType; +import us.myles.ViaVersion.api.type.types.UnsignedShortType; +import us.myles.ViaVersion.api.type.types.VarIntArrayType; +import us.myles.ViaVersion.api.type.types.VarIntType; +import us.myles.ViaVersion.api.type.types.VarLongType; +import us.myles.ViaVersion.api.type.types.VoidType; import us.myles.ViaVersion.api.type.types.minecraft.BlockChangeRecordType; import us.myles.ViaVersion.api.type.types.minecraft.EulerAngleType; import us.myles.ViaVersion.api.type.types.minecraft.FlatItemArrayType; diff --git a/api/src/main/java/us/myles/ViaVersion/api/type/types/StringType.java b/api/src/main/java/us/myles/ViaVersion/api/type/types/StringType.java index 12df774ef..bde85d522 100644 --- a/api/src/main/java/us/myles/ViaVersion/api/type/types/StringType.java +++ b/api/src/main/java/us/myles/ViaVersion/api/type/types/StringType.java @@ -48,7 +48,7 @@ public class StringType extends Type { int len = Type.VAR_INT.readPrimitive(buffer); Preconditions.checkArgument(len <= maxLength * maxJavaCharUtf8Length, - "Cannot receive string longer than Short.MAX_VALUE * " + maxJavaCharUtf8Length + " bytes (got %s bytes)", len); + "Cannot receive string longer than Short.MAX_VALUE * " + maxJavaCharUtf8Length + " bytes (got %s bytes)", len); String string = buffer.toString(buffer.readerIndex(), len, StandardCharsets.UTF_8); buffer.skipBytes(len); diff --git a/api/src/main/java/us/myles/ViaVersion/util/CompactArrayUtil.java b/api/src/main/java/us/myles/ViaVersion/util/CompactArrayUtil.java index aaf542ef3..5dbc2ab20 100644 --- a/api/src/main/java/us/myles/ViaVersion/util/CompactArrayUtil.java +++ b/api/src/main/java/us/myles/ViaVersion/util/CompactArrayUtil.java @@ -46,7 +46,7 @@ public class CompactArrayUtil { 79536431, 0, 78090314, 78090314, 0, 76695844, 76695844, 0, 75350303, 75350303, 0, 74051160, 74051160, 0, 72796055, 72796055, 0, 71582788, 71582788, 0, 70409299, 70409299, 0, 69273666, 69273666, 0, 68174084, 68174084, 0, Integer.MIN_VALUE, - 0, 5 }; + 0, 5}; private CompactArrayUtil() { throw new AssertionError(); @@ -72,6 +72,7 @@ public class CompactArrayUtil { return data; } + public static void iterateCompactArrayWithPadding(int bitsPerEntry, int entries, long[] data, BiIntConsumer consumer) { long maxEntryValue = (1L << bitsPerEntry) - 1; char valuesPerLong = (char) (64 / bitsPerEntry); diff --git a/api/src/main/java/us/myles/ViaVersion/util/Int2IntBiMap.java b/api/src/main/java/us/myles/ViaVersion/util/Int2IntBiMap.java index 61fdb0834..1432525f6 100644 --- a/api/src/main/java/us/myles/ViaVersion/util/Int2IntBiMap.java +++ b/api/src/main/java/us/myles/ViaVersion/util/Int2IntBiMap.java @@ -27,7 +27,7 @@ import it.unimi.dsi.fastutil.ints.Int2IntMap; import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; import it.unimi.dsi.fastutil.ints.IntSet; import it.unimi.dsi.fastutil.objects.ObjectSet; -import org.jetbrains.annotations.NotNull; +import org.checkerframework.checker.nullness.qual.NonNull; import java.util.Map; @@ -106,7 +106,7 @@ public class Int2IntBiMap implements Int2IntMap { @Override @Deprecated - public void putAll(@NotNull Map m) { + public void putAll(@NonNull Map m) { throw new UnsupportedOperationException(); } @@ -127,14 +127,12 @@ public class Int2IntBiMap implements Int2IntMap { } @Override - @NotNull - public IntSet keySet() { + public @NonNull IntSet keySet() { return map.keySet(); } @Override - @NotNull - public IntSet values() { + public @NonNull IntSet values() { return inverse.map.keySet(); } diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index 1a0a2d648..b8a26c6a5 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -11,8 +11,8 @@ object Versions { const val guava = "17.0" const val snakeYaml = "1.18" - const val jetbrainsAnnotations = "20.1.0" const val jUnit = "5.6.3" + const val checkerQual = "3.12.0" // Platforms const val spigot = "1.16.5-R0.1-SNAPSHOT" diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/handlers/BukkitEncodeHandler.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/handlers/BukkitEncodeHandler.java index cee0aa6dc..c840055f2 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/handlers/BukkitEncodeHandler.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/handlers/BukkitEncodeHandler.java @@ -71,7 +71,7 @@ public class BukkitEncodeHandler extends MessageToByteEncoder implements ViaHand throw (Error) e.getCause(); } } - + } else { bytebuf.writeBytes((ByteBuf) o); } diff --git a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/listeners/multiversion/PlayerSneakListener.java b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/listeners/multiversion/PlayerSneakListener.java index e97a86fa3..b63fc5dcd 100644 --- a/bukkit/src/main/java/us/myles/ViaVersion/bukkit/listeners/multiversion/PlayerSneakListener.java +++ b/bukkit/src/main/java/us/myles/ViaVersion/bukkit/listeners/multiversion/PlayerSneakListener.java @@ -32,7 +32,11 @@ import us.myles.ViaVersion.protocols.base.ProtocolInfo; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.*; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.UUID; +import java.util.WeakHashMap; public class PlayerSneakListener extends ViaBukkitListener { private static final float STANDING_HEIGHT = 1.8F; diff --git a/bungee/src/main/java/us/myles/ViaVersion/BungeePlugin.java b/bungee/src/main/java/us/myles/ViaVersion/BungeePlugin.java index a169ae132..74db72ea3 100644 --- a/bungee/src/main/java/us/myles/ViaVersion/BungeePlugin.java +++ b/bungee/src/main/java/us/myles/ViaVersion/BungeePlugin.java @@ -43,8 +43,8 @@ import us.myles.ViaVersion.dump.PluginInfo; import us.myles.ViaVersion.util.GsonUtil; import java.util.ArrayList; -import java.util.Collections; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.UUID; import java.util.concurrent.TimeUnit; diff --git a/bungee/src/main/java/us/myles/ViaVersion/bungee/handlers/BungeeDecodeHandler.java b/bungee/src/main/java/us/myles/ViaVersion/bungee/handlers/BungeeDecodeHandler.java index ae6afb9c8..62003d98d 100644 --- a/bungee/src/main/java/us/myles/ViaVersion/bungee/handlers/BungeeDecodeHandler.java +++ b/bungee/src/main/java/us/myles/ViaVersion/bungee/handlers/BungeeDecodeHandler.java @@ -22,8 +22,8 @@ import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.MessageToMessageDecoder; import us.myles.ViaVersion.api.data.UserConnection; -import us.myles.ViaVersion.exception.CancelDecoderException; import us.myles.ViaVersion.exception.CancelCodecException; +import us.myles.ViaVersion.exception.CancelDecoderException; import java.util.List; diff --git a/bungee/src/main/java/us/myles/ViaVersion/bungee/handlers/BungeeEncodeHandler.java b/bungee/src/main/java/us/myles/ViaVersion/bungee/handlers/BungeeEncodeHandler.java index f72d6301d..020cb2d85 100644 --- a/bungee/src/main/java/us/myles/ViaVersion/bungee/handlers/BungeeEncodeHandler.java +++ b/bungee/src/main/java/us/myles/ViaVersion/bungee/handlers/BungeeEncodeHandler.java @@ -23,8 +23,8 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.MessageToMessageEncoder; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.bungee.util.BungeePipelineUtil; -import us.myles.ViaVersion.exception.CancelEncoderException; import us.myles.ViaVersion.exception.CancelCodecException; +import us.myles.ViaVersion.exception.CancelEncoderException; import java.util.List; diff --git a/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaConfig.java b/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaConfig.java index 8ac8e46ae..2e3e8d46e 100644 --- a/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaConfig.java +++ b/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaConfig.java @@ -23,7 +23,11 @@ import us.myles.ViaVersion.bungee.providers.BungeeVersionProvider; import java.io.File; import java.net.URL; -import java.util.*; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; public class BungeeViaConfig extends AbstractViaConfig { private static final List UNSUPPORTED = Arrays.asList("nms-player-ticking", "item-cache", "anti-xray-patch", "quick-move-action-fix", "velocity-ping-interval", "velocity-ping-save", "velocity-servers", "blockconnection-method", "change-1_9-hitbox", "change-1_14-hitbox"); diff --git a/common/src/main/java/us/myles/ViaVersion/api/ViaListener.java b/common/src/main/java/us/myles/ViaVersion/api/ViaListener.java index 713d4b6b2..2772903e3 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/ViaListener.java +++ b/common/src/main/java/us/myles/ViaVersion/api/ViaListener.java @@ -17,7 +17,7 @@ */ package us.myles.ViaVersion.api; -import org.jetbrains.annotations.Nullable; +import org.checkerframework.checker.nullness.qual.Nullable; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.protocol.Protocol; @@ -37,8 +37,7 @@ public abstract class ViaListener { * @param uuid UUID object * @return The UserConnection */ - @Nullable - protected UserConnection getUserConnection(UUID uuid) { + protected @Nullable UserConnection getUserConnection(UUID uuid) { return Via.getManager().getConnectionManager().getConnectedClient(uuid); } diff --git a/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolManagerImpl.java b/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolManagerImpl.java index 52da7f7c2..92da8f748 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolManagerImpl.java +++ b/common/src/main/java/us/myles/ViaVersion/api/protocol/ProtocolManagerImpl.java @@ -23,7 +23,7 @@ import com.google.common.collect.Range; import com.google.common.util.concurrent.ThreadFactoryBuilder; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; -import org.jetbrains.annotations.Nullable; +import org.checkerframework.checker.nullness.qual.Nullable; import us.myles.ViaVersion.api.Pair; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.data.MappingDataLoader; @@ -210,9 +210,8 @@ public class ProtocolManagerImpl implements ProtocolManager { } } - @Nullable @Override - public List getProtocolPath(int clientVersion, int serverVersion) { + public @Nullable List getProtocolPath(int clientVersion, int serverVersion) { ProtocolPathKey protocolKey = new ProtocolPathKeyImpl(clientVersion, serverVersion); // Check cache List protocolList = pathCache.get(protocolKey); @@ -237,8 +236,7 @@ public class ProtocolManagerImpl implements ProtocolManager { * @param serverVersion desired output version * @return path that has been generated, null if failed */ - @Nullable - private List getProtocolPath(List current, int clientVersion, int serverVersion) { + private @Nullable List getProtocolPath(List current, int clientVersion, int serverVersion) { if (clientVersion == serverVersion) return null; // We're already there if (current.size() > maxProtocolPathSize) return null; // Fail safe, protocol too complicated. @@ -282,9 +280,8 @@ public class ProtocolManagerImpl implements ProtocolManager { return shortest; // null if none found } - @Nullable @Override - public Protocol getProtocol(Class protocolClass) { + public @Nullable Protocol getProtocol(Class protocolClass) { return protocols.get(protocolClass); } @@ -406,9 +403,8 @@ public class ProtocolManagerImpl implements ProtocolManager { } } - @Nullable @Override - public CompletableFuture getMappingLoaderFuture(Class protocolClass) { + public @Nullable CompletableFuture getMappingLoaderFuture(Class protocolClass) { mappingLoaderLock.readLock().lock(); try { return mappingsLoaded ? null : mappingLoaderFutures.get(protocolClass); diff --git a/common/src/main/java/us/myles/ViaVersion/api/rewriters/CommandRewriter.java b/common/src/main/java/us/myles/ViaVersion/api/rewriters/CommandRewriter.java index 3d54a6d02..ee373f158 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/rewriters/CommandRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/api/rewriters/CommandRewriter.java @@ -17,7 +17,7 @@ */ package us.myles.ViaVersion.api.rewriters; -import org.jetbrains.annotations.Nullable; +import org.checkerframework.checker.nullness.qual.Nullable; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.protocol.ClientboundPacketType; import us.myles.ViaVersion.api.protocol.Protocol; @@ -122,8 +122,7 @@ public abstract class CommandRewriter { * @param argumentType argument type * @return new argument type, or null if it should be removed */ - @Nullable - protected String handleArgumentType(String argumentType) { + protected @Nullable String handleArgumentType(String argumentType) { return argumentType; } diff --git a/common/src/main/java/us/myles/ViaVersion/api/rewriters/MetadataRewriter.java b/common/src/main/java/us/myles/ViaVersion/api/rewriters/MetadataRewriter.java index ebebae675..d5d4a8702 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/rewriters/MetadataRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/api/rewriters/MetadataRewriter.java @@ -19,7 +19,7 @@ package us.myles.ViaVersion.api.rewriters; import it.unimi.dsi.fastutil.ints.Int2IntMap; import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; -import org.jetbrains.annotations.Nullable; +import org.checkerframework.checker.nullness.qual.Nullable; import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.data.ParticleMappings; import us.myles.ViaVersion.api.data.UserConnection; @@ -296,8 +296,7 @@ public abstract class MetadataRewriter { */ protected abstract void handleMetadata(int entityId, @Nullable EntityType type, Metadata metadata, List metadatas, UserConnection connection) throws Exception; - @Nullable - protected Metadata getMetaByIndex(int index, List metadataList) { + protected @Nullable Metadata getMetaByIndex(int index, List metadataList) { for (Metadata metadata : metadataList) { if (metadata.getId() == index) { return metadata; diff --git a/common/src/main/java/us/myles/ViaVersion/api/rewriters/RegistryType.java b/common/src/main/java/us/myles/ViaVersion/api/rewriters/RegistryType.java index b5db45613..236585f51 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/rewriters/RegistryType.java +++ b/common/src/main/java/us/myles/ViaVersion/api/rewriters/RegistryType.java @@ -17,7 +17,7 @@ */ package us.myles.ViaVersion.api.rewriters; -import org.jetbrains.annotations.Nullable; +import org.checkerframework.checker.nullness.qual.Nullable; import java.util.HashMap; import java.util.Map; @@ -43,8 +43,7 @@ public enum RegistryType { return VALUES; } - @Nullable - public static RegistryType getByKey(String resourceKey) { + public static @Nullable RegistryType getByKey(String resourceKey) { return MAP.get(resourceKey); } diff --git a/common/src/main/java/us/myles/ViaVersion/api/rewriters/StatisticsRewriter.java b/common/src/main/java/us/myles/ViaVersion/api/rewriters/StatisticsRewriter.java index d2190da0e..f2449cf54 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/rewriters/StatisticsRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/api/rewriters/StatisticsRewriter.java @@ -17,7 +17,7 @@ */ package us.myles.ViaVersion.api.rewriters; -import org.jetbrains.annotations.Nullable; +import org.checkerframework.checker.nullness.qual.Nullable; import us.myles.ViaVersion.api.protocol.ClientboundPacketType; import us.myles.ViaVersion.api.protocol.Protocol; import us.myles.ViaVersion.api.remapper.PacketRemapper; @@ -74,8 +74,7 @@ public class StatisticsRewriter { }); } - @Nullable - protected IdRewriteFunction getRewriter(RegistryType type) { + protected @Nullable IdRewriteFunction getRewriter(RegistryType type) { switch (type) { case BLOCK: return protocol.getMappingData().getBlockMappings() != null ? id -> protocol.getMappingData().getNewBlockId(id) : null; @@ -87,8 +86,7 @@ public class StatisticsRewriter { throw new IllegalArgumentException("Unknown registry type in statistics packet: " + type); } - @Nullable - public RegistryType getRegistryTypeForStatistic(int statisticsId) { + public @Nullable RegistryType getRegistryTypeForStatistic(int statisticsId) { switch (statisticsId) { case 0: return RegistryType.BLOCK; diff --git a/common/src/main/java/us/myles/ViaVersion/api/rewriters/TagRewriter.java b/common/src/main/java/us/myles/ViaVersion/api/rewriters/TagRewriter.java index 0f66f3f1f..a317095d9 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/rewriters/TagRewriter.java +++ b/common/src/main/java/us/myles/ViaVersion/api/rewriters/TagRewriter.java @@ -19,7 +19,7 @@ package us.myles.ViaVersion.api.rewriters; import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntList; -import org.jetbrains.annotations.Nullable; +import org.checkerframework.checker.nullness.qual.Nullable; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.data.MappingData; import us.myles.ViaVersion.api.protocol.ClientboundPacketType; @@ -162,8 +162,7 @@ public class TagRewriter { } } - @Nullable - public List getNewTags(RegistryType tagType) { + public @Nullable List getNewTags(RegistryType tagType) { return newTags.get(tagType); } @@ -171,8 +170,7 @@ public class TagRewriter { return newTags.computeIfAbsent(tagType, type -> new ArrayList<>()); } - @Nullable - public IdRewriteFunction getRewriter(RegistryType tagType) { + public @Nullable IdRewriteFunction getRewriter(RegistryType tagType) { MappingData mappingData = protocol.getMappingData(); switch (tagType) { case BLOCK: diff --git a/common/src/main/java/us/myles/ViaVersion/api/storage/EntityTracker.java b/common/src/main/java/us/myles/ViaVersion/api/storage/EntityTracker.java index 26ad5b845..11c71fc17 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/storage/EntityTracker.java +++ b/common/src/main/java/us/myles/ViaVersion/api/storage/EntityTracker.java @@ -17,7 +17,7 @@ */ package us.myles.ViaVersion.api.storage; -import org.jetbrains.annotations.Nullable; +import org.checkerframework.checker.nullness.qual.Nullable; import us.myles.ViaVersion.api.data.ExternalJoinGameListener; import us.myles.ViaVersion.api.data.StoredObject; import us.myles.ViaVersion.api.data.UserConnection; @@ -48,8 +48,7 @@ public abstract class EntityTracker extends StoredObject implements ExternalJoin return clientEntityTypes.containsKey(entityId); } - @Nullable - public EntityType getEntity(int entityId) { + public @Nullable EntityType getEntity(int entityId) { return clientEntityTypes.get(entityId); } diff --git a/common/src/main/java/us/myles/ViaVersion/commands/defaultsubs/PPSSubCmd.java b/common/src/main/java/us/myles/ViaVersion/commands/defaultsubs/PPSSubCmd.java index f18b50f49..f0e21c029 100644 --- a/common/src/main/java/us/myles/ViaVersion/commands/defaultsubs/PPSSubCmd.java +++ b/common/src/main/java/us/myles/ViaVersion/commands/defaultsubs/PPSSubCmd.java @@ -23,7 +23,11 @@ import us.myles.ViaVersion.api.command.ViaSubCommand; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.protocol.ProtocolVersion; -import java.util.*; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; public class PPSSubCmd extends ViaSubCommand { @Override diff --git a/common/src/main/java/us/myles/ViaVersion/handlers/ChannelHandlerContextWrapper.java b/common/src/main/java/us/myles/ViaVersion/handlers/ChannelHandlerContextWrapper.java index 37c1c0489..e3dc7d228 100644 --- a/common/src/main/java/us/myles/ViaVersion/handlers/ChannelHandlerContextWrapper.java +++ b/common/src/main/java/us/myles/ViaVersion/handlers/ChannelHandlerContextWrapper.java @@ -19,7 +19,13 @@ package us.myles.ViaVersion.handlers; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufAllocator; -import io.netty.channel.*; +import io.netty.channel.Channel; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelHandler; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelPipeline; +import io.netty.channel.ChannelProgressivePromise; +import io.netty.channel.ChannelPromise; import io.netty.util.Attribute; import io.netty.util.AttributeKey; import io.netty.util.concurrent.EventExecutor; diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_10to1_9_3/packets/InventoryPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_10to1_9_3/packets/InventoryPackets.java index 6e5bc2d9e..dd0e602b6 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_10to1_9_3/packets/InventoryPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_10to1_9_3/packets/InventoryPackets.java @@ -26,7 +26,8 @@ import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_ public class InventoryPackets { public static void register(Protocol1_10To1_9_3_4 protocol) { - ItemRewriter itemRewriter = new ItemRewriter(protocol, item -> {}, InventoryPackets::toServerItem); + ItemRewriter itemRewriter = new ItemRewriter(protocol, item -> { + }, InventoryPackets::toServerItem); itemRewriter.registerCreativeInvAction(ServerboundPackets1_9_3.CREATIVE_INVENTORY_ACTION, Type.ITEM); } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11_1to1_11/packets/InventoryPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11_1to1_11/packets/InventoryPackets.java index a2dac473d..de4f436e8 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11_1to1_11/packets/InventoryPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11_1to1_11/packets/InventoryPackets.java @@ -26,7 +26,8 @@ import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_ public class InventoryPackets { public static void register(Protocol1_11_1To1_11 protocol) { - ItemRewriter itemRewriter = new ItemRewriter(protocol, item -> {}, InventoryPackets::toServerItem); + ItemRewriter itemRewriter = new ItemRewriter(protocol, item -> { + }, InventoryPackets::toServerItem); itemRewriter.registerCreativeInvAction(ServerboundPackets1_9_3.CREATIVE_INVENTORY_ACTION, Type.ITEM); } diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/packets/InventoryPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/packets/InventoryPackets.java index 3f0cf75bc..ce7371c03 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/packets/InventoryPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_11to1_10/packets/InventoryPackets.java @@ -23,10 +23,10 @@ import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.rewriters.ItemRewriter; import us.myles.ViaVersion.api.type.Type; -import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3; -import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3; import us.myles.ViaVersion.protocols.protocol1_11to1_10.EntityIdRewriter; import us.myles.ViaVersion.protocols.protocol1_11to1_10.Protocol1_11To1_10; +import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3; +import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3; public class InventoryPackets { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/packets/InventoryPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/packets/InventoryPackets.java index fa1c922c5..bd7e94bf5 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/packets/InventoryPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_12to1_11_1/packets/InventoryPackets.java @@ -24,11 +24,11 @@ import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.rewriters.ItemRewriter; import us.myles.ViaVersion.api.type.Type; -import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3; import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.BedRewriter; import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.Protocol1_12To1_11_1; import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.ServerboundPackets1_12; import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.providers.InventoryQuickMoveProvider; +import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.ClientboundPackets1_9_3; public class InventoryPackets { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java index a6dbc1676..b4bf87c8b 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java @@ -119,7 +119,7 @@ public class Protocol1_13To1_12_2 extends Protocol T get(String key, Class clazz, T def) { + public @Nullable T get(String key, Class clazz, T def) { Object o = this.config.get(key); if (o != null) { return (T) o; @@ -161,8 +164,7 @@ public abstract class Config implements ConfigurationProvider { } } - @Nullable - public String getString(String key, @Nullable String def) { + public @Nullable String getString(String key, @Nullable String def) { final Object o = this.config.get(key); if (o != null) { return (String) o; diff --git a/sponge/src/main/java/us/myles/ViaVersion/sponge/commands/SpongeCommandHandler.java b/sponge/src/main/java/us/myles/ViaVersion/sponge/commands/SpongeCommandHandler.java index 649b2c73c..7398688d3 100644 --- a/sponge/src/main/java/us/myles/ViaVersion/sponge/commands/SpongeCommandHandler.java +++ b/sponge/src/main/java/us/myles/ViaVersion/sponge/commands/SpongeCommandHandler.java @@ -17,7 +17,7 @@ */ package us.myles.ViaVersion.sponge.commands; -import org.jetbrains.annotations.Nullable; +import org.checkerframework.checker.nullness.qual.Nullable; import org.spongepowered.api.command.CommandCallable; import org.spongepowered.api.command.CommandException; import org.spongepowered.api.command.CommandResult;