diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index dac8a9a07..a483fbe95 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -19,32 +19,28 @@ public class LongClassName { public int nameWithMultipleWords = 0; /** - * Javadoc comment to explain what a function does. - */ + * Javadoc comment to explain what a function does. + */ @RandomAnnotation(stuff = true, moreStuff = "might exist") public void applyStuff() { Variable variable = new Variable(); Variable otherVariable = new Variable(); if (condition) { - // Do stuff. + // Do stuff. } else if (anotherCondition) { - // Do something else. + // Do something else. } switch (value) { - case 0: - stuff(); - break; - case 1: - differentStuff(); - break; + case 0 -> stuff(); + case 1 -> differentStuff(); } } } ``` -Make sure to comment your code where possible. +Make sure to comment your code where possible. To mark nullable methods, use `@Nullable` (and subsequently, `@NonNull`) from the `org.checkerframework.checker.nullness.qual` package. The nature of our software requires a lot of arrays and maps to be stored - where possible, use Fastutil's specialized maps. For example, if you're storing block state translations, use an `Int2IntMap`. diff --git a/ap/src/main/java/org/geysermc/geyser/processor/ClassProcessor.java b/ap/src/main/java/org/geysermc/geyser/processor/ClassProcessor.java index e1da50f25..6fcd5d888 100644 --- a/ap/src/main/java/org/geysermc/geyser/processor/ClassProcessor.java +++ b/ap/src/main/java/org/geysermc/geyser/processor/ClassProcessor.java @@ -25,6 +25,8 @@ package org.geysermc.geyser.processor; +import org.checkerframework.checker.nullness.qual.Nullable; + import javax.annotation.processing.AbstractProcessor; import javax.annotation.processing.ProcessingEnvironment; import javax.annotation.processing.RoundEnvironment; @@ -159,7 +161,7 @@ public class ClassProcessor extends AbstractProcessor { this.processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "Completed processing for " + this.annotationClassName); } - private BufferedReader createReader() throws IOException { + private @Nullable BufferedReader createReader() throws IOException { if (this.outputPath != null) { this.processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "Reading existing " + this.annotationClassName + " list from " + this.outputPath); return Files.newBufferedReader(this.outputPath); diff --git a/api/src/main/java/org/geysermc/geyser/api/GeyserApi.java b/api/src/main/java/org/geysermc/geyser/api/GeyserApi.java index de5c78678..0d6007c1c 100644 --- a/api/src/main/java/org/geysermc/geyser/api/GeyserApi.java +++ b/api/src/main/java/org/geysermc/geyser/api/GeyserApi.java @@ -77,6 +77,7 @@ public interface GeyserApi extends GeyserApiBase { * @param apiClass the builder class * @param the implementation type * @param the API type + * @throws IllegalArgumentException if there is no provider for the specified API class * @return the builder instance */ @NonNull diff --git a/api/src/main/java/org/geysermc/geyser/api/bedrock/camera/CameraShake.java b/api/src/main/java/org/geysermc/geyser/api/bedrock/camera/CameraShake.java index 18bafb428..67b56b1f5 100644 --- a/api/src/main/java/org/geysermc/geyser/api/bedrock/camera/CameraShake.java +++ b/api/src/main/java/org/geysermc/geyser/api/bedrock/camera/CameraShake.java @@ -27,5 +27,5 @@ package org.geysermc.geyser.api.bedrock.camera; public enum CameraShake { POSITIONAL, - ROTATIONAL; + ROTATIONAL } diff --git a/api/src/main/java/org/geysermc/geyser/api/block/custom/component/PlacementConditions.java b/api/src/main/java/org/geysermc/geyser/api/block/custom/component/PlacementConditions.java index d06d9a967..e274fd8bd 100644 --- a/api/src/main/java/org/geysermc/geyser/api/block/custom/component/PlacementConditions.java +++ b/api/src/main/java/org/geysermc/geyser/api/block/custom/component/PlacementConditions.java @@ -25,11 +25,11 @@ package org.geysermc.geyser.api.block.custom.component; +import org.checkerframework.checker.nullness.qual.NonNull; + import java.util.LinkedHashMap; import java.util.Set; -import org.checkerframework.checker.nullness.qual.NonNull; - /** * This class is used to store conditions for a placement filter for a custom block. * @@ -43,7 +43,7 @@ public record PlacementConditions(@NonNull Set allowedFaces, @NonNull Link NORTH, SOUTH, WEST, - EAST; + EAST } public enum BlockFilterType { diff --git a/api/src/main/java/org/geysermc/geyser/api/block/custom/nonvanilla/JavaBlockState.java b/api/src/main/java/org/geysermc/geyser/api/block/custom/nonvanilla/JavaBlockState.java index 6293506a8..f7da4b932 100644 --- a/api/src/main/java/org/geysermc/geyser/api/block/custom/nonvanilla/JavaBlockState.java +++ b/api/src/main/java/org/geysermc/geyser/api/block/custom/nonvanilla/JavaBlockState.java @@ -39,7 +39,7 @@ public interface JavaBlockState { * * @return whether the block state is waterlogged */ - @NonNull boolean waterlogged(); + boolean waterlogged(); /** * Gets the collision of the block state @@ -53,7 +53,7 @@ public interface JavaBlockState { * * @return whether the block state can be broken with hand */ - @NonNull boolean canBreakWithHand(); + boolean canBreakWithHand(); /** * Gets the pick item of the block state @@ -74,7 +74,7 @@ public interface JavaBlockState { * * @return whether the block state has block entity */ - @Nullable boolean hasBlockEntity(); + boolean hasBlockEntity(); /** * Creates a new {@link JavaBlockState.Builder} instance @@ -94,17 +94,17 @@ public interface JavaBlockState { Builder blockHardness(@NonNegative float blockHardness); - Builder waterlogged(@NonNull boolean waterlogged); + Builder waterlogged(boolean waterlogged); Builder collision(@NonNull JavaBoundingBox[] collision); - Builder canBreakWithHand(@NonNull boolean canBreakWithHand); + Builder canBreakWithHand(boolean canBreakWithHand); Builder pickItem(@Nullable String pickItem); Builder pistonBehavior(@Nullable String pistonBehavior); - Builder hasBlockEntity(@Nullable boolean hasBlockEntity); + Builder hasBlockEntity(boolean hasBlockEntity); JavaBlockState build(); } diff --git a/api/src/main/java/org/geysermc/geyser/api/block/custom/nonvanilla/JavaBoundingBox.java b/api/src/main/java/org/geysermc/geyser/api/block/custom/nonvanilla/JavaBoundingBox.java index 56a4ca3da..9065e8711 100644 --- a/api/src/main/java/org/geysermc/geyser/api/block/custom/nonvanilla/JavaBoundingBox.java +++ b/api/src/main/java/org/geysermc/geyser/api/block/custom/nonvanilla/JavaBoundingBox.java @@ -1,6 +1,4 @@ package org.geysermc.geyser.api.block.custom.nonvanilla; -import org.checkerframework.checker.nullness.qual.NonNull; - -public record JavaBoundingBox(@NonNull double middleX, @NonNull double middleY, @NonNull double middleZ, @NonNull double sizeX, @NonNull double sizeY, @NonNull double sizeZ) { +public record JavaBoundingBox(double middleX, double middleY, double middleZ, double sizeX, double sizeY, double sizeZ) { } diff --git a/api/src/main/java/org/geysermc/geyser/api/event/EventBus.java b/api/src/main/java/org/geysermc/geyser/api/event/EventBus.java index 801bfa45f..3344e38f4 100644 --- a/api/src/main/java/org/geysermc/geyser/api/event/EventBus.java +++ b/api/src/main/java/org/geysermc/geyser/api/event/EventBus.java @@ -28,7 +28,6 @@ package org.geysermc.geyser.api.event; import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.event.Event; import org.geysermc.event.bus.OwnedEventBus; -import org.geysermc.geyser.api.extension.Extension; import java.util.Set; diff --git a/api/src/main/java/org/geysermc/geyser/api/event/EventSubscriber.java b/api/src/main/java/org/geysermc/geyser/api/event/EventSubscriber.java index 7f91d09a3..258ef9164 100644 --- a/api/src/main/java/org/geysermc/geyser/api/event/EventSubscriber.java +++ b/api/src/main/java/org/geysermc/geyser/api/event/EventSubscriber.java @@ -27,7 +27,6 @@ package org.geysermc.geyser.api.event; import org.geysermc.event.Event; import org.geysermc.event.subscribe.OwnedSubscriber; -import org.geysermc.geyser.api.extension.Extension; /** * Represents a subscribed listener to a {@link Event}. Wraps around diff --git a/api/src/main/java/org/geysermc/geyser/api/event/connection/GeyserBedrockPingEvent.java b/api/src/main/java/org/geysermc/geyser/api/event/connection/GeyserBedrockPingEvent.java index 67a81ac58..10ccb93d5 100644 --- a/api/src/main/java/org/geysermc/geyser/api/event/connection/GeyserBedrockPingEvent.java +++ b/api/src/main/java/org/geysermc/geyser/api/event/connection/GeyserBedrockPingEvent.java @@ -34,7 +34,7 @@ import java.net.InetSocketAddress; /** * Called whenever Geyser gets pinged - * + *

* This event allows you to modify/obtain the MOTD, maximum player count, and current number of players online, * Geyser will reply to the client with what was given. */ diff --git a/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineCommandsEvent.java b/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineCommandsEvent.java index 77d5efa65..994373752 100644 --- a/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineCommandsEvent.java +++ b/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineCommandsEvent.java @@ -33,7 +33,7 @@ import java.util.Map; /** * Called when commands are defined within Geyser. - * + *

* This event allows you to register new commands using the {@link #register(Command)} * method and retrieve the default commands defined. */ diff --git a/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineCustomBlocksEvent.java b/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineCustomBlocksEvent.java index b1a01d7e6..a105578d9 100644 --- a/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineCustomBlocksEvent.java +++ b/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineCustomBlocksEvent.java @@ -28,13 +28,12 @@ package org.geysermc.geyser.api.event.lifecycle; import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.geyser.api.block.custom.CustomBlockData; import org.geysermc.geyser.api.block.custom.CustomBlockState; -import org.geysermc.geyser.api.block.custom.nonvanilla.JavaBlockItem; import org.geysermc.geyser.api.block.custom.nonvanilla.JavaBlockState; import org.geysermc.event.Event; /** * Called on Geyser's startup when looking for custom blocks. Custom blocks must be registered through this event. - * + *

* This event will not be called if the "add-non-bedrock-items" setting is disabled in the Geyser config. */ public abstract class GeyserDefineCustomBlocksEvent implements Event { @@ -48,8 +47,8 @@ public abstract class GeyserDefineCustomBlocksEvent implements Event { /** * Registers the given {@link CustomBlockState} as an override for the * given java state identifier - * Java state identifiers are listed in - * https://raw.githubusercontent.com/GeyserMC/mappings/master/blocks.json + * Java state identifiers are listed + * here * * @param javaIdentifier the java state identifier to override * @param customBlockState the custom block state with which to override java state identifier diff --git a/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineCustomItemsEvent.java b/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineCustomItemsEvent.java index 0957b8551..bd14aaf43 100644 --- a/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineCustomItemsEvent.java +++ b/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineCustomItemsEvent.java @@ -36,7 +36,7 @@ import java.util.Map; /** * Called on Geyser's startup when looking for custom items. Custom items must be registered through this event. - * + *

* This event will not be called if the "add non-Bedrock items" setting is disabled in the Geyser config. */ public interface GeyserDefineCustomItemsEvent extends Event { diff --git a/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineCustomSkullsEvent.java b/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineCustomSkullsEvent.java index 17f7b599a..6443bbeb3 100644 --- a/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineCustomSkullsEvent.java +++ b/api/src/main/java/org/geysermc/geyser/api/event/lifecycle/GeyserDefineCustomSkullsEvent.java @@ -5,7 +5,7 @@ import org.geysermc.event.Event; /** * Called on Geyser's startup when looking for custom skulls. Custom skulls must be registered through this event. - * + *

* This event will not be called if the "add-non-bedrock-items" setting is disabled in the Geyser config. */ public abstract class GeyserDefineCustomSkullsEvent implements Event { diff --git a/api/src/main/java/org/geysermc/geyser/api/extension/exception/InvalidDescriptionException.java b/api/src/main/java/org/geysermc/geyser/api/extension/exception/InvalidDescriptionException.java index 1fe88e9e9..5313c1f40 100644 --- a/api/src/main/java/org/geysermc/geyser/api/extension/exception/InvalidDescriptionException.java +++ b/api/src/main/java/org/geysermc/geyser/api/extension/exception/InvalidDescriptionException.java @@ -25,10 +25,16 @@ package org.geysermc.geyser.api.extension.exception; +import java.io.Serial; + /** * Thrown when an extension's description is invalid. */ public class InvalidDescriptionException extends Exception { + + @Serial + private static final long serialVersionUID = 1L; + public InvalidDescriptionException(Throwable cause) { super(cause); } diff --git a/api/src/main/java/org/geysermc/geyser/api/extension/exception/InvalidExtensionException.java b/api/src/main/java/org/geysermc/geyser/api/extension/exception/InvalidExtensionException.java index 7fb6b6922..89780fe46 100644 --- a/api/src/main/java/org/geysermc/geyser/api/extension/exception/InvalidExtensionException.java +++ b/api/src/main/java/org/geysermc/geyser/api/extension/exception/InvalidExtensionException.java @@ -25,10 +25,16 @@ package org.geysermc.geyser.api.extension.exception; +import java.io.Serial; + /** * Thrown when an extension is invalid. */ public class InvalidExtensionException extends Exception { + + @Serial + private static final long serialVersionUID = 1L; + public InvalidExtensionException(Throwable cause) { super(cause); } diff --git a/api/src/main/java/org/geysermc/geyser/api/util/CreativeCategory.java b/api/src/main/java/org/geysermc/geyser/api/util/CreativeCategory.java index 7519ff157..207320b1e 100644 --- a/api/src/main/java/org/geysermc/geyser/api/util/CreativeCategory.java +++ b/api/src/main/java/org/geysermc/geyser/api/util/CreativeCategory.java @@ -51,7 +51,7 @@ public enum CreativeCategory { * * @return the name of the category */ - @NonNull public String internalName() { + public @NonNull String internalName() { return internalName; } diff --git a/api/src/main/java/org/geysermc/geyser/api/util/TriState.java b/api/src/main/java/org/geysermc/geyser/api/util/TriState.java index 457a38e32..a8bb723d6 100644 --- a/api/src/main/java/org/geysermc/geyser/api/util/TriState.java +++ b/api/src/main/java/org/geysermc/geyser/api/util/TriState.java @@ -30,7 +30,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; /** * This is a way to represent a boolean, but with a non set value added. - * This class was inspired by adventure's version https://github.com/KyoriPowered/adventure/blob/main/4/api/src/main/java/net/kyori/adventure/util/TriState.java + * This class was inspired by adventure's TriState */ public enum TriState { /** diff --git a/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeeDumpInfo.java b/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeeDumpInfo.java index ba7bc464f..85abd285b 100644 --- a/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeeDumpInfo.java +++ b/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeeDumpInfo.java @@ -30,6 +30,7 @@ import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.plugin.Plugin; import org.geysermc.geyser.dump.BootstrapDumpInfo; +import java.net.InetSocketAddress; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -51,7 +52,8 @@ public class GeyserBungeeDumpInfo extends BootstrapDumpInfo { this.plugins = new ArrayList<>(); for (net.md_5.bungee.api.config.ListenerInfo listener : proxy.getConfig().getListeners()) { - this.listeners.add(new ListenerInfo(listener.getHost().getHostString(), listener.getHost().getPort())); + InetSocketAddress address = (InetSocketAddress) listener.getSocketAddress(); + this.listeners.add(new ListenerInfo(address.getHostString(), address.getPort())); } for (Plugin plugin : proxy.getPluginManager().getPlugins()) { diff --git a/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeeInjector.java b/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeeInjector.java index e10b3ce6f..7c60ba95d 100644 --- a/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeeInjector.java +++ b/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeeInjector.java @@ -39,6 +39,7 @@ import net.md_5.bungee.api.plugin.Listener; import net.md_5.bungee.api.plugin.Plugin; import net.md_5.bungee.event.EventHandler; import net.md_5.bungee.netty.PipelineUtils; +import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.geyser.GeyserBootstrap; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.network.netty.GeyserInjector; @@ -125,7 +126,7 @@ public class GeyserBungeeInjector extends GeyserInjector implements Listener { .channel(LocalServerChannelWrapper.class) .childHandler(new ChannelInitializer<>() { @Override - protected void initChannel(Channel ch) throws Exception { + protected void initChannel(@NonNull Channel ch) throws Exception { if (proxy.getConfig().getServers() == null) { // Proxy hasn't finished loading all plugins - it loads the config after all plugins // Probably doesn't need to be translatable? diff --git a/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeePingPassthrough.java b/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeePingPassthrough.java index e14e8ff66..3c3853ed8 100644 --- a/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeePingPassthrough.java +++ b/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeePingPassthrough.java @@ -35,6 +35,7 @@ import net.md_5.bungee.api.connection.PendingConnection; import net.md_5.bungee.api.event.ProxyPingEvent; import net.md_5.bungee.api.plugin.Listener; import net.md_5.bungee.protocol.ProtocolConstants; +import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.ping.GeyserPingInfo; import org.geysermc.geyser.ping.IGeyserPingPassthrough; @@ -104,7 +105,7 @@ public class GeyserBungeePingPassthrough implements IGeyserPingPassthrough, List } @Override - public InetSocketAddress getVirtualHost() { + public @Nullable InetSocketAddress getVirtualHost() { return null; } diff --git a/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeePlugin.java b/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeePlugin.java index e58abc3b4..c4eea66b8 100644 --- a/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeePlugin.java +++ b/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/GeyserBungeePlugin.java @@ -30,6 +30,7 @@ import net.md_5.bungee.BungeeCord; import net.md_5.bungee.api.config.ListenerInfo; import net.md_5.bungee.api.plugin.Plugin; import net.md_5.bungee.protocol.ProtocolConstants; +import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.api.util.PlatformType; import org.geysermc.geyser.GeyserBootstrap; @@ -44,7 +45,6 @@ import org.geysermc.geyser.ping.IGeyserPingPassthrough; import org.geysermc.geyser.platform.bungeecord.command.GeyserBungeeCommandExecutor; import org.geysermc.geyser.text.GeyserLocale; import org.geysermc.geyser.util.FileUtils; -import org.jetbrains.annotations.NotNull; import java.io.File; import java.io.IOException; @@ -72,6 +72,7 @@ public class GeyserBungeePlugin extends Plugin implements GeyserBootstrap { private static boolean INITIALIZED = false; + @SuppressWarnings({"JavaReflectionMemberAccess", "ResultOfMethodCallIgnored"}) @Override public void onLoad() { GeyserLocale.init(this); @@ -251,7 +252,7 @@ public class GeyserBungeePlugin extends Plugin implements GeyserBootstrap { return this.geyserInjector.getServerSocketAddress(); } - @NotNull + @NonNull @Override public String getServerBindAddress() { return findCompatibleListener().map(InetSocketAddress::getHostString).orElse(""); diff --git a/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/command/BungeeCommandSource.java b/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/command/BungeeCommandSource.java index f65377643..e3099f170 100644 --- a/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/command/BungeeCommandSource.java +++ b/bootstrap/bungeecord/src/main/java/org/geysermc/geyser/platform/bungeecord/command/BungeeCommandSource.java @@ -29,6 +29,7 @@ import net.kyori.adventure.text.Component; import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer; import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.connection.ProxiedPlayer; +import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.geyser.command.GeyserCommandSource; import org.geysermc.geyser.text.GeyserLocale; @@ -50,7 +51,7 @@ public class BungeeCommandSource implements GeyserCommandSource { } @Override - public void sendMessage(String message) { + public void sendMessage(@NonNull String message) { handle.sendMessage(TextComponent.fromLegacyText(message)); } diff --git a/bootstrap/fabric/src/main/java/org/geysermc/geyser/platform/fabric/GeyserFabricMod.java b/bootstrap/fabric/src/main/java/org/geysermc/geyser/platform/fabric/GeyserFabricMod.java index af0c9efca..071409046 100644 --- a/bootstrap/fabric/src/main/java/org/geysermc/geyser/platform/fabric/GeyserFabricMod.java +++ b/bootstrap/fabric/src/main/java/org/geysermc/geyser/platform/fabric/GeyserFabricMod.java @@ -37,6 +37,8 @@ import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; import net.minecraft.server.MinecraftServer; import org.apache.logging.log4j.LogManager; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.GeyserBootstrap; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserLogger; @@ -54,8 +56,6 @@ import org.geysermc.geyser.platform.fabric.command.GeyserFabricCommandExecutor; import org.geysermc.geyser.platform.fabric.world.GeyserFabricWorldManager; import org.geysermc.geyser.text.GeyserLocale; import org.geysermc.geyser.util.FileUtils; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.io.File; import java.io.IOException; @@ -251,7 +251,7 @@ public class GeyserFabricMod implements ModInitializer, GeyserBootstrap { return this.server.getServerVersion(); } - @NotNull + @NonNull @Override public String getServerBindAddress() { String ip = this.server.getLocalIp(); diff --git a/bootstrap/fabric/src/main/java/org/geysermc/geyser/platform/fabric/command/FabricCommandSender.java b/bootstrap/fabric/src/main/java/org/geysermc/geyser/platform/fabric/command/FabricCommandSender.java index 6517ac133..28875ec6e 100644 --- a/bootstrap/fabric/src/main/java/org/geysermc/geyser/platform/fabric/command/FabricCommandSender.java +++ b/bootstrap/fabric/src/main/java/org/geysermc/geyser/platform/fabric/command/FabricCommandSender.java @@ -30,11 +30,12 @@ import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import net.minecraft.commands.CommandSourceStack; import net.minecraft.network.chat.Component; import net.minecraft.server.level.ServerPlayer; +import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.command.GeyserCommandSource; import org.geysermc.geyser.text.ChatColor; -import javax.annotation.Nonnull; +import java.util.Objects; public class FabricCommandSender implements GeyserCommandSource { @@ -50,7 +51,7 @@ public class FabricCommandSender implements GeyserCommandSource { } @Override - public void sendMessage(@Nonnull String message) { + public void sendMessage(@NonNull String message) { if (source.getEntity() instanceof ServerPlayer) { ((ServerPlayer) source.getEntity()).displayClientMessage(Component.literal(message), false); } else { @@ -62,7 +63,7 @@ public class FabricCommandSender implements GeyserCommandSource { public void sendMessage(net.kyori.adventure.text.Component message) { if (source.getEntity() instanceof ServerPlayer player) { String decoded = GsonComponentSerializer.gson().serialize(message); - player.displayClientMessage(Component.Serializer.fromJson(decoded), false); + player.displayClientMessage(Objects.requireNonNull(Component.Serializer.fromJson(decoded)), false); return; } GeyserCommandSource.super.sendMessage(message); diff --git a/bootstrap/fabric/src/main/java/org/geysermc/geyser/platform/fabric/command/GeyserFabricCommandExecutor.java b/bootstrap/fabric/src/main/java/org/geysermc/geyser/platform/fabric/command/GeyserFabricCommandExecutor.java index 8da7c8512..732b28ca7 100644 --- a/bootstrap/fabric/src/main/java/org/geysermc/geyser/platform/fabric/command/GeyserFabricCommandExecutor.java +++ b/bootstrap/fabric/src/main/java/org/geysermc/geyser/platform/fabric/command/GeyserFabricCommandExecutor.java @@ -52,12 +52,12 @@ public class GeyserFabricCommandExecutor extends GeyserCommandExecutor implement } @Override - public int run(CommandContext context) { + public int run(CommandContext context) { return runWithArgs(context, ""); } - public int runWithArgs(CommandContext context, String args) { - CommandSourceStack source = (CommandSourceStack) context.getSource(); + public int runWithArgs(CommandContext context, String args) { + CommandSourceStack source = context.getSource(); FabricCommandSender sender = new FabricCommandSender(source); GeyserSession session = getGeyserSession(sender); if (!testPermission(source)) { diff --git a/bootstrap/fabric/src/main/java/org/geysermc/geyser/platform/fabric/mixin/client/IntegratedServerMixin.java b/bootstrap/fabric/src/main/java/org/geysermc/geyser/platform/fabric/mixin/client/IntegratedServerMixin.java index 942909068..f11d3a1ae 100644 --- a/bootstrap/fabric/src/main/java/org/geysermc/geyser/platform/fabric/mixin/client/IntegratedServerMixin.java +++ b/bootstrap/fabric/src/main/java/org/geysermc/geyser/platform/fabric/mixin/client/IntegratedServerMixin.java @@ -42,6 +42,8 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import java.util.Objects; + @Environment(EnvType.CLIENT) @Mixin(IntegratedServer.class) public class IntegratedServerMixin implements GeyserServerPortGetter { @@ -58,6 +60,7 @@ public class IntegratedServerMixin implements GeyserServerPortGetter { // Ensure player locale has been loaded, in case it's different from Java system language GeyserLocale.loadGeyserLocale(this.minecraft.options.languageCode); // Give indication that Geyser is loaded + Objects.requireNonNull(this.minecraft.player); this.minecraft.player.displayClientMessage(Component.literal(GeyserLocale.getPlayerLocaleString("geyser.core.start", this.minecraft.options.languageCode, "localhost", String.valueOf(this.publishedPort))), false); } diff --git a/bootstrap/fabric/src/main/java/org/geysermc/geyser/platform/fabric/world/GeyserFabricWorldManager.java b/bootstrap/fabric/src/main/java/org/geysermc/geyser/platform/fabric/world/GeyserFabricWorldManager.java index 923db9b25..9d7b81831 100644 --- a/bootstrap/fabric/src/main/java/org/geysermc/geyser/platform/fabric/world/GeyserFabricWorldManager.java +++ b/bootstrap/fabric/src/main/java/org/geysermc/geyser/platform/fabric/world/GeyserFabricWorldManager.java @@ -39,6 +39,7 @@ import net.minecraft.world.level.block.entity.BannerBlockEntity; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.LecternBlockEntity; import net.minecraft.world.level.chunk.LevelChunk; +import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.vector.Vector3i; import org.cloudburstmc.nbt.NbtMap; import org.cloudburstmc.nbt.NbtMapBuilder; @@ -48,9 +49,9 @@ import org.geysermc.geyser.level.GeyserWorldManager; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.BlockEntityUtils; -import javax.annotation.Nonnull; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.concurrent.CompletableFuture; public class GeyserFabricWorldManager extends GeyserWorldManager { @@ -73,9 +74,11 @@ public class GeyserFabricWorldManager extends GeyserWorldManager { return; } + //noinspection resource - level() is just a getter LevelChunk chunk = player.level().getChunk(x, z); final int chunkBlockX = x << 4; final int chunkBlockZ = z << 4; + //noinspection ForLoopReplaceableByForEach - avoid constructing iterator for (int i = 0; i < blockEntityInfos.size(); i++) { BlockEntityInfo blockEntityInfo = blockEntityInfos.get(i); BlockEntity blockEntity = chunk.getBlockEntity(new BlockPos(chunkBlockX + blockEntityInfo.getX(), @@ -92,7 +95,7 @@ public class GeyserFabricWorldManager extends GeyserWorldManager { if (player == null) { return; } - + //noinspection resource - level() is just a getter BlockEntity blockEntity = player.level().getBlockEntity(new BlockPos(x, y, z)); sendLecternData(session, blockEntity, false); }); @@ -159,7 +162,7 @@ public class GeyserFabricWorldManager extends GeyserWorldManager { return GameMode.byId(server.getDefaultGameType().getId()); } - @Nonnull + @NonNull @Override public CompletableFuture getPickItemNbt(GeyserSession session, int x, int y, int z, boolean addNbtData) { CompletableFuture future = new CompletableFuture<>(); @@ -172,6 +175,7 @@ public class GeyserFabricWorldManager extends GeyserWorldManager { BlockPos pos = new BlockPos(x, y, z); // Don't create a new block entity if invalid + //noinspection resource - level() is just a getter BlockEntity blockEntity = player.level().getChunkAt(pos).getBlockEntity(pos); if (blockEntity instanceof BannerBlockEntity banner) { // Potentially exposes other NBT data? But we need to get the NBT data for the banner patterns *and* @@ -263,7 +267,7 @@ public class GeyserFabricWorldManager extends GeyserWorldManager { } @Override - public void visitCompound(CompoundTag compoundTag) { + public void visitCompound(@NonNull CompoundTag compoundTag) { currentTag = convert(currentKey, compoundTag); } @@ -271,7 +275,7 @@ public class GeyserFabricWorldManager extends GeyserWorldManager { OpenNbtTagVisitor visitor = new OpenNbtTagVisitor(name); for (String key : compoundTag.getAllKeys()) { visitor.currentKey = key; - Tag tag = compoundTag.get(key); + Tag tag = Objects.requireNonNull(compoundTag.get(key)); tag.accept(visitor); visitor.root.put(visitor.currentTag); } @@ -279,7 +283,7 @@ public class GeyserFabricWorldManager extends GeyserWorldManager { } @Override - public void visitEnd(EndTag endTag) { + public void visitEnd(@NonNull EndTag endTag) { } } } diff --git a/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserPaperPingPassthrough.java b/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserPaperPingPassthrough.java index 60e0ae519..6a962f450 100644 --- a/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserPaperPingPassthrough.java +++ b/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserPaperPingPassthrough.java @@ -28,11 +28,11 @@ package org.geysermc.geyser.platform.spigot; import com.destroystokyo.paper.event.server.PaperServerListPingEvent; import com.destroystokyo.paper.network.StatusClient; import org.bukkit.Bukkit; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.network.GameProtocol; import org.geysermc.geyser.ping.GeyserPingInfo; import org.geysermc.geyser.ping.IGeyserPingPassthrough; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.lang.reflect.Constructor; import java.net.InetSocketAddress; @@ -50,6 +50,7 @@ public final class GeyserPaperPingPassthrough implements IGeyserPingPassthrough this.logger = logger; } + @SuppressWarnings("deprecation") @Nullable @Override public GeyserPingInfo getPingInformation(InetSocketAddress inetSocketAddress) { @@ -89,7 +90,7 @@ public final class GeyserPaperPingPassthrough implements IGeyserPingPassthrough private record GeyserStatusClient(InetSocketAddress address) implements StatusClient { @Override - public @NotNull InetSocketAddress getAddress() { + public @NonNull InetSocketAddress getAddress() { return address; } diff --git a/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotCompressionDisabler.java b/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotCompressionDisabler.java index 9b112f62f..2a6056df9 100644 --- a/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotCompressionDisabler.java +++ b/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotCompressionDisabler.java @@ -34,7 +34,7 @@ import org.geysermc.geyser.GeyserImpl; /** * Disables the compression packet (and the compression handlers from being added to the pipeline) for Geyser clients * that won't be receiving the data over the network. - * + *

* As of 1.8 - 1.17.1, compression is enabled in the Netty pipeline by adding a listener after a packet is written. * If we simply "cancel" or don't forward the packet, then the listener is never called. */ diff --git a/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotDumpInfo.java b/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotDumpInfo.java index d340935b3..329663709 100644 --- a/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotDumpInfo.java +++ b/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotDumpInfo.java @@ -47,6 +47,7 @@ public class GeyserSpigotDumpInfo extends BootstrapDumpInfo { private final int serverPort; private final List plugins; + @SuppressWarnings("deprecation") GeyserSpigotDumpInfo() { super(); this.platformName = Bukkit.getName(); diff --git a/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotInjector.java b/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotInjector.java index e3d73fb19..01bc0bea4 100644 --- a/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotInjector.java +++ b/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotInjector.java @@ -32,6 +32,7 @@ import io.netty.channel.*; import io.netty.channel.local.LocalAddress; import io.netty.util.concurrent.DefaultThreadFactory; import org.bukkit.Bukkit; +import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.geyser.GeyserBootstrap; import org.geysermc.geyser.network.netty.GeyserInjector; import org.geysermc.geyser.network.netty.LocalServerChannelWrapper; @@ -74,12 +75,10 @@ public class GeyserSpigotInjector extends GeyserInjector { Object connection = null; // Find the class that manages network IO for (Method m : serverClazz.getDeclaredMethods()) { - if (m.getReturnType() != null) { - // First is Spigot-mapped name, second is Mojang-mapped name which is implemented as future-proofing - if (m.getReturnType().getSimpleName().equals("ServerConnection") || m.getReturnType().getSimpleName().equals("ServerConnectionListener")) { - if (m.getParameterTypes().length == 0) { - connection = m.invoke(server); - } + // First is Spigot-mapped name, second is Mojang-mapped name which is implemented as future-proofing + if (m.getReturnType().getSimpleName().equals("ServerConnection") || m.getReturnType().getSimpleName().equals("ServerConnectionListener")) { + if (m.getParameterTypes().length == 0) { + connection = m.invoke(server); } } } @@ -117,7 +116,7 @@ public class GeyserSpigotInjector extends GeyserInjector { .channel(LocalServerChannelWrapper.class) .childHandler(new ChannelInitializer<>() { @Override - protected void initChannel(Channel ch) throws Exception { + protected void initChannel(@NonNull Channel ch) throws Exception { initChannel.invoke(childHandler, ch); if (bootstrap.getGeyserConfig().isDisableCompression() && GeyserSpigotCompressionDisabler.ENABLED) { diff --git a/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotPingPassthrough.java b/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotPingPassthrough.java index df197f137..4b1e42871 100644 --- a/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotPingPassthrough.java +++ b/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotPingPassthrough.java @@ -30,10 +30,12 @@ import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.server.ServerListPingEvent; import org.bukkit.util.CachedServerIcon; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; +import org.geysermc.geyser.network.GameProtocol; import org.geysermc.geyser.ping.GeyserPingInfo; import org.geysermc.geyser.ping.IGeyserPingPassthrough; -import javax.annotation.Nonnull; import java.net.InetAddress; import java.net.InetSocketAddress; import java.util.Collections; @@ -44,8 +46,9 @@ public class GeyserSpigotPingPassthrough implements IGeyserPingPassthrough { private final GeyserSpigotLogger logger; + @SuppressWarnings("deprecation") @Override - public GeyserPingInfo getPingInformation(InetSocketAddress inetSocketAddress) { + public @Nullable GeyserPingInfo getPingInformation(InetSocketAddress inetSocketAddress) { try { ServerListPingEvent event = new GeyserPingEvent(inetSocketAddress.getAddress(), Bukkit.getMotd(), Bukkit.getOnlinePlayers().size(), Bukkit.getMaxPlayers()); Bukkit.getPluginManager().callEvent(event); @@ -67,7 +70,7 @@ public class GeyserSpigotPingPassthrough implements IGeyserPingPassthrough { public void setServerIcon(CachedServerIcon icon) throws IllegalArgumentException, UnsupportedOperationException { } - @Nonnull + @NonNull @Override public Iterator iterator() throws UnsupportedOperationException { return Collections.emptyIterator(); diff --git a/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotPlugin.java b/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotPlugin.java index cfb6ff5ae..02ea91cf2 100644 --- a/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotPlugin.java +++ b/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotPlugin.java @@ -42,13 +42,14 @@ import org.bukkit.permissions.Permission; import org.bukkit.permissions.PermissionDefault; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; -import org.geysermc.geyser.api.util.PlatformType; +import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.geyser.Constants; import org.geysermc.geyser.GeyserBootstrap; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.adapters.spigot.SpigotAdapters; import org.geysermc.geyser.api.command.Command; import org.geysermc.geyser.api.extension.Extension; +import org.geysermc.geyser.api.util.PlatformType; import org.geysermc.geyser.command.GeyserCommandManager; import org.geysermc.geyser.configuration.GeyserConfiguration; import org.geysermc.geyser.dump.BootstrapDumpInfo; @@ -66,7 +67,6 @@ import org.geysermc.geyser.platform.spigot.world.manager.GeyserSpigotNativeWorld import org.geysermc.geyser.platform.spigot.world.manager.GeyserSpigotWorldManager; import org.geysermc.geyser.text.GeyserLocale; import org.geysermc.geyser.util.FileUtils; -import org.jetbrains.annotations.NotNull; import java.io.File; import java.io.IOException; @@ -76,6 +76,7 @@ import java.net.SocketAddress; import java.nio.file.Path; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.UUID; import java.util.logging.Level; @@ -137,6 +138,7 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap { // This is manually done instead of using Bukkit methods to save the config because otherwise comments get removed try { if (!getDataFolder().exists()) { + //noinspection ResultOfMethodCallIgnored getDataFolder().mkdir(); } File configFile = FileUtils.fileOrCopiedFromResource(new File(getDataFolder(), "config.yml"), "config.yml", @@ -272,6 +274,7 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap { } PluginCommand geyserCommand = this.getCommand("geyser"); + Objects.requireNonNull(geyserCommand, "base command cannot be null"); geyserCommand.setExecutor(new GeyserSpigotCommandExecutor(geyser, geyserCommandManager.getCommands())); for (Map.Entry> entry : this.geyserCommandManager.extensionCommands().entrySet()) { @@ -437,7 +440,7 @@ public class GeyserSpigotPlugin extends JavaPlugin implements GeyserBootstrap { return false; } - @NotNull + @NonNull @Override public String getServerBindAddress() { return Bukkit.getIp(); diff --git a/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotVersionChecker.java b/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotVersionChecker.java index 0212ff9b0..057304357 100644 --- a/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotVersionChecker.java +++ b/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/GeyserSpigotVersionChecker.java @@ -39,6 +39,7 @@ import java.lang.reflect.Modifier; public final class GeyserSpigotVersionChecker { private static final String VIAVERSION_DOWNLOAD_URL = "https://ci.viaversion.com/job/ViaVersion/"; + @SuppressWarnings("deprecation") public static void checkForSupportedProtocol(GeyserLogger logger, boolean viaversion) { if (viaversion) { checkViaVersionSupportedVersions(logger); diff --git a/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/PaperAdventure.java b/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/PaperAdventure.java index 5dd16da33..9e0b14b11 100644 --- a/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/PaperAdventure.java +++ b/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/PaperAdventure.java @@ -28,8 +28,8 @@ package org.geysermc.geyser.platform.spigot; import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer; import net.kyori.adventure.text.Component; import org.bukkit.command.CommandSender; +import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.GeyserImpl; -import org.jetbrains.annotations.Nullable; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; @@ -39,8 +39,8 @@ import java.lang.reflect.Method; /** * Utility class for converting our shaded Adventure into the Adventure bundled in Paper. - * - * Code mostly taken from https://github.com/KyoriPowered/adventure-platform/blob/94d5821f2e755170f42bd8a5fe1d5bf6f66d04ad/platform-bukkit/src/main/java/net/kyori/adventure/platform/bukkit/PaperFacet.java#L46 + *

+ * Code mostly taken from here * and the MinecraftReflection class. */ public final class PaperAdventure { @@ -102,7 +102,7 @@ public final class PaperAdventure { SEND_MESSAGE_COMPONENT = playerComponentSendMessage; } - public static Object toNativeComponent(final Component component) { + public static @Nullable Object toNativeComponent(final Component component) { if (NATIVE_GSON_COMPONENT_SERIALIZER_DESERIALIZE_METHOD_BOUND == null) { GeyserImpl.getInstance().getLogger().error("Illegal state where Component serialization was called when it wasn't available!"); return null; diff --git a/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/ReflectedNames.java b/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/ReflectedNames.java index 67e31fea2..275fec657 100644 --- a/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/ReflectedNames.java +++ b/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/ReflectedNames.java @@ -29,8 +29,8 @@ import com.destroystokyo.paper.event.server.PaperServerListPingEvent; import com.destroystokyo.paper.network.StatusClient; import org.bukkit.event.server.ServerListPingEvent; import org.bukkit.util.CachedServerIcon; +import org.checkerframework.checker.nullness.qual.Nullable; -import javax.annotation.Nullable; import java.lang.reflect.Constructor; import java.net.InetAddress; @@ -40,15 +40,8 @@ import java.net.InetAddress; public final class ReflectedNames { static boolean checkPaperPingEvent() { - return classExists("com.destroystokyo.paper.event.server.PaperServerListPingEvent"); - } - - /** - * @return if this class name exists - */ - private static boolean classExists(String clazz) { try { - Class.forName(clazz); + Class.forName("com.destroystokyo.paper.event.server.PaperServerListPingEvent"); return true; } catch (ClassNotFoundException e) { return false; @@ -59,7 +52,7 @@ public final class ReflectedNames { return getConstructor(ServerListPingEvent.class, InetAddress.class, String.class, boolean.class, int.class, int.class) != null; } - static Constructor getOldPaperPingConstructor() { + static @Nullable Constructor getOldPaperPingConstructor() { if (getConstructor(PaperServerListPingEvent.class, StatusClient.class, String.class, int.class, int.class, String.class, int.class, CachedServerIcon.class) != null) { // @NotNull StatusClient client, @NotNull String motd, int numPlayers, int maxPlayers, diff --git a/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/command/GeyserPaperCommandListener.java b/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/command/GeyserPaperCommandListener.java index 9375e3a62..dcec045ab 100644 --- a/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/command/GeyserPaperCommandListener.java +++ b/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/command/GeyserPaperCommandListener.java @@ -39,8 +39,8 @@ import java.util.Map; public final class GeyserPaperCommandListener implements Listener { + @SuppressWarnings("UnstableApiUsage") @EventHandler - @SuppressWarnings("deprecation") // Used to indicate an unstable event public void onCommandSend(AsyncPlayerSendCommandsEvent event) { // Documentation says to check (event.isAsynchronous() || !event.hasFiredAsync()), but as of Paper 1.18.2 // event.hasFiredAsync is never true diff --git a/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/command/GeyserSpigotCommandExecutor.java b/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/command/GeyserSpigotCommandExecutor.java index 61d394214..6780bde17 100644 --- a/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/command/GeyserSpigotCommandExecutor.java +++ b/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/command/GeyserSpigotCommandExecutor.java @@ -29,6 +29,7 @@ import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabExecutor; +import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.command.GeyserCommand; import org.geysermc.geyser.command.GeyserCommandExecutor; @@ -47,7 +48,7 @@ public class GeyserSpigotCommandExecutor extends GeyserCommandExecutor implement } @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + public boolean onCommand(@NonNull CommandSender sender, @NonNull Command command, @NonNull String label, String[] args) { SpigotCommandSource commandSender = new SpigotCommandSource(sender); GeyserSession session = getGeyserSession(commandSender); @@ -78,7 +79,7 @@ public class GeyserSpigotCommandExecutor extends GeyserCommandExecutor implement } @Override - public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { + public List onTabComplete(@NonNull CommandSender sender, @NonNull Command command, @NonNull String label, String[] args) { if (args.length == 1) { return tabComplete(new SpigotCommandSource(sender)); } diff --git a/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/command/SpigotCommandSource.java b/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/command/SpigotCommandSource.java index 95fba707f..365e9ad17 100644 --- a/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/command/SpigotCommandSource.java +++ b/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/command/SpigotCommandSource.java @@ -29,6 +29,7 @@ import net.kyori.adventure.text.Component; import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Player; +import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.geyser.command.GeyserCommandSource; import org.geysermc.geyser.platform.spigot.PaperAdventure; import org.geysermc.geyser.text.GeyserLocale; @@ -48,10 +49,11 @@ public class SpigotCommandSource implements GeyserCommandSource { } @Override - public void sendMessage(String message) { + public void sendMessage(@NonNull String message) { handle.sendMessage(message); } + @SuppressWarnings("deprecation") @Override public void sendMessage(Component message) { if (PaperAdventure.canSendMessageUsingComponent()) { @@ -68,9 +70,11 @@ public class SpigotCommandSource implements GeyserCommandSource { return handle instanceof ConsoleCommandSender; } + @SuppressWarnings("deprecation") @Override public String locale() { if (this.handle instanceof Player player) { + // getLocale() is deprecated on Paper, but not on Spigot return player.getLocale(); } diff --git a/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/world/manager/GeyserSpigotLegacyNativeWorldManager.java b/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/world/manager/GeyserSpigotLegacyNativeWorldManager.java index baffc9679..021db5ec1 100644 --- a/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/world/manager/GeyserSpigotLegacyNativeWorldManager.java +++ b/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/world/manager/GeyserSpigotLegacyNativeWorldManager.java @@ -37,6 +37,7 @@ import org.geysermc.geyser.platform.spigot.GeyserSpigotPlugin; import org.geysermc.geyser.session.GeyserSession; import java.util.List; +import java.util.Objects; /** * Used when block IDs need to be translated to the latest version @@ -52,6 +53,7 @@ public class GeyserSpigotLegacyNativeWorldManager extends GeyserSpigotNativeWorl ProtocolVersion serverVersion = plugin.getServerProtocolVersion(); List protocolList = Via.getManager().getProtocolManager().getProtocolPath(GameProtocol.getJavaProtocolVersion(), serverVersion.getVersion()); + Objects.requireNonNull(protocolList, "protocolList cannot be null"); for (int oldBlockId : allBlockStates) { int newBlockId = oldBlockId; // protocolList should *not* be null; we checked for that before initializing this class diff --git a/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/world/manager/GeyserSpigotNativeWorldManager.java b/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/world/manager/GeyserSpigotNativeWorldManager.java index 6b5d1ea1e..00212663c 100644 --- a/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/world/manager/GeyserSpigotNativeWorldManager.java +++ b/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/world/manager/GeyserSpigotNativeWorldManager.java @@ -28,11 +28,11 @@ package org.geysermc.geyser.platform.spigot.world.manager; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; +import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.adapters.spigot.SpigotAdapters; import org.geysermc.geyser.adapters.spigot.SpigotWorldAdapter; import org.geysermc.geyser.level.block.BlockStateValues; import org.geysermc.geyser.session.GeyserSession; -import org.jetbrains.annotations.Nullable; public class GeyserSpigotNativeWorldManager extends GeyserSpigotWorldManager { protected final SpigotWorldAdapter adapter; diff --git a/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/world/manager/GeyserSpigotWorldManager.java b/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/world/manager/GeyserSpigotWorldManager.java index c8ccfffd7..74f359e02 100644 --- a/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/world/manager/GeyserSpigotWorldManager.java +++ b/bootstrap/spigot/src/main/java/org/geysermc/geyser/platform/spigot/world/manager/GeyserSpigotWorldManager.java @@ -34,21 +34,23 @@ import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.nbt.NbtMap; import org.geysermc.erosion.bukkit.BukkitLecterns; import org.geysermc.erosion.bukkit.BukkitUtils; import org.geysermc.erosion.bukkit.PickBlockUtils; import org.geysermc.erosion.bukkit.SchedulerUtils; +import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.level.GameRule; import org.geysermc.geyser.level.WorldManager; import org.geysermc.geyser.level.block.BlockStateValues; import org.geysermc.geyser.registry.BlockRegistries; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.BlockEntityUtils; -import org.jetbrains.annotations.Nullable; -import javax.annotation.Nonnull; import java.util.List; +import java.util.Objects; import java.util.concurrent.CompletableFuture; /** @@ -128,7 +130,7 @@ public class GeyserSpigotWorldManager extends WorldManager { } } - private Chunk getChunk(World world, int x, int z) { + private @Nullable Chunk getChunk(World world, int x, int z) { if (!world.isChunkLoaded(x, z)) { return null; } @@ -136,6 +138,7 @@ public class GeyserSpigotWorldManager extends WorldManager { } private void sendLecternData(GeyserSession session, Chunk chunk, List blockEntityInfos) { + //noinspection ForLoopReplaceableByForEach - avoid constructing Iterator for (int i = 0; i < blockEntityInfos.size(); i++) { BlockEntityInfo info = blockEntityInfos.get(i); Block block = chunk.getBlock(info.getX(), info.getY(), info.getZ()); @@ -156,19 +159,34 @@ public class GeyserSpigotWorldManager extends WorldManager { } public boolean getGameRuleBool(GeyserSession session, GameRule gameRule) { - String value = Bukkit.getPlayer(session.getPlayerEntity().getUsername()).getWorld().getGameRuleValue(gameRule.getJavaID()); - if (!value.isEmpty()) { - return Boolean.parseBoolean(value); + org.bukkit.GameRule bukkitGameRule = org.bukkit.GameRule.getByName(gameRule.getJavaID()); + if (bukkitGameRule == null) { + GeyserImpl.getInstance().getLogger().debug("Unknown game rule " + gameRule.getJavaID()); + return gameRule.getDefaultBooleanValue(); } + + Player bukkitPlayer = Objects.requireNonNull(Bukkit.getPlayer(session.getPlayerEntity().getUuid())); + Object value = bukkitPlayer.getWorld().getGameRuleValue(bukkitGameRule); + if (value instanceof Boolean booleanValue) { + return booleanValue; + } + GeyserImpl.getInstance().getLogger().debug("Expected a bool for " + gameRule + " but got " + value); return gameRule.getDefaultBooleanValue(); } @Override public int getGameRuleInt(GeyserSession session, GameRule gameRule) { - String value = Bukkit.getPlayer(session.getPlayerEntity().getUsername()).getWorld().getGameRuleValue(gameRule.getJavaID()); - if (!value.isEmpty()) { - return Integer.parseInt(value); + org.bukkit.GameRule bukkitGameRule = org.bukkit.GameRule.getByName(gameRule.getJavaID()); + if (bukkitGameRule == null) { + GeyserImpl.getInstance().getLogger().debug("Unknown game rule " + gameRule.getJavaID()); + return gameRule.getDefaultIntValue(); } + Player bukkitPlayer = Objects.requireNonNull(Bukkit.getPlayer(session.getPlayerEntity().getUuid())); + Object value = bukkitPlayer.getWorld().getGameRuleValue(bukkitGameRule); + if (value instanceof Integer intValue) { + return intValue; + } + GeyserImpl.getInstance().getLogger().debug("Expected an int for " + gameRule + " but got " + value); return gameRule.getDefaultIntValue(); } @@ -179,12 +197,11 @@ public class GeyserSpigotWorldManager extends WorldManager { @Override public boolean hasPermission(GeyserSession session, String permission) { - return Bukkit.getPlayer(session.getPlayerEntity().getUsername()).hasPermission(permission); + return Objects.requireNonNull(Bukkit.getPlayer(session.getPlayerEntity().getUsername())).hasPermission(permission); } - @Nonnull @Override - public CompletableFuture<@Nullable CompoundTag> getPickItemNbt(GeyserSession session, int x, int y, int z, boolean addNbtData) { + public @NonNull CompletableFuture<@Nullable CompoundTag> getPickItemNbt(GeyserSession session, int x, int y, int z, boolean addNbtData) { CompletableFuture<@Nullable CompoundTag> future = new CompletableFuture<>(); Player bukkitPlayer; if ((bukkitPlayer = Bukkit.getPlayer(session.getPlayerEntity().getUuid())) == null) { diff --git a/bootstrap/standalone/src/main/java/org/geysermc/geyser/platform/standalone/GeyserStandaloneBootstrap.java b/bootstrap/standalone/src/main/java/org/geysermc/geyser/platform/standalone/GeyserStandaloneBootstrap.java index b505b361e..9f2208ea8 100644 --- a/bootstrap/standalone/src/main/java/org/geysermc/geyser/platform/standalone/GeyserStandaloneBootstrap.java +++ b/bootstrap/standalone/src/main/java/org/geysermc/geyser/platform/standalone/GeyserStandaloneBootstrap.java @@ -38,6 +38,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.core.Appender; import org.apache.logging.log4j.core.Logger; import org.apache.logging.log4j.core.appender.ConsoleAppender; +import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.geyser.api.util.PlatformType; import org.geysermc.geyser.GeyserBootstrap; import org.geysermc.geyser.GeyserImpl; @@ -51,7 +52,6 @@ import org.geysermc.geyser.platform.standalone.gui.GeyserStandaloneGUI; import org.geysermc.geyser.text.GeyserLocale; import org.geysermc.geyser.util.FileUtils; import org.geysermc.geyser.util.LoopbackUtil; -import org.jetbrains.annotations.NotNull; import java.io.File; import java.io.IOException; @@ -292,7 +292,7 @@ public class GeyserStandaloneBootstrap implements GeyserBootstrap { return new GeyserStandaloneDumpInfo(this); } - @NotNull + @NonNull @Override public String getServerBindAddress() { throw new IllegalStateException(); @@ -325,7 +325,7 @@ public class GeyserStandaloneBootstrap implements GeyserBootstrap { // Get the ignored properties Set ignoredProperties = OBJECT_MAPPER.getSerializationConfig().getAnnotationIntrospector() - .findPropertyIgnorals(beanDescription.getClassInfo()).getIgnored(); + .findPropertyIgnoralByName(OBJECT_MAPPER.getSerializationConfig() ,beanDescription.getClassInfo()).getIgnored(); // Filter properties removing the ignored ones return properties.stream() @@ -340,7 +340,7 @@ public class GeyserStandaloneBootstrap implements GeyserBootstrap { * @param parentObject The object to alter * @param value The new value of the property */ - @SuppressWarnings("unchecked") // Required for enum usage + @SuppressWarnings({"unchecked", "rawtypes"}) // Required for enum usage private static void setConfigOption(BeanPropertyDefinition property, Object parentObject, Object value) { Object parsedValue = value; diff --git a/bootstrap/standalone/src/main/java/org/geysermc/geyser/platform/standalone/gui/ColorPane.java b/bootstrap/standalone/src/main/java/org/geysermc/geyser/platform/standalone/gui/ColorPane.java index 1bdc90123..8e0eadb08 100644 --- a/bootstrap/standalone/src/main/java/org/geysermc/geyser/platform/standalone/gui/ColorPane.java +++ b/bootstrap/standalone/src/main/java/org/geysermc/geyser/platform/standalone/gui/ColorPane.java @@ -28,11 +28,16 @@ package org.geysermc.geyser.platform.standalone.gui; import javax.swing.*; import javax.swing.text.*; import java.awt.*; +import java.io.Serial; /** - * This class was based on this code: https://stackoverflow.com/a/6899478/5299903 + * This class was based on this code */ public class ColorPane extends JTextPane { + + @Serial + private static final long serialVersionUID = 1L; + private static Color colorCurrent = ANSIColor.RESET.getColor(); private String remaining = ""; @@ -62,7 +67,7 @@ public class ColorPane extends JTextPane { int aPos = 0; // current char position in addString int aIndex; // index of next Escape sequence int mIndex; // index of "m" terminating Escape sequence - String tmpString = ""; + String tmpString; boolean stillSearching = true; // true until no more Escape sequences String addString = remaining + s; remaining = ""; diff --git a/bootstrap/standalone/src/main/java/org/geysermc/geyser/platform/standalone/gui/GeyserStandaloneGUI.java b/bootstrap/standalone/src/main/java/org/geysermc/geyser/platform/standalone/gui/GeyserStandaloneGUI.java index af3e1069f..c3e2e10e8 100644 --- a/bootstrap/standalone/src/main/java/org/geysermc/geyser/platform/standalone/gui/GeyserStandaloneGUI.java +++ b/bootstrap/standalone/src/main/java/org/geysermc/geyser/platform/standalone/gui/GeyserStandaloneGUI.java @@ -25,6 +25,7 @@ package org.geysermc.geyser.platform.standalone.gui; +import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserLogger; import org.geysermc.geyser.command.GeyserCommandManager; @@ -64,7 +65,6 @@ public class GeyserStandaloneGUI { private final List ramValues = new ArrayList<>(); private final DefaultTableModel playerTableModel = new DefaultTableModel(); - private final JTable playerTable = new JTable(playerTableModel); /** * Create and show the Geyser-Standalone GUI @@ -158,6 +158,7 @@ public class GeyserStandaloneGUI { playerTableModel.addColumn(GeyserLocale.getLocaleStringLog("geyser.gui.table.ip")); playerTableModel.addColumn(GeyserLocale.getLocaleStringLog("geyser.gui.table.username")); + JTable playerTable = new JTable(playerTableModel); JScrollPane playerScrollPane = new JScrollPane(playerTable); rightContentPane.add(playerScrollPane); @@ -253,12 +254,12 @@ public class GeyserStandaloneGUI { } @Override - public void write(byte[] b, int off, int len) { + public void write(byte @NonNull [] b, int off, int len) { appendConsole(new String(b, off, len)); } @Override - public void write(byte[] b) { + public void write(byte @NonNull[] b) { write(b, 0, b.length); } }; diff --git a/bootstrap/standalone/src/main/java/org/geysermc/geyser/platform/standalone/gui/GraphPanel.java b/bootstrap/standalone/src/main/java/org/geysermc/geyser/platform/standalone/gui/GraphPanel.java index d8fca3e1b..063824218 100644 --- a/bootstrap/standalone/src/main/java/org/geysermc/geyser/platform/standalone/gui/GraphPanel.java +++ b/bootstrap/standalone/src/main/java/org/geysermc/geyser/platform/standalone/gui/GraphPanel.java @@ -29,15 +29,20 @@ import lombok.Setter; import javax.swing.*; import java.awt.*; +import java.io.Serial; import java.util.ArrayList; import java.util.Collection; import java.util.List; /** * This has been modified to fit Geyser more but is based on - * https://gist.github.com/roooodcastro/6325153#gistcomment-3107524 + * this Github gist */ public final class GraphPanel extends JPanel { + + @Serial + private static final long serialVersionUID = 1L; + private final static int padding = 10; private final static int labelPadding = 25; private final static int pointWidth = 4; @@ -103,7 +108,7 @@ public final class GraphPanel extends JPanel { g.drawLine(padding + labelPadding + 1 + pointWidth, y, width - padding, y); g.setColor(Color.BLACK); - final int tickValue = (int) (minScore + ((scoreRange * i) / numberYDivisions)); + final int tickValue = minScore + ((scoreRange * i) / numberYDivisions); final String yLabel = tickValue + ""; final int labelWidth = fontMetrics.stringWidth(yLabel); g.drawString(yLabel, x1 - labelWidth - 5, y + (fontHeight / 2) - 3); diff --git a/bootstrap/velocity/src/main/java/org/geysermc/geyser/platform/velocity/GeyserVelocityInjector.java b/bootstrap/velocity/src/main/java/org/geysermc/geyser/platform/velocity/GeyserVelocityInjector.java index 4ffb286b8..68a9eb40b 100644 --- a/bootstrap/velocity/src/main/java/org/geysermc/geyser/platform/velocity/GeyserVelocityInjector.java +++ b/bootstrap/velocity/src/main/java/org/geysermc/geyser/platform/velocity/GeyserVelocityInjector.java @@ -29,6 +29,7 @@ import com.velocitypowered.api.proxy.ProxyServer; import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.*; import io.netty.channel.local.LocalAddress; +import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.geyser.GeyserBootstrap; import org.geysermc.geyser.network.netty.GeyserInjector; import org.geysermc.geyser.network.netty.LocalServerChannelWrapper; @@ -76,7 +77,7 @@ public class GeyserVelocityInjector extends GeyserInjector { .channel(LocalServerChannelWrapper.class) .childHandler(new ChannelInitializer<>() { @Override - protected void initChannel(Channel ch) throws Exception { + protected void initChannel(@NonNull Channel ch) throws Exception { initChannel.invoke(channelInitializer, ch); if (bootstrap.getGeyserConfig().isDisableCompression() && GeyserVelocityCompressionDisabler.ENABLED) { diff --git a/bootstrap/velocity/src/main/java/org/geysermc/geyser/platform/velocity/GeyserVelocityPlugin.java b/bootstrap/velocity/src/main/java/org/geysermc/geyser/platform/velocity/GeyserVelocityPlugin.java index d7c6c588e..bd3d6085a 100644 --- a/bootstrap/velocity/src/main/java/org/geysermc/geyser/platform/velocity/GeyserVelocityPlugin.java +++ b/bootstrap/velocity/src/main/java/org/geysermc/geyser/platform/velocity/GeyserVelocityPlugin.java @@ -36,11 +36,13 @@ import com.velocitypowered.api.plugin.Plugin; import com.velocitypowered.api.proxy.ProxyServer; import lombok.Getter; import net.kyori.adventure.util.Codec; -import org.geysermc.geyser.api.util.PlatformType; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.GeyserBootstrap; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.api.command.Command; import org.geysermc.geyser.api.extension.Extension; +import org.geysermc.geyser.api.util.PlatformType; import org.geysermc.geyser.command.GeyserCommandManager; import org.geysermc.geyser.configuration.GeyserConfiguration; import org.geysermc.geyser.dump.BootstrapDumpInfo; @@ -49,8 +51,6 @@ import org.geysermc.geyser.ping.IGeyserPingPassthrough; import org.geysermc.geyser.platform.velocity.command.GeyserVelocityCommandExecutor; import org.geysermc.geyser.text.GeyserLocale; import org.geysermc.geyser.util.FileUtils; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import java.io.File; @@ -222,7 +222,7 @@ public class GeyserVelocityPlugin implements GeyserBootstrap { return this.geyserInjector.getServerSocketAddress(); } - @NotNull + @NonNull @Override public String getServerBindAddress() { return proxyServer.getBoundAddress().getHostString(); diff --git a/bootstrap/velocity/src/main/java/org/geysermc/geyser/platform/velocity/command/VelocityCommandSource.java b/bootstrap/velocity/src/main/java/org/geysermc/geyser/platform/velocity/command/VelocityCommandSource.java index 00c99e92b..403e4cb20 100644 --- a/bootstrap/velocity/src/main/java/org/geysermc/geyser/platform/velocity/command/VelocityCommandSource.java +++ b/bootstrap/velocity/src/main/java/org/geysermc/geyser/platform/velocity/command/VelocityCommandSource.java @@ -30,6 +30,7 @@ import com.velocitypowered.api.proxy.ConsoleCommandSource; import com.velocitypowered.api.proxy.Player; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; +import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.geyser.command.GeyserCommandSource; import org.geysermc.geyser.text.GeyserLocale; @@ -56,7 +57,7 @@ public class VelocityCommandSource implements GeyserCommandSource { } @Override - public void sendMessage(String message) { + public void sendMessage(@NonNull String message) { handle.sendMessage(LegacyComponentSerializer.legacy('§').deserialize(message)); } diff --git a/common/src/main/java/org/geysermc/floodgate/crypto/AesKeyProducer.java b/common/src/main/java/org/geysermc/floodgate/crypto/AesKeyProducer.java index 4fae21b32..e39d5119a 100644 --- a/common/src/main/java/org/geysermc/floodgate/crypto/AesKeyProducer.java +++ b/common/src/main/java/org/geysermc/floodgate/crypto/AesKeyProducer.java @@ -32,7 +32,7 @@ import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; public final class AesKeyProducer implements KeyProducer { - public static int KEY_SIZE = 128; + public static final int KEY_SIZE = 128; @Override public SecretKey produce() { diff --git a/common/src/main/java/org/geysermc/floodgate/crypto/FloodgateCipher.java b/common/src/main/java/org/geysermc/floodgate/crypto/FloodgateCipher.java index 2f7b442f4..d3001f374 100644 --- a/common/src/main/java/org/geysermc/floodgate/crypto/FloodgateCipher.java +++ b/common/src/main/java/org/geysermc/floodgate/crypto/FloodgateCipher.java @@ -25,6 +25,7 @@ package org.geysermc.floodgate.crypto; +import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.floodgate.util.InvalidFormatException; import java.security.Key; @@ -97,7 +98,8 @@ public interface FloodgateCipher { * @return the decrypted data in a UTF-8 String * @throws Exception when the decrypting failed */ - default String decryptToString(byte[] data) throws Exception { + @SuppressWarnings("unused") + default @Nullable String decryptToString(byte[] data) throws Exception { byte[] decrypted = decrypt(data); if (decrypted == null) { return null; @@ -113,6 +115,7 @@ public interface FloodgateCipher { * @return the decrypted data in a byte[] * @throws Exception when the decrypting failed */ + @SuppressWarnings("unused") default byte[] decryptFromString(String data) throws Exception { return decrypt(data.getBytes(UTF_8)); } diff --git a/common/src/main/java/org/geysermc/floodgate/crypto/KeyProducer.java b/common/src/main/java/org/geysermc/floodgate/crypto/KeyProducer.java index 4ee00f366..0b8679dad 100644 --- a/common/src/main/java/org/geysermc/floodgate/crypto/KeyProducer.java +++ b/common/src/main/java/org/geysermc/floodgate/crypto/KeyProducer.java @@ -31,7 +31,7 @@ import java.nio.file.Path; import java.security.Key; public interface KeyProducer { - Key produce(); + @SuppressWarnings("unused") Key produce(); Key produceFrom(byte[] keyFileData); default Key produceFrom(Path keyFileLocation) throws IOException { diff --git a/common/src/main/java/org/geysermc/floodgate/news/NewsItem.java b/common/src/main/java/org/geysermc/floodgate/news/NewsItem.java index 8ae28f422..f0dd3fadb 100644 --- a/common/src/main/java/org/geysermc/floodgate/news/NewsItem.java +++ b/common/src/main/java/org/geysermc/floodgate/news/NewsItem.java @@ -109,6 +109,7 @@ public final class NewsItem { return (T) data; } + @SuppressWarnings("unused") public String getRawMessage() { return message; } diff --git a/common/src/main/java/org/geysermc/floodgate/news/NewsItemAction.java b/common/src/main/java/org/geysermc/floodgate/news/NewsItemAction.java index 00e34b622..31995e25d 100644 --- a/common/src/main/java/org/geysermc/floodgate/news/NewsItemAction.java +++ b/common/src/main/java/org/geysermc/floodgate/news/NewsItemAction.java @@ -25,6 +25,8 @@ package org.geysermc.floodgate.news; +import org.checkerframework.checker.nullness.qual.Nullable; + public enum NewsItemAction { ON_SERVER_STARTED, ON_OPERATOR_JOIN, @@ -33,7 +35,7 @@ public enum NewsItemAction { private static final NewsItemAction[] VALUES = values(); - public static NewsItemAction getByName(String actionName) { + public static @Nullable NewsItemAction getByName(String actionName) { for (NewsItemAction type : VALUES) { if (type.name().equalsIgnoreCase(actionName)) { return type; diff --git a/common/src/main/java/org/geysermc/floodgate/news/NewsItemMessage.java b/common/src/main/java/org/geysermc/floodgate/news/NewsItemMessage.java index 9c2f3d15d..ed5d8f949 100644 --- a/common/src/main/java/org/geysermc/floodgate/news/NewsItemMessage.java +++ b/common/src/main/java/org/geysermc/floodgate/news/NewsItemMessage.java @@ -26,6 +26,7 @@ package org.geysermc.floodgate.news; import com.google.gson.JsonArray; +import org.checkerframework.checker.nullness.qual.Nullable; // {} is used for things that have to be filled in by the server, // {@} is for things that have to be filled in by us @@ -49,7 +50,7 @@ public enum NewsItemMessage { this.messageSplitted = messageFormat.split(" "); } - public static NewsItemMessage getById(int id) { + public static @Nullable NewsItemMessage getById(int id) { return VALUES.length > id ? VALUES[id] : null; } diff --git a/common/src/main/java/org/geysermc/floodgate/news/NewsType.java b/common/src/main/java/org/geysermc/floodgate/news/NewsType.java index ed7c1553b..af1d8bc38 100644 --- a/common/src/main/java/org/geysermc/floodgate/news/NewsType.java +++ b/common/src/main/java/org/geysermc/floodgate/news/NewsType.java @@ -26,6 +26,7 @@ package org.geysermc.floodgate.news; import com.google.gson.JsonObject; +import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.floodgate.news.data.*; import java.util.function.Function; @@ -44,7 +45,7 @@ public enum NewsType { this.readFunction = readFunction; } - public static NewsType getByName(String newsType) { + public static @Nullable NewsType getByName(String newsType) { for (NewsType type : VALUES) { if (type.name().equalsIgnoreCase(newsType)) { return type; diff --git a/common/src/main/java/org/geysermc/floodgate/news/data/BuildSpecificData.java b/common/src/main/java/org/geysermc/floodgate/news/data/BuildSpecificData.java index 7f2c7360f..c987dcfbc 100644 --- a/common/src/main/java/org/geysermc/floodgate/news/data/BuildSpecificData.java +++ b/common/src/main/java/org/geysermc/floodgate/news/data/BuildSpecificData.java @@ -56,6 +56,7 @@ public final class BuildSpecificData implements ItemData { (allAffected || buildId > affectedGreaterThan && buildId < affectedLessThan); } + @SuppressWarnings("unused") public String getBranch() { return branch; } diff --git a/common/src/main/java/org/geysermc/floodgate/news/data/ConfigSpecificData.java b/common/src/main/java/org/geysermc/floodgate/news/data/ConfigSpecificData.java index 1479d20a1..6993fe91d 100644 --- a/common/src/main/java/org/geysermc/floodgate/news/data/ConfigSpecificData.java +++ b/common/src/main/java/org/geysermc/floodgate/news/data/ConfigSpecificData.java @@ -51,6 +51,7 @@ public final class ConfigSpecificData implements ItemData { return configSpecificData; } + @SuppressWarnings("unused") public boolean isAffected(Map config) { for (Map.Entry entry : affectedKeys.entrySet()) { if (config.containsKey(entry.getKey())) { diff --git a/common/src/main/java/org/geysermc/floodgate/util/BedrockData.java b/common/src/main/java/org/geysermc/floodgate/util/BedrockData.java index 95fc62229..f0ed6ea00 100644 --- a/common/src/main/java/org/geysermc/floodgate/util/BedrockData.java +++ b/common/src/main/java/org/geysermc/floodgate/util/BedrockData.java @@ -72,6 +72,7 @@ public final class BedrockData implements Cloneable { false, subscribeId, verifyCode); } + @SuppressWarnings("unused") public static BedrockData fromString(String data) { String[] split = data.split("\0"); if (split.length != EXPECTED_LENGTH) { @@ -92,6 +93,7 @@ public final class BedrockData implements Cloneable { dataLength); } + @SuppressWarnings("unused") public boolean hasPlayerLink() { return linkedPlayer != null; } diff --git a/common/src/main/java/org/geysermc/floodgate/util/InvalidFormatException.java b/common/src/main/java/org/geysermc/floodgate/util/InvalidFormatException.java index e0630d48c..a2526700e 100644 --- a/common/src/main/java/org/geysermc/floodgate/util/InvalidFormatException.java +++ b/common/src/main/java/org/geysermc/floodgate/util/InvalidFormatException.java @@ -26,6 +26,9 @@ package org.geysermc.floodgate.util; public class InvalidFormatException extends Exception { + + private static final long serialVersionUID = 1L; + public InvalidFormatException(String message) { super(message); } diff --git a/common/src/main/java/org/geysermc/floodgate/util/LinkedPlayer.java b/common/src/main/java/org/geysermc/floodgate/util/LinkedPlayer.java index 681080a30..0a131071e 100644 --- a/common/src/main/java/org/geysermc/floodgate/util/LinkedPlayer.java +++ b/common/src/main/java/org/geysermc/floodgate/util/LinkedPlayer.java @@ -28,6 +28,7 @@ package org.geysermc.floodgate.util; import lombok.AccessLevel; import lombok.Getter; import lombok.RequiredArgsConstructor; +import org.checkerframework.checker.nullness.qual.Nullable; import java.util.UUID; @@ -56,7 +57,7 @@ public final class LinkedPlayer implements Cloneable { return new LinkedPlayer(javaUsername, javaUniqueId, bedrockId); } - public static LinkedPlayer fromString(String data) { + public static @Nullable LinkedPlayer fromString(String data) { String[] split = data.split(";"); if (split.length != 3) { return null; diff --git a/common/src/main/java/org/geysermc/floodgate/util/UiProfile.java b/common/src/main/java/org/geysermc/floodgate/util/UiProfile.java index d93042277..4438ae67f 100644 --- a/common/src/main/java/org/geysermc/floodgate/util/UiProfile.java +++ b/common/src/main/java/org/geysermc/floodgate/util/UiProfile.java @@ -25,6 +25,8 @@ package org.geysermc.floodgate.util; +import org.checkerframework.checker.nullness.qual.NonNull; + public enum UiProfile { CLASSIC, POCKET; @@ -37,7 +39,7 @@ public enum UiProfile { * @param id the UiProfile identifier * @return The UiProfile or {@link #CLASSIC} if the UiProfile wasn't found */ - public static UiProfile fromId(int id) { + public static @NonNull UiProfile fromId(int id) { return VALUES.length > id ? VALUES[id] : VALUES[0]; } } diff --git a/common/src/main/java/org/geysermc/floodgate/util/WebsocketEventType.java b/common/src/main/java/org/geysermc/floodgate/util/WebsocketEventType.java index 61e6c63b1..dffbabaaf 100644 --- a/common/src/main/java/org/geysermc/floodgate/util/WebsocketEventType.java +++ b/common/src/main/java/org/geysermc/floodgate/util/WebsocketEventType.java @@ -25,6 +25,8 @@ package org.geysermc.floodgate.util; +import org.checkerframework.checker.nullness.qual.Nullable; + public enum WebsocketEventType { /** * Sent once we successfully connected to the server @@ -81,7 +83,7 @@ public enum WebsocketEventType { this.id = id; } - public static WebsocketEventType fromId(int id) { + public static @Nullable WebsocketEventType fromId(int id) { return VALUES.length > id ? VALUES[id] : null; } diff --git a/core/src/main/java/org/geysermc/geyser/GeyserBootstrap.java b/core/src/main/java/org/geysermc/geyser/GeyserBootstrap.java index 1827cfb36..4dbc1dca3 100644 --- a/core/src/main/java/org/geysermc/geyser/GeyserBootstrap.java +++ b/core/src/main/java/org/geysermc/geyser/GeyserBootstrap.java @@ -152,7 +152,7 @@ public interface GeyserBootstrap { * @param resource Resource to get * @return InputStream of the given resource */ - default @NonNull InputStream getResource(String resource) { + default @NonNull InputStream getResourceOrThrow(@NonNull String resource) { InputStream stream = getResourceOrNull(resource); if (stream == null) { throw new AssertionError("Unable to find resource: " + resource); diff --git a/core/src/main/java/org/geysermc/geyser/GeyserImpl.java b/core/src/main/java/org/geysermc/geyser/GeyserImpl.java index 185ab7c2a..aef2288d6 100644 --- a/core/src/main/java/org/geysermc/geyser/GeyserImpl.java +++ b/core/src/main/java/org/geysermc/geyser/GeyserImpl.java @@ -71,6 +71,7 @@ import org.geysermc.geyser.level.WorldManager; import org.geysermc.geyser.network.netty.GeyserServer; import org.geysermc.geyser.registry.BlockRegistries; import org.geysermc.geyser.registry.Registries; +import org.geysermc.geyser.registry.provider.ProviderSupplier; import org.geysermc.geyser.scoreboard.ScoreboardUpdater; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.PendingMicrosoftAuthentication; @@ -622,7 +623,7 @@ public class GeyserImpl implements GeyserApi { */ public boolean isProductionEnvironment() { // First is if Blossom runs, second is if Blossom doesn't run - // noinspection ConstantConditions - changes in production + //noinspection ConstantConditions,MismatchedStringCase - changes in production return !("git-local/dev-0000000".equals(GeyserImpl.GIT_VERSION) || "${gitVersion}".equals(GeyserImpl.GIT_VERSION)); } @@ -638,8 +639,13 @@ public class GeyserImpl implements GeyserApi { } @Override + @SuppressWarnings("unchecked") public @NonNull R provider(@NonNull Class apiClass, @Nullable Object... args) { - return (R) Registries.PROVIDERS.get(apiClass).create(args); + ProviderSupplier provider = Registries.PROVIDERS.get(apiClass); + if (provider == null) { + throw new IllegalArgumentException("No provider found for " + apiClass); + } + return (R) provider.create(args); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/GeyserLogger.java b/core/src/main/java/org/geysermc/geyser/GeyserLogger.java index 88220eec9..aa79e3630 100644 --- a/core/src/main/java/org/geysermc/geyser/GeyserLogger.java +++ b/core/src/main/java/org/geysermc/geyser/GeyserLogger.java @@ -26,9 +26,10 @@ package org.geysermc.geyser; import net.kyori.adventure.text.Component; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.command.GeyserCommandSource; -import javax.annotation.Nullable; public interface GeyserLogger extends GeyserCommandSource { @@ -119,7 +120,7 @@ public interface GeyserLogger extends GeyserCommandSource { } @Override - default void sendMessage(String message) { + default void sendMessage(@NonNull String message) { info(message); } diff --git a/core/src/main/java/org/geysermc/geyser/GeyserMain.java b/core/src/main/java/org/geysermc/geyser/GeyserMain.java index 4e60a79b8..05cbebed4 100644 --- a/core/src/main/java/org/geysermc/geyser/GeyserMain.java +++ b/core/src/main/java/org/geysermc/geyser/GeyserMain.java @@ -30,6 +30,7 @@ import java.io.InputStream; import java.lang.reflect.Method; import java.nio.charset.StandardCharsets; import java.util.Locale; +import java.util.Objects; import java.util.Scanner; public class GeyserMain { @@ -61,8 +62,8 @@ public class GeyserMain { helpStream = GeyserMain.class.getClassLoader().getResourceAsStream("languages/run-help/en_US.txt"); } - Scanner help = new Scanner(helpStream, StandardCharsets.UTF_8).useDelimiter("\\Z"); - String line = ""; + Scanner help = new Scanner(Objects.requireNonNull(helpStream), StandardCharsets.UTF_8).useDelimiter("\\Z"); + String line; while (help.hasNext()) { line = help.next(); diff --git a/core/src/main/java/org/geysermc/geyser/command/GeyserCommand.java b/core/src/main/java/org/geysermc/geyser/command/GeyserCommand.java index 5808dbc2c..47d57e73f 100644 --- a/core/src/main/java/org/geysermc/geyser/command/GeyserCommand.java +++ b/core/src/main/java/org/geysermc/geyser/command/GeyserCommand.java @@ -29,10 +29,10 @@ import lombok.Getter; import lombok.RequiredArgsConstructor; import lombok.experimental.Accessors; import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.api.command.Command; import org.geysermc.geyser.session.GeyserSession; -import javax.annotation.Nullable; import java.util.Collections; import java.util.List; @@ -73,15 +73,6 @@ public abstract class GeyserCommand implements Command { return Collections.emptyList(); } - /** - * Shortcut to {@link #subCommands()} ()}{@code .isEmpty()}. - * - * @return true if there are subcommand present for this command. - */ - public boolean hasSubCommands() { - return !this.subCommands().isEmpty(); - } - public void setAliases(List aliases) { this.aliases = aliases; } diff --git a/core/src/main/java/org/geysermc/geyser/command/GeyserCommandExecutor.java b/core/src/main/java/org/geysermc/geyser/command/GeyserCommandExecutor.java index a9b1c734f..37d2ef4fb 100644 --- a/core/src/main/java/org/geysermc/geyser/command/GeyserCommandExecutor.java +++ b/core/src/main/java/org/geysermc/geyser/command/GeyserCommandExecutor.java @@ -26,11 +26,11 @@ package org.geysermc.geyser.command; import lombok.AllArgsConstructor; +import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.api.command.Command; import org.geysermc.geyser.session.GeyserSession; -import javax.annotation.Nullable; import java.util.ArrayList; import java.util.Collections; import java.util.List; diff --git a/core/src/main/java/org/geysermc/geyser/command/GeyserCommandManager.java b/core/src/main/java/org/geysermc/geyser/command/GeyserCommandManager.java index 373395ea2..d646845c7 100644 --- a/core/src/main/java/org/geysermc/geyser/command/GeyserCommandManager.java +++ b/core/src/main/java/org/geysermc/geyser/command/GeyserCommandManager.java @@ -29,6 +29,7 @@ import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import lombok.Getter; import lombok.RequiredArgsConstructor; import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.api.util.PlatformType; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.api.command.Command; @@ -53,8 +54,6 @@ import org.geysermc.geyser.event.type.GeyserDefineCommandsEventImpl; import org.geysermc.geyser.extension.command.GeyserExtensionCommand; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.text.GeyserLocale; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.Collections; import java.util.HashMap; @@ -136,12 +135,12 @@ public class GeyserCommandManager { } } - @NotNull + @NonNull public Map commands() { return Collections.unmodifiableMap(this.commands); } - @NotNull + @NonNull public Map> extensionCommands() { return Collections.unmodifiableMap(this.extensionCommands); } diff --git a/core/src/main/java/org/geysermc/geyser/command/defaults/ConnectionTestCommand.java b/core/src/main/java/org/geysermc/geyser/command/defaults/ConnectionTestCommand.java index 12294ae06..4cda72c9b 100644 --- a/core/src/main/java/org/geysermc/geyser/command/defaults/ConnectionTestCommand.java +++ b/core/src/main/java/org/geysermc/geyser/command/defaults/ConnectionTestCommand.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.command.defaults; import com.fasterxml.jackson.databind.JsonNode; +import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.api.util.PlatformType; import org.geysermc.geyser.command.GeyserCommand; @@ -34,7 +35,6 @@ import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.text.GeyserLocale; import org.geysermc.geyser.util.LoopbackUtil; import org.geysermc.geyser.util.WebUtils; -import org.jetbrains.annotations.Nullable; import java.util.Random; import java.util.concurrent.CompletableFuture; diff --git a/core/src/main/java/org/geysermc/geyser/command/defaults/DumpCommand.java b/core/src/main/java/org/geysermc/geyser/command/defaults/DumpCommand.java index 544be7446..b3fee375f 100644 --- a/core/src/main/java/org/geysermc/geyser/command/defaults/DumpCommand.java +++ b/core/src/main/java/org/geysermc/geyser/command/defaults/DumpCommand.java @@ -98,7 +98,7 @@ public class DumpCommand extends GeyserCommand { return; } - String uploadedDumpUrl = ""; + String uploadedDumpUrl; if (offlineDump) { sender.sendMessage(GeyserLocale.getPlayerLocaleString("geyser.commands.dump.writing", sender.locale())); diff --git a/core/src/main/java/org/geysermc/geyser/command/defaults/ExtensionsCommand.java b/core/src/main/java/org/geysermc/geyser/command/defaults/ExtensionsCommand.java index 30d422b23..df33437d9 100644 --- a/core/src/main/java/org/geysermc/geyser/command/defaults/ExtensionsCommand.java +++ b/core/src/main/java/org/geysermc/geyser/command/defaults/ExtensionsCommand.java @@ -25,6 +25,7 @@ package org.geysermc.geyser.command.defaults; +import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.api.extension.Extension; import org.geysermc.geyser.command.GeyserCommand; @@ -32,7 +33,6 @@ import org.geysermc.geyser.command.GeyserCommandSource; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.text.ChatColor; import org.geysermc.geyser.text.GeyserLocale; -import org.jetbrains.annotations.Nullable; import java.util.Comparator; import java.util.List; diff --git a/core/src/main/java/org/geysermc/geyser/command/defaults/VersionCommand.java b/core/src/main/java/org/geysermc/geyser/command/defaults/VersionCommand.java index b263d6727..eb2e8ff47 100644 --- a/core/src/main/java/org/geysermc/geyser/command/defaults/VersionCommand.java +++ b/core/src/main/java/org/geysermc/geyser/command/defaults/VersionCommand.java @@ -27,8 +27,8 @@ package org.geysermc.geyser.command.defaults; import org.cloudburstmc.protocol.bedrock.codec.BedrockCodec; import org.geysermc.geyser.Constants; -import org.geysermc.geyser.api.util.PlatformType; import org.geysermc.geyser.GeyserImpl; +import org.geysermc.geyser.api.util.PlatformType; import org.geysermc.geyser.command.GeyserCommand; import org.geysermc.geyser.command.GeyserCommandSource; import org.geysermc.geyser.network.GameProtocol; @@ -37,7 +37,6 @@ import org.geysermc.geyser.text.ChatColor; import org.geysermc.geyser.text.GeyserLocale; import org.geysermc.geyser.util.WebUtils; -import java.io.IOException; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.List; @@ -77,7 +76,7 @@ public class VersionCommand extends GeyserCommand { sender.sendMessage(GeyserLocale.getPlayerLocaleString("geyser.commands.version.checking", sender.locale())); try { String buildXML = WebUtils.getBody("https://ci.opencollab.dev/job/GeyserMC/job/Geyser/job/" + - URLEncoder.encode(GeyserImpl.BRANCH, StandardCharsets.UTF_8.toString()) + "/lastSuccessfulBuild/api/xml?xpath=//buildNumber"); + URLEncoder.encode(GeyserImpl.BRANCH, StandardCharsets.UTF_8) + "/lastSuccessfulBuild/api/xml?xpath=//buildNumber"); if (buildXML.startsWith("")) { int latestBuildNum = Integer.parseInt(buildXML.replaceAll("<(\\\\)?(/)?buildNumber>", "").trim()); int buildNum = this.geyser.buildNumber(); @@ -90,7 +89,7 @@ public class VersionCommand extends GeyserCommand { } else { throw new AssertionError("buildNumber missing"); } - } catch (IOException e) { + } catch (Exception e) { GeyserImpl.getInstance().getLogger().error(GeyserLocale.getLocaleStringLog("geyser.commands.version.failed"), e); sender.sendMessage(ChatColor.RED + GeyserLocale.getPlayerLocaleString("geyser.commands.version.failed", sender.locale())); } diff --git a/core/src/main/java/org/geysermc/geyser/configuration/GeyserConfiguration.java b/core/src/main/java/org/geysermc/geyser/configuration/GeyserConfiguration.java index 51cd7d4ae..f9bb15b32 100644 --- a/core/src/main/java/org/geysermc/geyser/configuration/GeyserConfiguration.java +++ b/core/src/main/java/org/geysermc/geyser/configuration/GeyserConfiguration.java @@ -52,6 +52,7 @@ public interface GeyserConfiguration { List getSavedUserLogins(); + @SuppressWarnings("BooleanMethodIsAlwaysInverted") boolean isCommandSuggestions(); @JsonIgnore @@ -93,6 +94,7 @@ public interface GeyserConfiguration { boolean isForceResourcePacks(); + @SuppressWarnings("BooleanMethodIsAlwaysInverted") boolean isXboxAchievementsEnabled(); int getCacheImages(); diff --git a/core/src/main/java/org/geysermc/geyser/configuration/GeyserJacksonConfiguration.java b/core/src/main/java/org/geysermc/geyser/configuration/GeyserJacksonConfiguration.java index 95ac7b1de..0874daa07 100644 --- a/core/src/main/java/org/geysermc/geyser/configuration/GeyserJacksonConfiguration.java +++ b/core/src/main/java/org/geysermc/geyser/configuration/GeyserJacksonConfiguration.java @@ -34,6 +34,7 @@ import com.fasterxml.jackson.databind.JsonDeserializer; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import lombok.Getter; import lombok.Setter; +import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.api.network.AuthType; import org.geysermc.geyser.network.CIDRMatcher; @@ -158,7 +159,7 @@ public abstract class GeyserJacksonConfiguration implements GeyserConfiguration private String address = "0.0.0.0"; @Override - public String address() { + public @NonNull String address() { return address; } @@ -260,7 +261,7 @@ public abstract class GeyserJacksonConfiguration implements GeyserConfiguration private AuthType authType = AuthType.ONLINE; @Override - public AuthType authType() { + public @NonNull AuthType authType() { return authType; } diff --git a/core/src/main/java/org/geysermc/geyser/dump/DumpInfo.java b/core/src/main/java/org/geysermc/geyser/dump/DumpInfo.java index 290a0e3ad..818607314 100644 --- a/core/src/main/java/org/geysermc/geyser/dump/DumpInfo.java +++ b/core/src/main/java/org/geysermc/geyser/dump/DumpInfo.java @@ -33,7 +33,6 @@ import com.google.common.io.ByteSource; import com.google.common.io.Files; import it.unimi.dsi.fastutil.objects.Object2IntMap; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; -import lombok.AllArgsConstructor; import lombok.Getter; import org.cloudburstmc.protocol.bedrock.codec.BedrockCodec; import org.geysermc.floodgate.util.DeviceOs; @@ -106,8 +105,8 @@ public class DumpInfo { // https://stackoverflow.com/questions/304268/getting-a-files-md5-checksum-in-java File file = new File(DumpInfo.class.getProtectionDomain().getCodeSource().getLocation().toURI()); ByteSource byteSource = Files.asByteSource(file); - // Jenkins uses MD5 for its hash - //noinspection UnstableApiUsage + // Jenkins uses MD5 for its hash - TODO remove + //noinspection UnstableApiUsage,deprecation md5Hash = byteSource.hash(Hashing.md5()).toString(); //noinspection UnstableApiUsage sha256Hash = byteSource.hash(Hashing.sha256()).toString(); @@ -118,7 +117,7 @@ public class DumpInfo { } this.hashInfo = new HashInfo(md5Hash, sha256Hash); - this.ramInfo = new DumpInfo.RamInfo(); + this.ramInfo = new RamInfo(); if (addLog) { this.logsInfo = new LogsInfo(); @@ -202,7 +201,7 @@ public class DumpInfo { private boolean checkDockerBasic() { try { String OS = System.getProperty("os.name").toLowerCase(); - if (OS.indexOf("nix") >= 0 || OS.indexOf("nux") >= 0 || OS.indexOf("aix") > 0) { + if (OS.contains("nix") || OS.contains("nux") || OS.indexOf("aix") > 0) { String output = new String(java.nio.file.Files.readAllBytes(Paths.get("/proc/1/cgroup"))); if (output.contains("docker")) { @@ -259,60 +258,30 @@ public class DumpInfo { } } - @AllArgsConstructor - @Getter - public static class HashInfo { - private final String md5Hash; - private final String sha256Hash; + public record HashInfo(String md5Hash, String sha256Hash) { } - @Getter - public static class RamInfo { - private final long free; - private final long total; - private final long max; - - RamInfo() { - this.free = Runtime.getRuntime().freeMemory() / MEGABYTE; - this.total = Runtime.getRuntime().totalMemory() / MEGABYTE; - this.max = Runtime.getRuntime().maxMemory() / MEGABYTE; + public record RamInfo(long free, long total, long max) { + public RamInfo() { + this(Runtime.getRuntime().freeMemory() / MEGABYTE, + Runtime.getRuntime().totalMemory() / MEGABYTE, + Runtime.getRuntime().maxMemory() / MEGABYTE); } } /** * E.G. `-Xmx1024M` - all runtime JVM flags on this machine */ - @Getter - public static class FlagsInfo { - private final List flags; - - FlagsInfo() { - this.flags = ManagementFactory.getRuntimeMXBean().getInputArguments(); + public record FlagsInfo(List flags) { + public FlagsInfo() { + this(ManagementFactory.getRuntimeMXBean().getInputArguments()); } } - @Getter - @AllArgsConstructor - public static class ExtensionInfo { - public boolean enabled; - public String name; - public String version; - public String apiVersion; - public String main; - public List authors; + public record ExtensionInfo(boolean enabled, String name, String version, String apiVersion, String main, List authors) { } - @Getter - @AllArgsConstructor - public static class GitInfo { - private final String buildNumber; - @JsonProperty("git.commit.id.abbrev") - private final String commitHashAbbrev; - @JsonProperty("git.commit.id") - private final String commitHash; - @JsonProperty("git.branch") - private final String branchName; - @JsonProperty("git.remote.origin.url") - private final String originUrl; + public record GitInfo(String buildNumber, @JsonProperty("git.commit.id.abbrev") String commitHashAbbrev, @JsonProperty("git.commit.id") String commitHash, + @JsonProperty("git.branch") String branchName, @JsonProperty("git.remote.origin.url") String originUrl) { } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinition.java b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinition.java index 566b3daff..8b430d559 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/EntityDefinition.java +++ b/core/src/main/java/org/geysermc/geyser/entity/EntityDefinition.java @@ -59,6 +59,7 @@ public record EntityDefinition(EntityFactory factory, Entit return new Builder<>(factory); } + @SuppressWarnings("unchecked") public void translateMetadata(T entity, EntityMetadata> metadata) { EntityMetadataTranslator>> translator = (EntityMetadataTranslator>>) this.translators.get(metadata.getId()); if (translator == null) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/attribute/GeyserAttributeType.java b/core/src/main/java/org/geysermc/geyser/entity/attribute/GeyserAttributeType.java index 92bfb7585..234c1afe9 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/attribute/GeyserAttributeType.java +++ b/core/src/main/java/org/geysermc/geyser/entity/attribute/GeyserAttributeType.java @@ -25,6 +25,7 @@ package org.geysermc.geyser.entity.attribute; +import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.protocol.bedrock.data.AttributeData; import lombok.AllArgsConstructor; import lombok.Getter; @@ -69,7 +70,7 @@ public enum GeyserAttributeType { return getAttribute(value, maximum); } - public AttributeData getAttribute(float value, float maximum) { + public @Nullable AttributeData getAttribute(float value, float maximum) { if (bedrockIdentifier == null) { return null; } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/AreaEffectCloudEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/AreaEffectCloudEntity.java index fcd4f2160..84dfae468 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/AreaEffectCloudEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/AreaEffectCloudEntity.java @@ -34,7 +34,6 @@ import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.registry.Registries; -import org.geysermc.geyser.registry.type.ParticleMapping; import org.geysermc.geyser.session.GeyserSession; import java.util.UUID; diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java index 5ca739f61..a2b7cc6ec 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/Entity.java @@ -36,6 +36,7 @@ import lombok.AccessLevel; import lombok.Getter; import lombok.Setter; import net.kyori.adventure.text.Component; +import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.math.vector.Vector2f; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; @@ -580,7 +581,7 @@ public class Entity implements GeyserEntity { } @SuppressWarnings("unchecked") - public I as(Class entityClass) { + public @Nullable I as(Class entityClass) { return entityClass.isInstance(this) ? (I) this : null; } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/LivingEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/LivingEntity.java index be38098ac..245b99cef 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/LivingEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/LivingEntity.java @@ -38,6 +38,7 @@ import com.github.steveice10.opennbt.tag.builtin.StringTag; import lombok.AccessLevel; import lombok.Getter; import lombok.Setter; +import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.math.vector.Vector3i; import org.cloudburstmc.protocol.bedrock.data.AttributeData; @@ -120,7 +121,7 @@ public class LivingEntity extends Entity { session.sendUpstreamPacket(attributesPacket); } - public Vector3i setBedPosition(EntityMetadata, ?> entityMetadata) { + public @Nullable Vector3i setBedPosition(EntityMetadata, ?> entityMetadata) { Optional optionalPos = entityMetadata.getValue(); if (optionalPos.isPresent()) { Vector3i bedPosition = optionalPos.get(); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEntity.java index 72ae88310..60840e65b 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/ThrowableEntity.java @@ -51,7 +51,6 @@ public class ThrowableEntity extends Entity implements Tickable { /** * Updates the position for the Bedrock client. - * * Java clients assume the next positions of moving items. Bedrock needs to be explicitly told positions */ @Override diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/AbstractFishEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/AbstractFishEntity.java index ec0caac33..9cc3a006e 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/AbstractFishEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/AbstractFishEntity.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.entity.type.living; import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; +import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.EntityDefinition; @@ -34,7 +35,6 @@ import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.EntityUtils; import org.geysermc.geyser.util.InteractionResult; -import javax.annotation.Nonnull; import java.util.UUID; public class AbstractFishEntity extends WaterEntity { @@ -48,9 +48,9 @@ public class AbstractFishEntity extends WaterEntity { setFlag(EntityFlag.HAS_GRAVITY, false); } - @Nonnull + @NonNull @Override - protected InteractionResult mobInteract(Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { if (EntityUtils.attemptToBucket(itemInHand)) { return InteractionResult.SUCCESS; } else { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/AllayEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/AllayEntity.java index f39200eed..48d633e5d 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/AllayEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/AllayEntity.java @@ -27,6 +27,7 @@ package org.geysermc.geyser.entity.type.living; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; +import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.EntityDefinition; @@ -36,7 +37,6 @@ import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; -import javax.annotation.Nonnull; import java.util.UUID; public class AllayEntity extends MobEntity { @@ -54,9 +54,9 @@ public class AllayEntity extends MobEntity { this.canDuplicate = entityMetadata.getPrimitiveValue(); } - @Nonnull + @NonNull @Override - protected InteractiveTag testMobInteraction(@Nonnull Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { if (this.canDuplicate && getFlag(EntityFlag.DANCING) && isDuplicationItem(itemInHand)) { // Maybe better as another tag? return InteractiveTag.GIVE_ITEM_TO_ALLAY; @@ -70,9 +70,9 @@ public class AllayEntity extends MobEntity { } } - @Nonnull + @NonNull @Override - protected InteractionResult mobInteract(@Nonnull Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { if (this.canDuplicate && getFlag(EntityFlag.DANCING) && isDuplicationItem(itemInHand)) { //TOCHECK sound return InteractionResult.SUCCESS; diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/ArmorStandEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/ArmorStandEntity.java index c9018fe76..c64776f18 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/ArmorStandEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/ArmorStandEntity.java @@ -70,7 +70,7 @@ public class ArmorStandEntity extends LivingEntity { private boolean primaryEntity = true; /** * Whether the entity's position must be updated to included the offset. - * + *

* This should be true when the Java server marks the armor stand as invisible, but we shrink the entity * to allow the nametag to appear. Basically: * - Is visible: this is irrelevant (false) @@ -207,7 +207,7 @@ public class ArmorStandEntity extends LivingEntity { * @param negativeZToggle the flag to set true if the Z value of rotation is negative * @param rotation the Java rotation value */ - private void onRotationUpdate(EntityDataType dataLeech, EntityFlag negativeXToggle, EntityFlag negativeYToggle, EntityFlag negativeZToggle, Vector3f rotation) { + private void onRotationUpdate(EntityDataType dataLeech, EntityFlag negativeXToggle, EntityFlag negativeYToggle, EntityFlag negativeZToggle, Vector3f rotation) { // Indicate that rotation should be checked setFlag(EntityFlag.BRIBED, true); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/DolphinEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/DolphinEntity.java index 7c1d8efc7..f0348bcaf 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/DolphinEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/DolphinEntity.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.entity.type.living; import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; +import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.inventory.GeyserItemStack; @@ -33,7 +34,6 @@ import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; -import javax.annotation.Nonnull; import java.util.UUID; public class DolphinEntity extends WaterEntity { @@ -46,18 +46,18 @@ public class DolphinEntity extends WaterEntity { return true; } - @Nonnull + @NonNull @Override - protected InteractiveTag testMobInteraction(Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { if (!itemInHand.isEmpty() && session.getTagCache().isFish(itemInHand)) { return InteractiveTag.FEED; } return super.testMobInteraction(hand, itemInHand); } - @Nonnull + @NonNull @Override - protected InteractionResult mobInteract(Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { if (!itemInHand.isEmpty() && session.getTagCache().isFish(itemInHand)) { // Feed return InteractionResult.SUCCESS; diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/IronGolemEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/IronGolemEntity.java index 1f653decd..7afa4b436 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/IronGolemEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/IronGolemEntity.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.entity.type.living; import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; +import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; @@ -35,7 +36,6 @@ import org.geysermc.geyser.item.Items; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.InteractionResult; -import javax.annotation.Nonnull; import java.util.UUID; public class IronGolemEntity extends GolemEntity { @@ -51,9 +51,9 @@ public class IronGolemEntity extends GolemEntity { maxHealth = 100f; } - @Nonnull + @NonNull @Override - protected InteractionResult mobInteract(@Nonnull Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { if (itemInHand.asItem() == Items.IRON_INGOT) { if (health < maxHealth) { // Healing the iron golem diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/MobEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/MobEntity.java index 60a9a1474..0ac81c957 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/MobEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/MobEntity.java @@ -28,6 +28,7 @@ package org.geysermc.geyser.entity.type.living; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; import lombok.Getter; +import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; @@ -40,7 +41,6 @@ import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; -import javax.annotation.Nonnull; import java.util.UUID; public class MobEntity extends LivingEntity { @@ -133,13 +133,13 @@ public class MobEntity extends LivingEntity { return InteractionResult.PASS; } - @Nonnull - protected InteractiveTag testMobInteraction(@Nonnull Hand hand, @Nonnull GeyserItemStack itemInHand) { + @NonNull + protected InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { return InteractiveTag.NONE; } - @Nonnull - protected InteractionResult mobInteract(@Nonnull Hand hand, @Nonnull GeyserItemStack itemInHand) { + @NonNull + protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { return InteractionResult.PASS; } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/SnowGolemEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/SnowGolemEntity.java index ced274185..7f0699415 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/SnowGolemEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/SnowGolemEntity.java @@ -27,6 +27,7 @@ package org.geysermc.geyser.entity.type.living; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; +import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.EntityDefinition; @@ -36,7 +37,6 @@ import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; -import javax.annotation.Nonnull; import java.util.UUID; public class SnowGolemEntity extends GolemEntity { @@ -51,9 +51,9 @@ public class SnowGolemEntity extends GolemEntity { setFlag(EntityFlag.SHEARED, (xd & 0x10) != 0x10); } - @Nonnull + @NonNull @Override - protected InteractiveTag testMobInteraction(@Nonnull Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { if (Items.SHEARS == itemInHand.asItem() && isAlive() && !getFlag(EntityFlag.SHEARED)) { // Shearing the snow golem return InteractiveTag.SHEAR; @@ -61,9 +61,9 @@ public class SnowGolemEntity extends GolemEntity { return InteractiveTag.NONE; } - @Nonnull + @NonNull @Override - protected InteractionResult mobInteract(@Nonnull Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { if (Items.SHEARS == itemInHand.asItem() && isAlive() && !getFlag(EntityFlag.SHEARED)) { // Shearing the snow golem return InteractionResult.SUCCESS; diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/TadpoleEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/TadpoleEntity.java index 47ddb9126..7094c431e 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/TadpoleEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/TadpoleEntity.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.entity.type.living; import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; +import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.inventory.GeyserItemStack; @@ -34,7 +35,6 @@ import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; -import javax.annotation.Nonnull; import java.util.UUID; public class TadpoleEntity extends AbstractFishEntity { @@ -42,18 +42,18 @@ public class TadpoleEntity extends AbstractFishEntity { super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); } - @Nonnull + @NonNull @Override - protected InteractiveTag testMobInteraction(@Nonnull Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { if (isFood(itemInHand)) { return InteractiveTag.FEED; } return super.testMobInteraction(hand, itemInHand); } - @Nonnull + @NonNull @Override - protected InteractionResult mobInteract(@Nonnull Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { if (isFood(itemInHand)) { //TODO particles return InteractionResult.SUCCESS; diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/AnimalEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/AnimalEntity.java index 2c46da13b..7278709ce 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/AnimalEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/AnimalEntity.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.entity.type.living.animal; import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; +import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityEventType; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; @@ -38,7 +39,6 @@ import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; -import javax.annotation.Nonnull; import java.util.UUID; public class AnimalEntity extends AgeableEntity { @@ -59,18 +59,18 @@ public class AnimalEntity extends AgeableEntity { return item == Items.WHEAT; } - @Nonnull + @NonNull @Override - protected InteractiveTag testMobInteraction(@Nonnull Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { if (canEat(itemInHand)) { return InteractiveTag.FEED; } return super.testMobInteraction(hand, itemInHand); } - @Nonnull + @NonNull @Override - protected InteractionResult mobInteract(@Nonnull Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { if (canEat(itemInHand)) { // FEED if (getFlag(EntityFlag.BABY)) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/AxolotlEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/AxolotlEntity.java index 06eb0791b..85b2afc14 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/AxolotlEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/AxolotlEntity.java @@ -28,6 +28,7 @@ package org.geysermc.geyser.entity.type.living.animal; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; +import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; @@ -38,7 +39,6 @@ import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.EntityUtils; import org.geysermc.geyser.util.InteractionResult; -import javax.annotation.Nonnull; import java.util.UUID; public class AxolotlEntity extends AnimalEntity { @@ -74,9 +74,9 @@ public class AxolotlEntity extends AnimalEntity { return true; } - @Nonnull + @NonNull @Override - protected InteractionResult mobInteract(@Nonnull Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { if (EntityUtils.attemptToBucket(itemInHand)) { return InteractionResult.SUCCESS; } else { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/CowEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/CowEntity.java index 01641c8c3..cdcf534a3 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/CowEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/CowEntity.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.entity.type.living.animal; import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; +import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.SoundEvent; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; @@ -36,7 +37,6 @@ import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; -import javax.annotation.Nonnull; import java.util.UUID; public class CowEntity extends AnimalEntity { @@ -44,9 +44,9 @@ public class CowEntity extends AnimalEntity { super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); } - @Nonnull + @NonNull @Override - protected InteractiveTag testMobInteraction(@Nonnull Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { if (getFlag(EntityFlag.BABY) || itemInHand.asItem() != Items.BUCKET) { return super.testMobInteraction(hand, itemInHand); } @@ -54,9 +54,9 @@ public class CowEntity extends AnimalEntity { return InteractiveTag.MILK; } - @Nonnull + @NonNull @Override - protected InteractionResult mobInteract(@Nonnull Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { if (getFlag(EntityFlag.BABY) || itemInHand.asItem() != Items.BUCKET) { return super.mobInteract(hand, itemInHand); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/GoatEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/GoatEntity.java index 20b8f5ccf..9ed94f96f 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/GoatEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/GoatEntity.java @@ -28,6 +28,7 @@ package org.geysermc.geyser.entity.type.living.animal; import com.github.steveice10.mc.protocol.data.game.entity.metadata.Pose; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; +import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.SoundEvent; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; @@ -38,7 +39,6 @@ import org.geysermc.geyser.item.Items; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.InteractionResult; -import javax.annotation.Nonnull; import java.util.UUID; public class GoatEntity extends AnimalEntity { @@ -70,9 +70,9 @@ public class GoatEntity extends AnimalEntity { // TODO testMobInteraction? - @Nonnull + @NonNull @Override - protected InteractionResult mobInteract(@Nonnull Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { if (!getFlag(EntityFlag.BABY) && itemInHand.asItem() == Items.BUCKET) { session.playSoundEvent(isScreamer ? SoundEvent.MILK_SCREAMER : SoundEvent.MILK, position); return InteractionResult.SUCCESS; diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/MooshroomEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/MooshroomEntity.java index 2d136a169..1c347bf31 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/MooshroomEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/MooshroomEntity.java @@ -27,6 +27,7 @@ package org.geysermc.geyser.entity.type.living.animal; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ObjectEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; +import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.geysermc.geyser.entity.EntityDefinition; @@ -37,7 +38,6 @@ import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; -import javax.annotation.Nonnull; import java.util.UUID; public class MooshroomEntity extends AnimalEntity { @@ -52,9 +52,9 @@ public class MooshroomEntity extends AnimalEntity { dirtyMetadata.put(EntityDataTypes.VARIANT, isBrown ? 1 : 0); } - @Nonnull + @NonNull @Override - protected InteractiveTag testMobInteraction(@Nonnull Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { if (!isBaby()) { if (itemInHand.asItem() == Items.BOWL) { // Stew @@ -67,9 +67,9 @@ public class MooshroomEntity extends AnimalEntity { return super.testMobInteraction(hand, itemInHand); } - @Nonnull + @NonNull @Override - protected InteractionResult mobInteract(@Nonnull Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { boolean isBaby = isBaby(); if (!isBaby && itemInHand.asItem() == Items.BOWL) { // Stew diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/OcelotEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/OcelotEntity.java index c81ddd52e..c115ebcdc 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/OcelotEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/OcelotEntity.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.entity.type.living.animal; import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; +import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.EntityDefinition; @@ -36,7 +37,6 @@ import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; -import javax.annotation.Nonnull; import java.util.UUID; public class OcelotEntity extends AnimalEntity { @@ -50,9 +50,9 @@ public class OcelotEntity extends AnimalEntity { return item == Items.COD || item == Items.SALMON; } - @Nonnull + @NonNull @Override - protected InteractiveTag testMobInteraction(Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { if (!getFlag(EntityFlag.TRUSTING) && canEat(itemInHand) && session.getPlayerEntity().getPosition().distanceSquared(position) < 9f) { // Attempt to feed return InteractiveTag.FEED; @@ -61,9 +61,9 @@ public class OcelotEntity extends AnimalEntity { } } - @Nonnull + @NonNull @Override - protected InteractionResult mobInteract(Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { if (!getFlag(EntityFlag.TRUSTING) && canEat(itemInHand) && session.getPlayerEntity().getPosition().distanceSquared(position) < 9f) { // Attempt to feed return InteractionResult.SUCCESS; diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PandaEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PandaEntity.java index 212eaa91e..d2ef36932 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PandaEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PandaEntity.java @@ -28,6 +28,8 @@ package org.geysermc.geyser.entity.type.living.animal; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityEventType; @@ -41,8 +43,6 @@ import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; import java.util.UUID; public class PandaEntity extends AnimalEntity { @@ -93,18 +93,18 @@ public class PandaEntity extends AnimalEntity { return item == Items.BAMBOO; } - @Nonnull + @NonNull @Override - protected InteractiveTag testMobInteraction(@Nonnull Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { if (mainGene == Gene.WORRIED && session.isThunder()) { return InteractiveTag.NONE; } return super.testMobInteraction(hand, itemInHand); } - @Nonnull + @NonNull @Override - protected InteractionResult mobInteract(@Nonnull Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { if (mainGene == Gene.WORRIED && session.isThunder()) { // Huh! return InteractionResult.PASS; diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PigEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PigEntity.java index 91e94321c..2bc02cd55 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PigEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/PigEntity.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.entity.type.living.animal; import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; +import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.EntityDefinition; @@ -37,7 +38,6 @@ import org.geysermc.geyser.util.EntityUtils; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; -import javax.annotation.Nonnull; import java.util.UUID; public class PigEntity extends AnimalEntity { @@ -51,9 +51,9 @@ public class PigEntity extends AnimalEntity { return item == Items.CARROT || item == Items.POTATO || item == Items.BEETROOT; } - @Nonnull + @NonNull @Override - protected InteractiveTag testMobInteraction(@Nonnull Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { if (!canEat(itemInHand) && getFlag(EntityFlag.SADDLED) && passengers.isEmpty() && !session.isSneaking()) { // Mount return InteractiveTag.MOUNT; @@ -68,9 +68,9 @@ public class PigEntity extends AnimalEntity { } } - @Nonnull + @NonNull @Override - protected InteractionResult mobInteract(@Nonnull Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { if (!canEat(itemInHand) && getFlag(EntityFlag.SADDLED) && passengers.isEmpty() && !session.isSneaking()) { // Mount return InteractionResult.SUCCESS; diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SheepEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SheepEntity.java index 8c9458012..13059244a 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SheepEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/SheepEntity.java @@ -27,6 +27,7 @@ package org.geysermc.geyser.entity.type.living.animal; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; +import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; @@ -38,7 +39,6 @@ import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; -import javax.annotation.Nonnull; import java.util.UUID; public class SheepEntity extends AnimalEntity { @@ -55,9 +55,9 @@ public class SheepEntity extends AnimalEntity { dirtyMetadata.put(EntityDataTypes.COLOR, (byte) color); } - @Nonnull + @NonNull @Override - protected InteractiveTag testMobInteraction(@Nonnull Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { if (itemInHand.asItem() == Items.SHEARS) { return InteractiveTag.SHEAR; } else { @@ -73,9 +73,9 @@ public class SheepEntity extends AnimalEntity { } } - @Nonnull + @NonNull @Override - protected InteractionResult mobInteract(@Nonnull Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { if (itemInHand.asItem() == Items.SHEARS) { return InteractionResult.CONSUME; } else { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/StriderEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/StriderEntity.java index e58fa5aca..39a55fa1e 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/StriderEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/StriderEntity.java @@ -27,6 +27,7 @@ package org.geysermc.geyser.entity.type.living.animal; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; +import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.EntityDefinition; @@ -39,7 +40,6 @@ import org.geysermc.geyser.util.EntityUtils; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; -import javax.annotation.Nonnull; import java.util.UUID; public class StriderEntity extends AnimalEntity { @@ -98,9 +98,9 @@ public class StriderEntity extends AnimalEntity { return item == Items.WARPED_FUNGUS; } - @Nonnull + @NonNull @Override - protected InteractiveTag testMobInteraction(@Nonnull Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { if (!canEat(itemInHand) && getFlag(EntityFlag.SADDLED) && passengers.isEmpty() && !session.isSneaking()) { // Mount Strider return InteractiveTag.RIDE_STRIDER; @@ -115,9 +115,9 @@ public class StriderEntity extends AnimalEntity { } } - @Nonnull + @NonNull @Override - protected InteractionResult mobInteract(@Nonnull Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { if (!canEat(itemInHand) && getFlag(EntityFlag.SADDLED) && passengers.isEmpty() && !session.isSneaking()) { // Mount Strider return InteractionResult.SUCCESS; diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/AbstractHorseEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/AbstractHorseEntity.java index 872f72190..faa495487 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/AbstractHorseEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/AbstractHorseEntity.java @@ -27,6 +27,7 @@ package org.geysermc.geyser.entity.type.living.animal.horse; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; +import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityEventType; @@ -44,7 +45,6 @@ import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; -import javax.annotation.Nonnull; import java.util.Set; import java.util.UUID; @@ -128,14 +128,14 @@ public class AbstractHorseEntity extends AnimalEntity { return DONKEY_AND_HORSE_FOODS.contains(item); } - @Nonnull + @NonNull @Override - protected InteractiveTag testMobInteraction(@Nonnull Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { return testHorseInteraction(hand, itemInHand); } - @Nonnull - protected final InteractiveTag testHorseInteraction(@Nonnull Hand hand, @Nonnull GeyserItemStack itemInHand) { + @NonNull + protected final InteractiveTag testHorseInteraction(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { boolean isBaby = isBaby(); if (!isBaby) { if (getFlag(EntityFlag.TAMED) && session.isSneaking()) { @@ -178,14 +178,14 @@ public class AbstractHorseEntity extends AnimalEntity { } } - @Nonnull + @NonNull @Override - protected InteractionResult mobInteract(Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { return mobHorseInteract(hand, itemInHand); } - @Nonnull - protected final InteractionResult mobHorseInteract(@Nonnull Hand hand, @Nonnull GeyserItemStack itemInHand) { + @NonNull + protected final InteractionResult mobHorseInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { boolean isBaby = isBaby(); if (!isBaby) { if (getFlag(EntityFlag.TAMED) && session.isSneaking()) { @@ -236,21 +236,21 @@ public class AbstractHorseEntity extends AnimalEntity { } } - protected boolean testSaddle(@Nonnull GeyserItemStack itemInHand) { + protected boolean testSaddle(@NonNull GeyserItemStack itemInHand) { return isAlive() && !getFlag(EntityFlag.BABY) && getFlag(EntityFlag.TAMED); } - protected boolean testForChest(@Nonnull GeyserItemStack itemInHand) { + protected boolean testForChest(@NonNull GeyserItemStack itemInHand) { return false; } - protected boolean additionalTestForInventoryOpen(@Nonnull GeyserItemStack itemInHand) { + protected boolean additionalTestForInventoryOpen(@NonNull GeyserItemStack itemInHand) { return itemInHand.asItem().javaIdentifier().endsWith("_horse_armor"); } /* Just a place to stuff common code for the undead variants without having duplicate code */ - protected final InteractiveTag testUndeadHorseInteraction(@Nonnull Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected final InteractiveTag testUndeadHorseInteraction(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { if (!getFlag(EntityFlag.TAMED)) { return InteractiveTag.NONE; } else if (isBaby()) { @@ -272,7 +272,7 @@ public class AbstractHorseEntity extends AnimalEntity { } } - protected final InteractionResult undeadHorseInteract(@Nonnull Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected final InteractionResult undeadHorseInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { if (!getFlag(EntityFlag.TAMED)) { return InteractionResult.PASS; } else if (isBaby()) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/CamelEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/CamelEntity.java index 4ce6f062b..8106b096d 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/CamelEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/CamelEntity.java @@ -111,6 +111,5 @@ public class CamelEntity extends AbstractHorseEntity { } public void setDashing(BooleanEntityMetadata entityMetadata) { - } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/ChestedHorseEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/ChestedHorseEntity.java index 0fb9438d2..fc8584de3 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/ChestedHorseEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/ChestedHorseEntity.java @@ -25,6 +25,7 @@ package org.geysermc.geyser.entity.type.living.animal.horse; +import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.EntityDefinition; @@ -32,7 +33,6 @@ import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.item.Items; import org.geysermc.geyser.session.GeyserSession; -import javax.annotation.Nonnull; import java.util.UUID; public class ChestedHorseEntity extends AbstractHorseEntity { @@ -47,18 +47,18 @@ public class ChestedHorseEntity extends AbstractHorseEntity { } @Override - protected boolean testSaddle(@Nonnull GeyserItemStack itemInHand) { + protected boolean testSaddle(@NonNull GeyserItemStack itemInHand) { // Not checked here return false; } @Override - protected boolean testForChest(@Nonnull GeyserItemStack itemInHand) { + protected boolean testForChest(@NonNull GeyserItemStack itemInHand) { return itemInHand.asItem() == Items.CHEST && !getFlag(EntityFlag.CHESTED); } @Override - protected boolean additionalTestForInventoryOpen(@Nonnull GeyserItemStack itemInHand) { + protected boolean additionalTestForInventoryOpen(@NonNull GeyserItemStack itemInHand) { // Armor won't work on these return false; } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/SkeletonHorseEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/SkeletonHorseEntity.java index 43c76202c..7080f9f75 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/SkeletonHorseEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/SkeletonHorseEntity.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.entity.type.living.animal.horse; import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; +import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.inventory.GeyserItemStack; @@ -33,7 +34,6 @@ import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; -import javax.annotation.Nonnull; import java.util.UUID; public class SkeletonHorseEntity extends AbstractHorseEntity { @@ -41,15 +41,15 @@ public class SkeletonHorseEntity extends AbstractHorseEntity { super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); } - @Nonnull + @NonNull @Override - protected InteractiveTag testMobInteraction(Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { return testUndeadHorseInteraction(hand, itemInHand); } - @Nonnull + @NonNull @Override - protected InteractionResult mobInteract(Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { return undeadHorseInteract(hand, itemInHand); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/ZombieHorseEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/ZombieHorseEntity.java index 423537496..3275712fc 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/ZombieHorseEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/horse/ZombieHorseEntity.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.entity.type.living.animal.horse; import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; +import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.vector.Vector3f; import org.geysermc.geyser.entity.EntityDefinition; import org.geysermc.geyser.inventory.GeyserItemStack; @@ -33,7 +34,6 @@ import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; -import javax.annotation.Nonnull; import java.util.UUID; public class ZombieHorseEntity extends AbstractHorseEntity { @@ -41,15 +41,15 @@ public class ZombieHorseEntity extends AbstractHorseEntity { super(session, entityId, geyserId, uuid, definition, position, motion, yaw, pitch, headYaw); } - @Nonnull + @NonNull @Override - protected InteractiveTag testMobInteraction(Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { return testUndeadHorseInteraction(hand, itemInHand); } - @Nonnull + @NonNull @Override - protected InteractionResult mobInteract(Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { return undeadHorseInteract(hand, itemInHand); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/CatEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/CatEntity.java index 7903d85ca..412157b5d 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/CatEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/CatEntity.java @@ -29,6 +29,7 @@ import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanE import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; +import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; @@ -40,7 +41,6 @@ import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; -import javax.annotation.Nonnull; import java.util.UUID; public class CatEntity extends TameableEntity { @@ -112,9 +112,9 @@ public class CatEntity extends TameableEntity { return item == Items.COD || item == Items.SALMON; } - @Nonnull + @NonNull @Override - protected InteractiveTag testMobInteraction(@Nonnull Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { boolean tamed = getFlag(EntityFlag.TAMED); if (tamed && ownerBedrockId == session.getPlayerEntity().getGeyserId()) { // Toggle sitting @@ -124,9 +124,9 @@ public class CatEntity extends TameableEntity { } } - @Nonnull + @NonNull @Override - protected InteractionResult mobInteract(@Nonnull Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { boolean tamed = getFlag(EntityFlag.TAMED); if (tamed && ownerBedrockId == session.getPlayerEntity().getGeyserId()) { return InteractionResult.SUCCESS; diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/ParrotEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/ParrotEntity.java index 43f379de8..4c4b6a222 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/ParrotEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/ParrotEntity.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.entity.type.living.animal.tameable; import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; +import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.EntityDefinition; @@ -36,7 +37,6 @@ import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; -import javax.annotation.Nonnull; import java.util.Set; import java.util.UUID; @@ -61,9 +61,9 @@ public class ParrotEntity extends TameableEntity { return item == Items.COOKIE; } - @Nonnull + @NonNull @Override - protected InteractiveTag testMobInteraction(@Nonnull Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { boolean tame = getFlag(EntityFlag.TAMED); if (!tame && isTameFood(itemInHand.asItem())) { return InteractiveTag.FEED; @@ -76,9 +76,9 @@ public class ParrotEntity extends TameableEntity { return super.testMobInteraction(hand, itemInHand); } - @Nonnull + @NonNull @Override - protected InteractionResult mobInteract(@Nonnull Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { boolean tame = getFlag(EntityFlag.TAMED); if (!tame && isTameFood(itemInHand.asItem())) { return InteractionResult.SUCCESS; diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/WolfEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/WolfEntity.java index ecf0736a3..0f5b36ec3 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/WolfEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/animal/tameable/WolfEntity.java @@ -28,6 +28,7 @@ package org.geysermc.geyser.entity.type.living.animal.tameable; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; +import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; @@ -40,7 +41,6 @@ import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; -import javax.annotation.Nonnull; import java.util.Set; import java.util.UUID; @@ -103,9 +103,9 @@ public class WolfEntity extends TameableEntity { return !getFlag(EntityFlag.ANGRY) && super.canBeLeashed(); } - @Nonnull + @NonNull @Override - protected InteractiveTag testMobInteraction(@Nonnull Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { if (getFlag(EntityFlag.ANGRY)) { return InteractiveTag.NONE; } @@ -126,9 +126,9 @@ public class WolfEntity extends TameableEntity { return super.testMobInteraction(hand, itemInHand); } - @Nonnull + @NonNull @Override - protected InteractionResult mobInteract(@Nonnull Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { if (ownerBedrockId == session.getPlayerEntity().getGeyserId() || getFlag(EntityFlag.TAMED) || itemInHand.asItem() == Items.BONE && !getFlag(EntityFlag.ANGRY)) { // Sitting toggle or feeding; not angry diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/merchant/AbstractMerchantEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/merchant/AbstractMerchantEntity.java index b8465f9ca..c7b29130f 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/merchant/AbstractMerchantEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/merchant/AbstractMerchantEntity.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.entity.type.living.merchant; import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; +import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; import org.geysermc.geyser.entity.EntityDefinition; @@ -37,7 +38,6 @@ import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; -import javax.annotation.Nonnull; import java.util.UUID; public class AbstractMerchantEntity extends AgeableEntity { @@ -51,9 +51,9 @@ public class AbstractMerchantEntity extends AgeableEntity { return false; } - @Nonnull + @NonNull @Override - protected InteractiveTag testMobInteraction(@Nonnull Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { if (itemInHand.asItem() != Items.VILLAGER_SPAWN_EGG && (definition != EntityDefinitions.VILLAGER || !getFlag(EntityFlag.SLEEPING) && ((VillagerEntity) this).isCanTradeWith())) { // An additional check we know cannot work @@ -64,9 +64,9 @@ public class AbstractMerchantEntity extends AgeableEntity { return super.testMobInteraction(hand, itemInHand); } - @Nonnull + @NonNull @Override - protected InteractionResult mobInteract(@Nonnull Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { if (itemInHand.asItem() != Items.VILLAGER_SPAWN_EGG && (definition != EntityDefinitions.VILLAGER || !getFlag(EntityFlag.SLEEPING)) && (definition != EntityDefinitions.WANDERING_TRADER || !getFlag(EntityFlag.BABY))) { diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/merchant/VillagerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/merchant/VillagerEntity.java index 84fa7d1bd..9b0f50050 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/merchant/VillagerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/merchant/VillagerEntity.java @@ -28,6 +28,7 @@ package org.geysermc.geyser.entity.type.living.merchant; import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.VillagerData; import lombok.Getter; +import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.math.vector.Vector3i; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; @@ -78,6 +79,7 @@ public class VillagerEntity extends AbstractMerchantEntity { VILLAGER_REGIONS[6] = 6; } + @Nullable private Vector3i bedPosition; /** * Used in the interactive tag manager @@ -103,7 +105,7 @@ public class VillagerEntity extends AbstractMerchantEntity { } @Override - public Vector3i setBedPosition(EntityMetadata, ?> entityMetadata) { + public @Nullable Vector3i setBedPosition(EntityMetadata, ?> entityMetadata) { return bedPosition = super.setBedPosition(entityMetadata); } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/CreeperEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/CreeperEntity.java index e50722681..33ea4e544 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/CreeperEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/CreeperEntity.java @@ -28,6 +28,7 @@ package org.geysermc.geyser.entity.type.living.monster; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.IntEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; +import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.SoundEvent; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; @@ -37,7 +38,6 @@ import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; -import javax.annotation.Nonnull; import java.util.UUID; public class CreeperEntity extends MonsterEntity { @@ -62,9 +62,9 @@ public class CreeperEntity extends MonsterEntity { setFlag(EntityFlag.IGNITED, ignitedByFlintAndSteel); } - @Nonnull + @NonNull @Override - protected InteractiveTag testMobInteraction(@Nonnull Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { if (session.getTagCache().isCreeperIgniter(itemInHand.asItem())) { return InteractiveTag.IGNITE_CREEPER; } else { @@ -72,9 +72,9 @@ public class CreeperEntity extends MonsterEntity { } } - @Nonnull + @NonNull @Override - protected InteractionResult mobInteract(@Nonnull Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { if (session.getTagCache().isCreeperIgniter(itemInHand.asItem())) { // Ignite creeper - as of 1.19.3 session.playSoundEvent(SoundEvent.IGNITE, position); diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/PiglinEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/PiglinEntity.java index 25fe7f802..450c546ec 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/PiglinEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/PiglinEntity.java @@ -27,6 +27,7 @@ package org.geysermc.geyser.entity.type.living.monster; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; +import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; @@ -37,7 +38,6 @@ import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; -import javax.annotation.Nonnull; import java.util.UUID; public class PiglinEntity extends BasePiglinEntity { @@ -71,9 +71,9 @@ public class PiglinEntity extends BasePiglinEntity { super.updateOffHand(session); } - @Nonnull + @NonNull @Override - protected InteractiveTag testMobInteraction(@Nonnull Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { InteractiveTag tag = super.testMobInteraction(hand, itemInHand); if (tag != InteractiveTag.NONE) { return tag; @@ -82,9 +82,9 @@ public class PiglinEntity extends BasePiglinEntity { } } - @Nonnull + @NonNull @Override - protected InteractionResult mobInteract(@Nonnull Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { InteractionResult superResult = super.mobInteract(hand, itemInHand); if (superResult.consumesAction()) { return superResult; @@ -93,7 +93,7 @@ public class PiglinEntity extends BasePiglinEntity { } } - private boolean canGiveGoldTo(@Nonnull GeyserItemStack itemInHand) { + private boolean canGiveGoldTo(@NonNull GeyserItemStack itemInHand) { return !getFlag(EntityFlag.BABY) && itemInHand.asItem() == Items.GOLD_INGOT && !getFlag(EntityFlag.ADMIRING); } } diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZombieVillagerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZombieVillagerEntity.java index fbac8663f..32e45507a 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZombieVillagerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/living/monster/ZombieVillagerEntity.java @@ -29,6 +29,7 @@ import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadat import com.github.steveice10.mc.protocol.data.game.entity.metadata.VillagerData; import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.BooleanEntityMetadata; import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; +import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; import org.cloudburstmc.protocol.bedrock.data.entity.EntityFlag; @@ -40,7 +41,6 @@ import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.InteractionResult; import org.geysermc.geyser.util.InteractiveTag; -import javax.annotation.Nonnull; import java.util.UUID; public class ZombieVillagerEntity extends ZombieEntity { @@ -67,9 +67,9 @@ public class ZombieVillagerEntity extends ZombieEntity { return getFlag(EntityFlag.IS_TRANSFORMING) || super.isShaking(); } - @Nonnull + @NonNull @Override - protected InteractiveTag testMobInteraction(@Nonnull Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected InteractiveTag testMobInteraction(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { if (itemInHand.asItem() == Items.GOLDEN_APPLE) { return InteractiveTag.CURE; } else { @@ -77,9 +77,9 @@ public class ZombieVillagerEntity extends ZombieEntity { } } - @Nonnull + @NonNull @Override - protected InteractionResult mobInteract(@Nonnull Hand hand, @Nonnull GeyserItemStack itemInHand) { + protected InteractionResult mobInteract(@NonNull Hand hand, @NonNull GeyserItemStack itemInHand) { if (itemInHand.asItem() == Items.GOLDEN_APPLE) { // The client doesn't know if the entity has weakness as that's not usually sent over the network return InteractionResult.CONSUME; diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java index e80418744..7504db1b1 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/player/PlayerEntity.java @@ -36,6 +36,7 @@ import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import lombok.Getter; import lombok.Setter; import net.kyori.adventure.text.Component; +import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.math.vector.Vector3i; import org.cloudburstmc.protocol.bedrock.data.*; @@ -57,7 +58,6 @@ import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.translator.text.MessageTranslator; import org.geysermc.geyser.util.ChunkUtils; -import javax.annotation.Nullable; import java.util.Collections; import java.util.List; import java.util.Optional; @@ -86,6 +86,7 @@ public class PlayerEntity extends LivingEntity implements GeyserPlayerEntity { @Nullable private String texturesProperty; + @Nullable private Vector3i bedPosition; /** @@ -240,7 +241,7 @@ public class PlayerEntity extends LivingEntity implements GeyserPlayerEntity { } @Override - public Vector3i setBedPosition(EntityMetadata, ?> entityMetadata) { + public @Nullable Vector3i setBedPosition(EntityMetadata, ?> entityMetadata) { bedPosition = super.setBedPosition(entityMetadata); if (bedPosition != null) { // Required to sync position of entity to bed diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/player/SessionPlayerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/player/SessionPlayerEntity.java index 58b7ffddb..751a24871 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/player/SessionPlayerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/player/SessionPlayerEntity.java @@ -33,6 +33,7 @@ import com.github.steveice10.mc.protocol.data.game.entity.metadata.type.ByteEnti import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import lombok.Getter; +import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.AttributeData; import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes; @@ -44,7 +45,6 @@ import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.AttributeUtils; import org.geysermc.geyser.util.DimensionUtils; -import javax.annotation.Nullable; import java.util.Collections; import java.util.List; import java.util.Map; @@ -112,7 +112,7 @@ public class SessionPlayerEntity extends PlayerEntity { /** * Sending any updated flags (sprinting, onFire, etc.) to the client while in spectator is not needed - * Also "fixes" https://github.com/GeyserMC/Geyser/issues/3318 + * Also "fixes" issue 3318 */ @Override public void setFlags(ByteEntityMetadata entityMetadata) { @@ -126,7 +126,7 @@ public class SessionPlayerEntity extends PlayerEntity { /** * Since 1.19.40, the client must be re-informed of its bounding box on respawn - * See https://github.com/GeyserMC/Geyser/issues/3370 + * See issue 3370 */ public void updateBoundingBox() { dirtyMetadata.put(EntityDataTypes.HEIGHT, getBoundingBoxHeight()); diff --git a/core/src/main/java/org/geysermc/geyser/erosion/AbstractGeyserboundPacketHandler.java b/core/src/main/java/org/geysermc/geyser/erosion/AbstractGeyserboundPacketHandler.java index eabed8f7b..b8363efc9 100644 --- a/core/src/main/java/org/geysermc/geyser/erosion/AbstractGeyserboundPacketHandler.java +++ b/core/src/main/java/org/geysermc/geyser/erosion/AbstractGeyserboundPacketHandler.java @@ -25,9 +25,9 @@ package org.geysermc.geyser.erosion; +import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.erosion.packet.geyserbound.*; import org.geysermc.geyser.session.GeyserSession; -import org.jetbrains.annotations.Nullable; public abstract class AbstractGeyserboundPacketHandler implements GeyserboundPacketHandler { protected final GeyserSession session; diff --git a/core/src/main/java/org/geysermc/geyser/erosion/GeyserboundHandshakePacketHandler.java b/core/src/main/java/org/geysermc/geyser/erosion/GeyserboundHandshakePacketHandler.java index 196595383..0b4f03643 100644 --- a/core/src/main/java/org/geysermc/geyser/erosion/GeyserboundHandshakePacketHandler.java +++ b/core/src/main/java/org/geysermc/geyser/erosion/GeyserboundHandshakePacketHandler.java @@ -26,11 +26,11 @@ package org.geysermc.geyser.erosion; import io.netty.channel.Channel; +import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.erosion.netty.NettyPacketSender; import org.geysermc.erosion.packet.ErosionPacketHandler; import org.geysermc.erosion.packet.geyserbound.GeyserboundHandshakePacket; import org.geysermc.geyser.session.GeyserSession; -import org.jetbrains.annotations.Nullable; public final class GeyserboundHandshakePacketHandler extends AbstractGeyserboundPacketHandler { @@ -66,7 +66,7 @@ public final class GeyserboundHandshakePacketHandler extends AbstractGeyserbound } @Override - public ErosionPacketHandler setChannel(Channel channel) { + public @Nullable ErosionPacketHandler setChannel(Channel channel) { return null; } } diff --git a/core/src/main/java/org/geysermc/geyser/erosion/UnixSocketClientListener.java b/core/src/main/java/org/geysermc/geyser/erosion/UnixSocketClientListener.java index a236099df..1e00fe02c 100644 --- a/core/src/main/java/org/geysermc/geyser/erosion/UnixSocketClientListener.java +++ b/core/src/main/java/org/geysermc/geyser/erosion/UnixSocketClientListener.java @@ -31,6 +31,7 @@ import io.netty.channel.ChannelInitializer; import io.netty.channel.EventLoopGroup; import io.netty.channel.epoll.EpollDomainSocketChannel; import io.netty.channel.epoll.EpollEventLoopGroup; +import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.erosion.netty.impl.AbstractUnixSocketListener; import org.geysermc.erosion.packet.geyserbound.GeyserboundPacketHandler; @@ -49,9 +50,9 @@ public final class UnixSocketClientListener extends AbstractUnixSocketListener { initializeEventLoopGroup(); (new Bootstrap() .channel(EpollDomainSocketChannel.class) - .handler(new ChannelInitializer() { + .handler(new ChannelInitializer<>() { @Override - protected void initChannel(Channel ch) { + protected void initChannel(@NonNull Channel ch) { initPipeline(ch, handler); } }) diff --git a/core/src/main/java/org/geysermc/geyser/event/GeyserEventBus.java b/core/src/main/java/org/geysermc/geyser/event/GeyserEventBus.java index 9593e327e..d8657b612 100644 --- a/core/src/main/java/org/geysermc/geyser/event/GeyserEventBus.java +++ b/core/src/main/java/org/geysermc/geyser/event/GeyserEventBus.java @@ -34,7 +34,6 @@ import org.geysermc.event.subscribe.Subscribe; import org.geysermc.geyser.api.event.EventBus; import org.geysermc.geyser.api.event.EventRegistrar; import org.geysermc.geyser.api.event.EventSubscriber; -import org.geysermc.geyser.api.extension.Extension; import java.util.Set; import java.util.function.BiConsumer; diff --git a/core/src/main/java/org/geysermc/geyser/event/GeyserEventSubscriber.java b/core/src/main/java/org/geysermc/geyser/event/GeyserEventSubscriber.java index d33de8cdd..ea2b73b5c 100644 --- a/core/src/main/java/org/geysermc/geyser/event/GeyserEventSubscriber.java +++ b/core/src/main/java/org/geysermc/geyser/event/GeyserEventSubscriber.java @@ -31,7 +31,6 @@ import org.geysermc.event.PostOrder; import org.geysermc.event.subscribe.impl.OwnedSubscriberImpl; import org.geysermc.geyser.api.event.EventRegistrar; import org.geysermc.geyser.api.event.ExtensionEventSubscriber; -import org.geysermc.geyser.api.extension.Extension; import java.util.function.BiConsumer; import java.util.function.Consumer; diff --git a/core/src/main/java/org/geysermc/geyser/event/type/GeyserBedrockPingEventImpl.java b/core/src/main/java/org/geysermc/geyser/event/type/GeyserBedrockPingEventImpl.java index 579b4c68c..df1f16650 100644 --- a/core/src/main/java/org/geysermc/geyser/event/type/GeyserBedrockPingEventImpl.java +++ b/core/src/main/java/org/geysermc/geyser/event/type/GeyserBedrockPingEventImpl.java @@ -26,12 +26,11 @@ package org.geysermc.geyser.event.type; import org.checkerframework.checker.index.qual.NonNegative; +import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.protocol.bedrock.BedrockPong; import org.geysermc.geyser.api.event.connection.GeyserBedrockPingEvent; -import org.jetbrains.annotations.NotNull; -import javax.annotation.Nonnull; import java.net.InetSocketAddress; import java.util.Objects; @@ -45,12 +44,12 @@ public class GeyserBedrockPingEventImpl implements GeyserBedrockPingEvent { } @Override - public void primaryMotd(@Nonnull String primary) { + public void primaryMotd(@NonNull String primary) { pong.motd(Objects.requireNonNull(primary, "Primary MOTD cannot be null")); } @Override - public void secondaryMotd(@Nonnull String secondary) { + public void secondaryMotd(@NonNull String secondary) { pong.subMotd(Objects.requireNonNull(secondary, "Secondary MOTD cannot be null")); } @@ -87,7 +86,7 @@ public class GeyserBedrockPingEventImpl implements GeyserBedrockPingEvent { } @Override - public @NotNull InetSocketAddress address() { + public @NonNull InetSocketAddress address() { return address; } } diff --git a/core/src/main/java/org/geysermc/geyser/event/type/GeyserDefineCustomItemsEventImpl.java b/core/src/main/java/org/geysermc/geyser/event/type/GeyserDefineCustomItemsEventImpl.java index 65fd7ea0d..b9a059f19 100644 --- a/core/src/main/java/org/geysermc/geyser/event/type/GeyserDefineCustomItemsEventImpl.java +++ b/core/src/main/java/org/geysermc/geyser/event/type/GeyserDefineCustomItemsEventImpl.java @@ -51,7 +51,7 @@ public abstract class GeyserDefineCustomItemsEventImpl implements GeyserDefineCu * @return a multimap of all the already registered custom items */ @Override - public Map> getExistingCustomItems() { + public @NonNull Map> getExistingCustomItems() { return Collections.unmodifiableMap(this.customItems.asMap()); } @@ -61,7 +61,7 @@ public abstract class GeyserDefineCustomItemsEventImpl implements GeyserDefineCu * @return the list of the already registered non-vanilla custom items */ @Override - public List getExistingNonVanillaCustomItems() { + public @NonNull List getExistingNonVanillaCustomItems() { return Collections.unmodifiableList(this.nonVanillaCustomItems); } diff --git a/core/src/main/java/org/geysermc/geyser/inventory/AnvilContainer.java b/core/src/main/java/org/geysermc/geyser/inventory/AnvilContainer.java index e99b901a4..9e0b83768 100644 --- a/core/src/main/java/org/geysermc/geyser/inventory/AnvilContainer.java +++ b/core/src/main/java/org/geysermc/geyser/inventory/AnvilContainer.java @@ -29,12 +29,11 @@ import com.github.steveice10.mc.protocol.data.game.inventory.ContainerType; import com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.ServerboundRenameItemPacket; import lombok.Getter; import lombok.Setter; +import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.translator.text.MessageTranslator; import org.geysermc.geyser.util.ItemUtils; -import javax.annotation.Nullable; - /** * Used to determine if rename packets should be sent and stores * the expected level cost for AnvilInventoryUpdater diff --git a/core/src/main/java/org/geysermc/geyser/inventory/Container.java b/core/src/main/java/org/geysermc/geyser/inventory/Container.java index 569802a5a..79fa67da1 100644 --- a/core/src/main/java/org/geysermc/geyser/inventory/Container.java +++ b/core/src/main/java/org/geysermc/geyser/inventory/Container.java @@ -27,12 +27,11 @@ package org.geysermc.geyser.inventory; import com.github.steveice10.mc.protocol.data.game.inventory.ContainerType; import lombok.Getter; +import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.translator.inventory.InventoryTranslator; import org.jetbrains.annotations.Range; -import javax.annotation.Nonnull; - /** * Combination of {@link Inventory} and {@link PlayerInventory} */ @@ -67,7 +66,7 @@ public class Container extends Inventory { } @Override - public void setItem(int slot, @Nonnull GeyserItemStack newItem, GeyserSession session) { + public void setItem(int slot, @NonNull GeyserItemStack newItem, GeyserSession session) { if (slot < this.size) { super.setItem(slot, newItem, session); } else { diff --git a/core/src/main/java/org/geysermc/geyser/inventory/Generic3X3Container.java b/core/src/main/java/org/geysermc/geyser/inventory/Generic3X3Container.java index 8dbc9b722..6518dce7c 100644 --- a/core/src/main/java/org/geysermc/geyser/inventory/Generic3X3Container.java +++ b/core/src/main/java/org/geysermc/geyser/inventory/Generic3X3Container.java @@ -33,7 +33,7 @@ import org.geysermc.geyser.translator.inventory.Generic3X3InventoryTranslator; public class Generic3X3Container extends Container { /** * Whether we need to set the container type as {@link org.cloudburstmc.protocol.bedrock.data.inventory.ContainerType#DROPPER}. - * + *

* Used at {@link Generic3X3InventoryTranslator#openInventory(GeyserSession, Inventory)} */ @Getter diff --git a/core/src/main/java/org/geysermc/geyser/inventory/GeyserEnchantOption.java b/core/src/main/java/org/geysermc/geyser/inventory/GeyserEnchantOption.java index d34ee2cbb..23365e392 100644 --- a/core/src/main/java/org/geysermc/geyser/inventory/GeyserEnchantOption.java +++ b/core/src/main/java/org/geysermc/geyser/inventory/GeyserEnchantOption.java @@ -40,7 +40,7 @@ import java.util.List; public class GeyserEnchantOption { private static final List EMPTY = Collections.emptyList(); /** - * This: https://cdn.discordapp.com/attachments/613168850925649981/791030657169227816/unknown.png + * This text * is controlled by the server. * So, of course, we have to throw in some easter eggs. ;) */ diff --git a/core/src/main/java/org/geysermc/geyser/inventory/GeyserItemStack.java b/core/src/main/java/org/geysermc/geyser/inventory/GeyserItemStack.java index b159193e3..a67516c5c 100644 --- a/core/src/main/java/org/geysermc/geyser/inventory/GeyserItemStack.java +++ b/core/src/main/java/org/geysermc/geyser/inventory/GeyserItemStack.java @@ -28,18 +28,18 @@ package org.geysermc.geyser.inventory; import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import lombok.AccessLevel; +import lombok.Data; import lombok.EqualsAndHashCode; import lombok.Getter; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.protocol.bedrock.data.inventory.ItemData; -import lombok.Data; import org.geysermc.geyser.item.type.Item; import org.geysermc.geyser.registry.Registries; import org.geysermc.geyser.registry.type.ItemMapping; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.translator.inventory.item.ItemTranslator; -import javax.annotation.Nonnull; - @Data public class GeyserItemStack { public static final GeyserItemStack EMPTY = new GeyserItemStack(0, 0, null); @@ -64,7 +64,7 @@ public class GeyserItemStack { this.netId = netId; } - public static @Nonnull GeyserItemStack from(ItemStack itemStack) { + public static @NonNull GeyserItemStack from(ItemStack itemStack) { return itemStack == null ? EMPTY : new GeyserItemStack(itemStack.getId(), itemStack.getAmount(), itemStack.getNbt()); } @@ -76,7 +76,7 @@ public class GeyserItemStack { return isEmpty() ? 0 : amount; } - public CompoundTag getNbt() { + public @Nullable CompoundTag getNbt() { return isEmpty() ? null : nbt; } @@ -96,7 +96,7 @@ public class GeyserItemStack { return getItemStack(amount); } - public ItemStack getItemStack(int newAmount) { + public @Nullable ItemStack getItemStack(int newAmount) { return isEmpty() ? null : new ItemStack(javaId, newAmount, nbt); } diff --git a/core/src/main/java/org/geysermc/geyser/inventory/Inventory.java b/core/src/main/java/org/geysermc/geyser/inventory/Inventory.java index 91e8c4e94..3376d6c26 100644 --- a/core/src/main/java/org/geysermc/geyser/inventory/Inventory.java +++ b/core/src/main/java/org/geysermc/geyser/inventory/Inventory.java @@ -29,6 +29,7 @@ import com.github.steveice10.mc.protocol.data.game.inventory.ContainerType; import com.github.steveice10.opennbt.tag.builtin.ByteTag; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.Tag; +import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.vector.Vector3i; import lombok.Getter; import lombok.Setter; @@ -40,7 +41,6 @@ import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.translator.inventory.item.ItemTranslator; import org.jetbrains.annotations.Range; -import javax.annotation.Nonnull; import java.util.Arrays; @ToString @@ -126,7 +126,7 @@ public abstract class Inventory { public abstract int getOffsetForHotbar(@Range(from = 0, to = 8) int slot); - public void setItem(int slot, @Nonnull GeyserItemStack newItem, GeyserSession session) { + public void setItem(int slot, @NonNull GeyserItemStack newItem, GeyserSession session) { if (slot > this.size) { session.getGeyser().getLogger().debug("Tried to set an item out of bounds! " + this); return; diff --git a/core/src/main/java/org/geysermc/geyser/inventory/PlayerInventory.java b/core/src/main/java/org/geysermc/geyser/inventory/PlayerInventory.java index 7b1064c8f..bda09a4ed 100644 --- a/core/src/main/java/org/geysermc/geyser/inventory/PlayerInventory.java +++ b/core/src/main/java/org/geysermc/geyser/inventory/PlayerInventory.java @@ -28,12 +28,11 @@ package org.geysermc.geyser.inventory; import com.github.steveice10.mc.protocol.data.game.entity.player.Hand; import lombok.Getter; import lombok.Setter; +import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.session.GeyserSession; import org.jetbrains.annotations.Range; -import javax.annotation.Nonnull; - public class PlayerInventory extends Inventory { /** * Stores the held item slot, starting at index 0. @@ -44,7 +43,7 @@ public class PlayerInventory extends Inventory { private int heldItemSlot; @Getter - @Nonnull + @NonNull private GeyserItemStack cursor = GeyserItemStack.EMPTY; public PlayerInventory() { @@ -57,12 +56,12 @@ public class PlayerInventory extends Inventory { return slot + 36; } - public void setCursor(@Nonnull GeyserItemStack newCursor, GeyserSession session) { + public void setCursor(@NonNull GeyserItemStack newCursor, GeyserSession session) { updateItemNetId(cursor, newCursor, session); cursor = newCursor; } - public GeyserItemStack getItemInHand(@Nonnull Hand hand) { + public GeyserItemStack getItemInHand(@NonNull Hand hand) { return hand == Hand.OFF_HAND ? getOffhand() : getItemInHand(); } @@ -74,7 +73,7 @@ public class PlayerInventory extends Inventory { return items[36 + heldItemSlot]; } - public void setItemInHand(@Nonnull GeyserItemStack item) { + public void setItemInHand(@NonNull GeyserItemStack item) { if (36 + heldItemSlot > this.size) { GeyserImpl.getInstance().getLogger().debug("Held item slot was larger than expected!"); return; diff --git a/core/src/main/java/org/geysermc/geyser/inventory/StonecutterContainer.java b/core/src/main/java/org/geysermc/geyser/inventory/StonecutterContainer.java index 6e04e6741..f99a0c71e 100644 --- a/core/src/main/java/org/geysermc/geyser/inventory/StonecutterContainer.java +++ b/core/src/main/java/org/geysermc/geyser/inventory/StonecutterContainer.java @@ -27,8 +27,8 @@ package org.geysermc.geyser.inventory; import com.github.steveice10.mc.protocol.data.game.inventory.ContainerType; import lombok.Getter; -import lombok.NonNull; import lombok.Setter; +import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.geyser.session.GeyserSession; public class StonecutterContainer extends Container { diff --git a/core/src/main/java/org/geysermc/geyser/inventory/item/Enchantment.java b/core/src/main/java/org/geysermc/geyser/inventory/item/Enchantment.java index bcbfe3e17..5fa2a5784 100644 --- a/core/src/main/java/org/geysermc/geyser/inventory/item/Enchantment.java +++ b/core/src/main/java/org/geysermc/geyser/inventory/item/Enchantment.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.inventory.item; import lombok.Getter; +import org.checkerframework.checker.nullness.qual.Nullable; import java.util.Locale; @@ -78,7 +79,7 @@ public enum Enchantment { this.javaIdentifier = "minecraft:" + this.name().toLowerCase(Locale.ENGLISH); } - public static Enchantment getByJavaIdentifier(String javaIdentifier) { + public static @Nullable Enchantment getByJavaIdentifier(String javaIdentifier) { for (Enchantment enchantment : VALUES) { if (enchantment.javaIdentifier.equals(javaIdentifier) || enchantment.name().toLowerCase(Locale.ENGLISH).equalsIgnoreCase(javaIdentifier)) { return enchantment; @@ -87,7 +88,7 @@ public enum Enchantment { return null; } - public static Enchantment getByBedrockId(int bedrockId) { + public static @Nullable Enchantment getByBedrockId(int bedrockId) { if (bedrockId >= 0 && bedrockId < VALUES.length) { return VALUES[bedrockId]; } @@ -149,7 +150,7 @@ public enum Enchantment { */ public static final String[] ALL_JAVA_IDENTIFIERS; - public static JavaEnchantment getByJavaIdentifier(String javaIdentifier) { + public static @Nullable JavaEnchantment getByJavaIdentifier(String javaIdentifier) { if (!javaIdentifier.startsWith("minecraft:")) { javaIdentifier = "minecraft:" + javaIdentifier; } diff --git a/core/src/main/java/org/geysermc/geyser/inventory/item/Potion.java b/core/src/main/java/org/geysermc/geyser/inventory/item/Potion.java index 8d2b52aa2..7ce0ee278 100644 --- a/core/src/main/java/org/geysermc/geyser/inventory/item/Potion.java +++ b/core/src/main/java/org/geysermc/geyser/inventory/item/Potion.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.inventory.item; import lombok.Getter; +import org.checkerframework.checker.nullness.qual.Nullable; import java.util.Locale; @@ -84,7 +85,7 @@ public enum Potion { this.bedrockId = (short) bedrockId; } - public static Potion getByJavaIdentifier(String javaIdentifier) { + public static @Nullable Potion getByJavaIdentifier(String javaIdentifier) { for (Potion potion : VALUES) { if (potion.javaIdentifier.equals(javaIdentifier)) { return potion; @@ -93,7 +94,7 @@ public enum Potion { return null; } - public static Potion getByBedrockId(int bedrockId) { + public static @Nullable Potion getByBedrockId(int bedrockId) { for (Potion potion : VALUES) { if (potion.bedrockId == bedrockId) { return potion; diff --git a/core/src/main/java/org/geysermc/geyser/inventory/item/StoredItemMappings.java b/core/src/main/java/org/geysermc/geyser/inventory/item/StoredItemMappings.java index 16fd7cde6..6bb786896 100644 --- a/core/src/main/java/org/geysermc/geyser/inventory/item/StoredItemMappings.java +++ b/core/src/main/java/org/geysermc/geyser/inventory/item/StoredItemMappings.java @@ -27,11 +27,11 @@ package org.geysermc.geyser.inventory.item; import lombok.Getter; import lombok.experimental.Accessors; +import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.geyser.item.Items; import org.geysermc.geyser.item.type.Item; import org.geysermc.geyser.registry.type.ItemMapping; -import javax.annotation.Nonnull; import java.util.Map; /** @@ -70,7 +70,7 @@ public class StoredItemMappings { this.writableBook = load(itemMappings, Items.WRITABLE_BOOK); } - @Nonnull + @NonNull private ItemMapping load(Map itemMappings, Item item) { ItemMapping mapping = itemMappings.get(item); if (mapping == null) { diff --git a/core/src/main/java/org/geysermc/geyser/inventory/item/TippedArrowPotion.java b/core/src/main/java/org/geysermc/geyser/inventory/item/TippedArrowPotion.java index e45667fe2..3ba0ad56f 100644 --- a/core/src/main/java/org/geysermc/geyser/inventory/item/TippedArrowPotion.java +++ b/core/src/main/java/org/geysermc/geyser/inventory/item/TippedArrowPotion.java @@ -26,12 +26,13 @@ package org.geysermc.geyser.inventory.item; import lombok.Getter; +import org.checkerframework.checker.nullness.qual.Nullable; import java.util.Locale; /** * Potion identifiers and their respective Bedrock IDs used with arrows. - * https://minecraft.wiki/w/Arrow#Data_values + * See here */ @Getter public enum TippedArrowPotion { @@ -93,7 +94,7 @@ public enum TippedArrowPotion { this.javaColor = arrowParticleColor.getColor(); } - public static TippedArrowPotion getByJavaIdentifier(String javaIdentifier) { + public static @Nullable TippedArrowPotion getByJavaIdentifier(String javaIdentifier) { for (TippedArrowPotion potion : VALUES) { if (potion.javaIdentifier.equals(javaIdentifier)) { return potion; @@ -102,7 +103,7 @@ public enum TippedArrowPotion { return null; } - public static TippedArrowPotion getByBedrockId(int bedrockId) { + public static @Nullable TippedArrowPotion getByBedrockId(int bedrockId) { for (TippedArrowPotion potion : VALUES) { if (potion.bedrockId == bedrockId) { return potion; @@ -115,7 +116,7 @@ public enum TippedArrowPotion { * @param color the potion color to look up * @return the tipped arrow potion that most closely resembles that color. */ - public static TippedArrowPotion getByJavaColor(int color) { + public static @Nullable TippedArrowPotion getByJavaColor(int color) { for (TippedArrowPotion potion : VALUES) { if (potion.javaColor == color) { return potion; diff --git a/core/src/main/java/org/geysermc/geyser/inventory/updater/AnvilInventoryUpdater.java b/core/src/main/java/org/geysermc/geyser/inventory/updater/AnvilInventoryUpdater.java index aa7897038..5adee0c20 100644 --- a/core/src/main/java/org/geysermc/geyser/inventory/updater/AnvilInventoryUpdater.java +++ b/core/src/main/java/org/geysermc/geyser/inventory/updater/AnvilInventoryUpdater.java @@ -64,7 +64,7 @@ public class AnvilInventoryUpdater extends InventoryUpdater { super.updateInventory(translator, session, inventory); AnvilContainer anvilContainer = (AnvilContainer) inventory; updateInventoryState(session, anvilContainer); - int targetSlot = getTargetSlot(session, anvilContainer); + int targetSlot = getTargetSlot(anvilContainer); for (int i = 0; i < translator.size; i++) { final int bedrockSlot = translator.javaSlotToBedrock(i); if (bedrockSlot == 50) @@ -89,7 +89,7 @@ public class AnvilInventoryUpdater extends InventoryUpdater { updateInventoryState(session, anvilContainer); int lastTargetSlot = anvilContainer.getLastTargetSlot(); - int targetSlot = getTargetSlot(session, anvilContainer); + int targetSlot = getTargetSlot(anvilContainer); if (targetSlot != javaSlot) { // Update the requested slot InventorySlotPacket slotPacket = new InventorySlotPacket(); @@ -136,7 +136,7 @@ public class AnvilInventoryUpdater extends InventoryUpdater { * @param anvilContainer the anvil inventory * @return the slot to change the repair cost */ - private int getTargetSlot(GeyserSession session, AnvilContainer anvilContainer) { + private int getTargetSlot(AnvilContainer anvilContainer) { GeyserItemStack input = anvilContainer.getInput(); GeyserItemStack material = anvilContainer.getMaterial(); @@ -433,6 +433,7 @@ public class AnvilInventoryUpdater extends InventoryUpdater { return !Objects.equals(originalName, ItemUtils.getCustomName(anvilContainer.getResult().getNbt())); } + @SuppressWarnings("SameParameterValue") private int getTagIntValueOr(GeyserItemStack itemStack, String tagName, int defaultValue) { if (itemStack.getNbt() != null) { Tag tag = itemStack.getNbt().get(tagName); diff --git a/core/src/main/java/org/geysermc/geyser/item/GeyserCustomItemOptions.java b/core/src/main/java/org/geysermc/geyser/item/GeyserCustomItemOptions.java index cebad261e..1434c49d9 100644 --- a/core/src/main/java/org/geysermc/geyser/item/GeyserCustomItemOptions.java +++ b/core/src/main/java/org/geysermc/geyser/item/GeyserCustomItemOptions.java @@ -30,15 +30,13 @@ import org.geysermc.geyser.api.util.TriState; import java.util.OptionalInt; +@SuppressWarnings("OptionalUsedAsFieldOrParameterType") public record GeyserCustomItemOptions(TriState unbreakable, OptionalInt customModelData, OptionalInt damagePredicate, boolean defaultItem) implements CustomItemOptions { - public GeyserCustomItemOptions(TriState unbreakable, OptionalInt customModelData, OptionalInt damagePredicate) { - this(unbreakable, customModelData, damagePredicate, false); - } - + @SuppressWarnings("OptionalUsedAsFieldOrParameterType") public static class CustomItemOptionsBuilder implements CustomItemOptions.Builder { private TriState unbreakable = TriState.NOT_SET; private OptionalInt customModelData = OptionalInt.empty(); diff --git a/core/src/main/java/org/geysermc/geyser/item/GeyserCustomMappingData.java b/core/src/main/java/org/geysermc/geyser/item/GeyserCustomMappingData.java index 37bf9e02c..d71f2e548 100644 --- a/core/src/main/java/org/geysermc/geyser/item/GeyserCustomMappingData.java +++ b/core/src/main/java/org/geysermc/geyser/item/GeyserCustomMappingData.java @@ -27,7 +27,6 @@ package org.geysermc.geyser.item; import org.cloudburstmc.protocol.bedrock.data.definitions.ItemDefinition; import org.cloudburstmc.protocol.bedrock.data.inventory.ComponentItemData; -import org.cloudburstmc.protocol.bedrock.packet.StartGamePacket; public record GeyserCustomMappingData(ComponentItemData componentItemData, ItemDefinition itemDefinition, String stringId, int integerId) { } diff --git a/core/src/main/java/org/geysermc/geyser/item/GeyserNonVanillaCustomItemData.java b/core/src/main/java/org/geysermc/geyser/item/GeyserNonVanillaCustomItemData.java index 47b5aed33..52b0ee7d0 100644 --- a/core/src/main/java/org/geysermc/geyser/item/GeyserNonVanillaCustomItemData.java +++ b/core/src/main/java/org/geysermc/geyser/item/GeyserNonVanillaCustomItemData.java @@ -32,11 +32,11 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.api.item.custom.CustomItemOptions; import org.geysermc.geyser.api.item.custom.CustomRenderOffsets; import org.geysermc.geyser.api.item.custom.NonVanillaCustomItemData; -import org.jetbrains.annotations.NotNull; import java.util.OptionalInt; import java.util.Set; +@SuppressWarnings("OptionalUsedAsFieldOrParameterType") @EqualsAndHashCode(callSuper = true) @ToString public final class GeyserNonVanillaCustomItemData extends GeyserCustomItemData implements NonVanillaCustomItemData { @@ -84,7 +84,7 @@ public final class GeyserNonVanillaCustomItemData extends GeyserCustomItemData i } @Override - public @NotNull String identifier() { + public @NonNull String identifier() { return identifier; } @@ -134,7 +134,7 @@ public final class GeyserNonVanillaCustomItemData extends GeyserCustomItemData i } @Override - public @NotNull OptionalInt creativeCategory() { + public @NonNull OptionalInt creativeCategory() { return creativeCategory; } diff --git a/core/src/main/java/org/geysermc/geyser/item/components/ToolTier.java b/core/src/main/java/org/geysermc/geyser/item/components/ToolTier.java index ee144acc6..8484eb185 100644 --- a/core/src/main/java/org/geysermc/geyser/item/components/ToolTier.java +++ b/core/src/main/java/org/geysermc/geyser/item/components/ToolTier.java @@ -26,7 +26,6 @@ package org.geysermc.geyser.item.components; import com.google.common.base.Suppliers; -import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.geyser.item.Items; import org.geysermc.geyser.item.type.Item; @@ -66,14 +65,4 @@ public enum ToolTier { public String toString() { return this.name().toLowerCase(Locale.ROOT); } - - public static ToolTier getByName(@NonNull String name) { - String upperCase = name.toUpperCase(Locale.ROOT); - for (ToolTier tier : VALUES) { - if (tier.name().equals(upperCase)) { - return tier; - } - } - return null; - } } diff --git a/core/src/main/java/org/geysermc/geyser/item/exception/InvalidCustomMappingsFileException.java b/core/src/main/java/org/geysermc/geyser/item/exception/InvalidCustomMappingsFileException.java index 5878f5cc7..99ca463d7 100644 --- a/core/src/main/java/org/geysermc/geyser/item/exception/InvalidCustomMappingsFileException.java +++ b/core/src/main/java/org/geysermc/geyser/item/exception/InvalidCustomMappingsFileException.java @@ -25,16 +25,14 @@ package org.geysermc.geyser.item.exception; +import java.io.Serial; + public class InvalidCustomMappingsFileException extends Exception { - public InvalidCustomMappingsFileException(Throwable cause) { - super(cause); - } + + @Serial + private static final long serialVersionUID = 1L; public InvalidCustomMappingsFileException(String message) { super(message); } - - public InvalidCustomMappingsFileException(String message, Throwable cause) { - super(message, cause); - } } diff --git a/core/src/main/java/org/geysermc/geyser/item/type/ArrowItem.java b/core/src/main/java/org/geysermc/geyser/item/type/ArrowItem.java index 9a93eeac8..938d4a79a 100644 --- a/core/src/main/java/org/geysermc/geyser/item/type/ArrowItem.java +++ b/core/src/main/java/org/geysermc/geyser/item/type/ArrowItem.java @@ -27,6 +27,7 @@ package org.geysermc.geyser.item.type; import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack; import com.github.steveice10.opennbt.tag.builtin.StringTag; +import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.protocol.bedrock.data.inventory.ItemData; import org.geysermc.geyser.inventory.item.TippedArrowPotion; import org.geysermc.geyser.item.Items; @@ -38,7 +39,8 @@ public class ArrowItem extends Item { super(javaIdentifier, builder); } - public ItemStack translateToJava(ItemData itemData, ItemMapping mapping, ItemMappings mappings) { + @Override + public @NonNull ItemStack translateToJava(@NonNull ItemData itemData, @NonNull ItemMapping mapping, @NonNull ItemMappings mappings) { TippedArrowPotion tippedArrowPotion = TippedArrowPotion.getByBedrockId(itemData.getDamage()); ItemStack itemStack = super.translateToJava(itemData, mapping, mappings); if (tippedArrowPotion != null) { diff --git a/core/src/main/java/org/geysermc/geyser/item/type/AxolotlBucketItem.java b/core/src/main/java/org/geysermc/geyser/item/type/AxolotlBucketItem.java index cd53cf904..81d7bf116 100644 --- a/core/src/main/java/org/geysermc/geyser/item/type/AxolotlBucketItem.java +++ b/core/src/main/java/org/geysermc/geyser/item/type/AxolotlBucketItem.java @@ -28,9 +28,9 @@ package org.geysermc.geyser.item.type; import com.github.steveice10.opennbt.tag.builtin.ByteTag; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.StringTag; +import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.text.MinecraftLocale; -import org.jetbrains.annotations.NotNull; public class AxolotlBucketItem extends Item { public AxolotlBucketItem(String javaIdentifier, Builder builder) { @@ -38,7 +38,7 @@ public class AxolotlBucketItem extends Item { } @Override - public void translateNbtToBedrock(@NotNull GeyserSession session, @NotNull CompoundTag tag) { + public void translateNbtToBedrock(@NonNull GeyserSession session, @NonNull CompoundTag tag) { super.translateNbtToBedrock(session, tag); // Bedrock Edition displays the properties of the axolotl. Java does not. diff --git a/core/src/main/java/org/geysermc/geyser/item/type/BannerItem.java b/core/src/main/java/org/geysermc/geyser/item/type/BannerItem.java index 920f9e168..344668836 100644 --- a/core/src/main/java/org/geysermc/geyser/item/type/BannerItem.java +++ b/core/src/main/java/org/geysermc/geyser/item/type/BannerItem.java @@ -29,14 +29,13 @@ import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.IntTag; import com.github.steveice10.opennbt.tag.builtin.ListTag; import com.github.steveice10.opennbt.tag.builtin.Tag; +import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.nbt.NbtList; import org.cloudburstmc.nbt.NbtMap; import org.cloudburstmc.nbt.NbtType; import org.geysermc.geyser.registry.type.ItemMapping; import org.geysermc.geyser.session.GeyserSession; -import org.jetbrains.annotations.NotNull; -import javax.annotation.Nonnull; import java.util.ArrayList; import java.util.List; @@ -45,7 +44,7 @@ import static org.geysermc.erosion.util.BannerUtils.getJavaPatternTag; public class BannerItem extends BlockItem { /** * Holds what a Java ominous banner pattern looks like. - * + *

* Translating the patterns over to Bedrock does not work effectively, but Bedrock has a dedicated type for * ominous banners that we set instead. This variable is used to detect Java ominous banner patterns, and apply * the correct ominous banner pattern if Bedrock pulls the item from creative. @@ -86,7 +85,7 @@ public class BannerItem extends BlockItem { * @param pattern Java edition pattern nbt * @return The Bedrock edition format pattern nbt */ - @Nonnull + @NonNull private static NbtMap getBedrockBannerPattern(CompoundTag pattern) { return NbtMap.builder() .putInt("Color", 15 - (int) pattern.get("Color").getValue()) @@ -121,7 +120,7 @@ public class BannerItem extends BlockItem { } @Override - public void translateNbtToBedrock(@NotNull GeyserSession session, @NotNull CompoundTag tag) { + public void translateNbtToBedrock(@NonNull GeyserSession session, @NonNull CompoundTag tag) { super.translateNbtToBedrock(session, tag); CompoundTag blockEntityTag = tag.remove("BlockEntityTag"); @@ -137,7 +136,7 @@ public class BannerItem extends BlockItem { } @Override - public void translateNbtToJava(@NotNull CompoundTag tag, @NotNull ItemMapping mapping) { + public void translateNbtToJava(@NonNull CompoundTag tag, @NonNull ItemMapping mapping) { super.translateNbtToJava(tag, mapping); if (tag.get("Type") instanceof IntTag type && type.getValue() == 1) { diff --git a/core/src/main/java/org/geysermc/geyser/item/type/CompassItem.java b/core/src/main/java/org/geysermc/geyser/item/type/CompassItem.java index d1ed6f6b8..87da96447 100644 --- a/core/src/main/java/org/geysermc/geyser/item/type/CompassItem.java +++ b/core/src/main/java/org/geysermc/geyser/item/type/CompassItem.java @@ -30,6 +30,7 @@ import com.github.steveice10.opennbt.tag.builtin.ByteTag; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.IntTag; import com.github.steveice10.opennbt.tag.builtin.Tag; +import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.protocol.bedrock.data.inventory.ItemData; import org.geysermc.geyser.registry.type.ItemMapping; import org.geysermc.geyser.registry.type.ItemMappings; @@ -57,7 +58,7 @@ public class CompassItem extends Item { } @Override - public void translateNbtToBedrock(GeyserSession session, CompoundTag tag) { + public void translateNbtToBedrock(@NonNull GeyserSession session, @NonNull CompoundTag tag) { super.translateNbtToBedrock(session, tag); Tag lodestoneTag = tag.get("LodestoneTracked"); @@ -77,7 +78,7 @@ public class CompassItem extends Item { } @Override - public ItemStack translateToJava(ItemData itemData, ItemMapping mapping, ItemMappings mappings) { + public @NonNull ItemStack translateToJava(@NonNull ItemData itemData, @NonNull ItemMapping mapping, @NonNull ItemMappings mappings) { if (mapping.getBedrockIdentifier().equals("minecraft:lodestone_compass")) { // Revert the entry back to the compass mapping = mappings.getStoredItems().compass(); diff --git a/core/src/main/java/org/geysermc/geyser/item/type/CrossbowItem.java b/core/src/main/java/org/geysermc/geyser/item/type/CrossbowItem.java index 756cd69ba..e409dccfb 100644 --- a/core/src/main/java/org/geysermc/geyser/item/type/CrossbowItem.java +++ b/core/src/main/java/org/geysermc/geyser/item/type/CrossbowItem.java @@ -28,11 +28,11 @@ package org.geysermc.geyser.item.type; import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack; import com.github.steveice10.opennbt.tag.builtin.*; import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.protocol.bedrock.data.inventory.ItemData; import org.geysermc.geyser.registry.type.ItemMapping; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.translator.inventory.item.ItemTranslator; -import org.jetbrains.annotations.Nullable; public class CrossbowItem extends Item { public CrossbowItem(String javaIdentifier, Builder builder) { diff --git a/core/src/main/java/org/geysermc/geyser/item/type/EnchantedBookItem.java b/core/src/main/java/org/geysermc/geyser/item/type/EnchantedBookItem.java index f7743e430..ac0751c73 100644 --- a/core/src/main/java/org/geysermc/geyser/item/type/EnchantedBookItem.java +++ b/core/src/main/java/org/geysermc/geyser/item/type/EnchantedBookItem.java @@ -28,6 +28,7 @@ package org.geysermc.geyser.item.type; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.ListTag; import com.github.steveice10.opennbt.tag.builtin.Tag; +import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.geyser.session.GeyserSession; import java.util.ArrayList; @@ -39,7 +40,7 @@ public class EnchantedBookItem extends Item { } @Override - public void translateNbtToBedrock(GeyserSession session, CompoundTag tag) { + public void translateNbtToBedrock(@NonNull GeyserSession session, @NonNull CompoundTag tag) { super.translateNbtToBedrock(session, tag); List newTags = new ArrayList<>(); diff --git a/core/src/main/java/org/geysermc/geyser/item/type/FishingRodItem.java b/core/src/main/java/org/geysermc/geyser/item/type/FishingRodItem.java index 96241deb3..f63a1ec5a 100644 --- a/core/src/main/java/org/geysermc/geyser/item/type/FishingRodItem.java +++ b/core/src/main/java/org/geysermc/geyser/item/type/FishingRodItem.java @@ -28,6 +28,7 @@ package org.geysermc.geyser.item.type; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.IntTag; import com.github.steveice10.opennbt.tag.builtin.Tag; +import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.geyser.session.GeyserSession; public class FishingRodItem extends Item { @@ -36,7 +37,7 @@ public class FishingRodItem extends Item { } @Override - public void translateNbtToBedrock(GeyserSession session, CompoundTag tag) { + public void translateNbtToBedrock(@NonNull GeyserSession session, @NonNull CompoundTag tag) { super.translateNbtToBedrock(session, tag); // Fix damage inconsistency diff --git a/core/src/main/java/org/geysermc/geyser/item/type/GoatHornItem.java b/core/src/main/java/org/geysermc/geyser/item/type/GoatHornItem.java index 4c21be833..aacb906c9 100644 --- a/core/src/main/java/org/geysermc/geyser/item/type/GoatHornItem.java +++ b/core/src/main/java/org/geysermc/geyser/item/type/GoatHornItem.java @@ -27,6 +27,7 @@ package org.geysermc.geyser.item.type; import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack; import com.github.steveice10.opennbt.tag.builtin.StringTag; +import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.protocol.bedrock.data.inventory.ItemData; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.registry.type.ItemMapping; @@ -71,7 +72,7 @@ public class GoatHornItem extends Item { } @Override - public ItemStack translateToJava(ItemData itemData, ItemMapping mapping, ItemMappings mappings) { + public @NonNull ItemStack translateToJava(@NonNull ItemData itemData, @NonNull ItemMapping mapping, @NonNull ItemMappings mappings) { ItemStack itemStack = super.translateToJava(itemData, mapping, mappings); int damage = itemData.getDamage(); diff --git a/core/src/main/java/org/geysermc/geyser/item/type/Item.java b/core/src/main/java/org/geysermc/geyser/item/type/Item.java index eef02ff0e..a7a59f6af 100644 --- a/core/src/main/java/org/geysermc/geyser/item/type/Item.java +++ b/core/src/main/java/org/geysermc/geyser/item/type/Item.java @@ -29,6 +29,7 @@ import com.github.steveice10.mc.protocol.data.game.Identifier; import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack; import com.github.steveice10.opennbt.tag.builtin.*; import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.protocol.bedrock.data.inventory.ItemData; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.inventory.item.Enchantment; @@ -99,8 +100,7 @@ public class Item { return builder; } - public ItemStack translateToJava(ItemData itemData, ItemMapping mapping, ItemMappings mappings) { - if (itemData == null) return null; + public @NonNull ItemStack translateToJava(@NonNull ItemData itemData, @NonNull ItemMapping mapping, @NonNull ItemMappings mappings) { if (itemData.getTag() == null) { return new ItemStack(javaId, itemData.getCount(), new CompoundTag("")); } @@ -206,7 +206,7 @@ public class Item { } } - protected final CompoundTag remapEnchantment(GeyserSession session, CompoundTag tag, CompoundTag rootTag) { + protected final @Nullable CompoundTag remapEnchantment(GeyserSession session, CompoundTag tag, CompoundTag rootTag) { Tag javaEnchId = tag.get("id"); if (!(javaEnchId instanceof StringTag)) return null; diff --git a/core/src/main/java/org/geysermc/geyser/item/type/MapItem.java b/core/src/main/java/org/geysermc/geyser/item/type/MapItem.java index cd63a3799..4405b66ad 100644 --- a/core/src/main/java/org/geysermc/geyser/item/type/MapItem.java +++ b/core/src/main/java/org/geysermc/geyser/item/type/MapItem.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.item.type; import com.github.steveice10.opennbt.tag.builtin.*; +import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.geyser.registry.type.ItemMapping; import org.geysermc.geyser.session.GeyserSession; @@ -35,7 +36,7 @@ public class MapItem extends Item { } @Override - public void translateNbtToBedrock(GeyserSession session, CompoundTag tag) { + public void translateNbtToBedrock(@NonNull GeyserSession session, @NonNull CompoundTag tag) { super.translateNbtToBedrock(session, tag); Tag mapId = tag.remove("map"); @@ -49,7 +50,7 @@ public class MapItem extends Item { } @Override - public void translateNbtToJava(CompoundTag tag, ItemMapping mapping) { + public void translateNbtToJava(@NonNull CompoundTag tag, @NonNull ItemMapping mapping) { super.translateNbtToJava(tag, mapping); IntTag mapNameIndex = tag.remove("map_name_index"); diff --git a/core/src/main/java/org/geysermc/geyser/item/type/PotionItem.java b/core/src/main/java/org/geysermc/geyser/item/type/PotionItem.java index 359639437..24dd56ef2 100644 --- a/core/src/main/java/org/geysermc/geyser/item/type/PotionItem.java +++ b/core/src/main/java/org/geysermc/geyser/item/type/PotionItem.java @@ -28,6 +28,7 @@ package org.geysermc.geyser.item.type; import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack; import com.github.steveice10.opennbt.tag.builtin.StringTag; import com.github.steveice10.opennbt.tag.builtin.Tag; +import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.protocol.bedrock.data.definitions.ItemDefinition; import org.cloudburstmc.protocol.bedrock.data.inventory.ItemData; import org.geysermc.geyser.GeyserImpl; @@ -69,7 +70,7 @@ public class PotionItem extends Item { } @Override - public ItemStack translateToJava(ItemData itemData, ItemMapping mapping, ItemMappings mappings) { + public @NonNull ItemStack translateToJava(@NonNull ItemData itemData, @NonNull ItemMapping mapping, @NonNull ItemMappings mappings) { Potion potion = Potion.getByBedrockId(itemData.getDamage()); ItemStack itemStack = super.translateToJava(itemData, mapping, mappings); if (potion != null) { diff --git a/core/src/main/java/org/geysermc/geyser/level/BedrockMapIcon.java b/core/src/main/java/org/geysermc/geyser/level/BedrockMapIcon.java index 9bb317996..eac8aca09 100644 --- a/core/src/main/java/org/geysermc/geyser/level/BedrockMapIcon.java +++ b/core/src/main/java/org/geysermc/geyser/level/BedrockMapIcon.java @@ -27,6 +27,7 @@ package org.geysermc.geyser.level; import com.github.steveice10.mc.protocol.data.game.level.map.MapIconType; import lombok.Getter; +import org.checkerframework.checker.nullness.qual.Nullable; public enum BedrockMapIcon { ICON_WHITE_ARROW(MapIconType.WHITE_ARROW, 0), @@ -87,7 +88,7 @@ public enum BedrockMapIcon { * @param iconType A MapIconType * @return The mapping for a BedrockMapIcon */ - public static BedrockMapIcon fromType(MapIconType iconType) { + public static @Nullable BedrockMapIcon fromType(MapIconType iconType) { for (BedrockMapIcon icon : VALUES) { if (icon.iconType.equals(iconType)) { return icon; diff --git a/core/src/main/java/org/geysermc/geyser/level/FireworkColor.java b/core/src/main/java/org/geysermc/geyser/level/FireworkColor.java index e005ab2d8..2ee8509a0 100644 --- a/core/src/main/java/org/geysermc/geyser/level/FireworkColor.java +++ b/core/src/main/java/org/geysermc/geyser/level/FireworkColor.java @@ -27,6 +27,7 @@ package org.geysermc.geyser.level; import net.kyori.adventure.text.format.TextColor; import net.kyori.adventure.util.HSVLike; +import org.checkerframework.checker.nullness.qual.NonNull; public enum FireworkColor { BLACK(1973019), @@ -75,7 +76,7 @@ public enum FireworkColor { * @return nearest named color. will always return a value * @since 4.0.0 */ - private static FireworkColor nearestTo(final HSVLike any) { + private static @NonNull FireworkColor nearestTo(final HSVLike any) { float matchedDistance = Float.MAX_VALUE; FireworkColor match = VALUES[0]; for (final FireworkColor potential : VALUES) { diff --git a/core/src/main/java/org/geysermc/geyser/level/GeyserAdvancement.java b/core/src/main/java/org/geysermc/geyser/level/GeyserAdvancement.java index 936248afe..e09cad19c 100644 --- a/core/src/main/java/org/geysermc/geyser/level/GeyserAdvancement.java +++ b/core/src/main/java/org/geysermc/geyser/level/GeyserAdvancement.java @@ -26,7 +26,7 @@ package org.geysermc.geyser.level; import com.github.steveice10.mc.protocol.data.game.advancement.Advancement; -import lombok.NonNull; +import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.geyser.session.cache.AdvancementsCache; import org.geysermc.geyser.text.ChatColor; @@ -73,7 +73,7 @@ public class GeyserAdvancement { return displayData != null && displayData.getFrameType() == Advancement.DisplayData.FrameType.CHALLENGE ? ChatColor.LIGHT_PURPLE : ChatColor.GREEN; } - public String getRootId(AdvancementsCache advancementsCache) { + public @NonNull String getRootId(AdvancementsCache advancementsCache) { if (rootId == null) { if (this.advancement.getParentId() == null) { // We are the root ID diff --git a/core/src/main/java/org/geysermc/geyser/level/GeyserWorldManager.java b/core/src/main/java/org/geysermc/geyser/level/GeyserWorldManager.java index a8e2d00ae..44c3b94b3 100644 --- a/core/src/main/java/org/geysermc/geyser/level/GeyserWorldManager.java +++ b/core/src/main/java/org/geysermc/geyser/level/GeyserWorldManager.java @@ -31,6 +31,8 @@ import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import it.unimi.dsi.fastutil.objects.Object2ObjectMap; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.ObjectArrayList; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.math.vector.Vector3i; import org.cloudburstmc.nbt.NbtMap; import org.cloudburstmc.nbt.NbtMapBuilder; @@ -39,9 +41,7 @@ import org.geysermc.erosion.util.BlockPositionIterator; import org.geysermc.erosion.util.LecternUtils; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.BlockEntityUtils; -import org.jetbrains.annotations.Nullable; -import javax.annotation.Nonnull; import java.util.List; import java.util.concurrent.CompletableFuture; @@ -99,6 +99,7 @@ public class GeyserWorldManager extends WorldManager { return; } List vectors = new ObjectArrayList<>(blockEntityInfos.size()); + //noinspection ForLoopReplaceableByForEach - avoid constructing iterator for (int i = 0; i < blockEntityInfos.size(); i++) { BlockEntityInfo info = blockEntityInfos.get(i); vectors.add(Vector3i.from(info.getX(), info.getY(), info.getZ())); @@ -171,7 +172,7 @@ public class GeyserWorldManager extends WorldManager { return false; } - @Nonnull + @NonNull @Override public CompletableFuture<@Nullable CompoundTag> getPickItemNbt(GeyserSession session, int x, int y, int z, boolean addNbtData) { var erosionHandler = session.getErosionHandler().getAsActive(); diff --git a/core/src/main/java/org/geysermc/geyser/level/WorldManager.java b/core/src/main/java/org/geysermc/geyser/level/WorldManager.java index a4de993d2..be7e2c139 100644 --- a/core/src/main/java/org/geysermc/geyser/level/WorldManager.java +++ b/core/src/main/java/org/geysermc/geyser/level/WorldManager.java @@ -29,12 +29,12 @@ import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode; import com.github.steveice10.mc.protocol.data.game.level.block.BlockEntityInfo; import com.github.steveice10.mc.protocol.data.game.setting.Difficulty; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.math.vector.Vector3i; import org.geysermc.erosion.util.BlockPositionIterator; import org.geysermc.geyser.session.GeyserSession; -import org.jetbrains.annotations.Nullable; -import javax.annotation.Nonnull; import java.util.List; import java.util.Locale; import java.util.concurrent.CompletableFuture; @@ -107,7 +107,7 @@ public abstract class WorldManager { * * We solve this problem by querying all loaded lecterns, where possible, and sending their information in a block entity * tag. - * + *

* Note that the lectern data may be sent asynchronously. * * @param session the session of the player @@ -210,8 +210,7 @@ public abstract class WorldManager { /** * Returns a list of biome identifiers available on the server. */ - @Nullable - public String[] getBiomeIdentifiers(boolean withTags) { + public String @Nullable [] getBiomeIdentifiers(boolean withTags) { return null; } @@ -220,7 +219,7 @@ public abstract class WorldManager { * * @return expected NBT for this item. */ - @Nonnull + @NonNull public CompletableFuture<@Nullable CompoundTag> getPickItemNbt(GeyserSession session, int x, int y, int z, boolean addNbtData) { return CompletableFuture.completedFuture(null); } diff --git a/core/src/main/java/org/geysermc/geyser/level/block/DoubleChestValue.java b/core/src/main/java/org/geysermc/geyser/level/block/DoubleChestValue.java index 8024af650..97c861df7 100644 --- a/core/src/main/java/org/geysermc/geyser/level/block/DoubleChestValue.java +++ b/core/src/main/java/org/geysermc/geyser/level/block/DoubleChestValue.java @@ -27,19 +27,14 @@ package org.geysermc.geyser.level.block; /** * This stores all values of double chests that are part of the Java block state. + * + * @param isFacingEast If true, then chest is facing east/west; if false, south/north + * @param isDirectionPositive If true, direction is positive (east/south); if false, direction is negative (west/north) + * @param isLeft If true, chest is the left of a pair; if false, chest is the right of a pair. */ public record DoubleChestValue( - /** - * If true, then chest is facing east/west; if false, south/north - */ boolean isFacingEast, - /** - * If true, direction is positive (east/south); if false, direction is negative (west/north) - */ boolean isDirectionPositive, - /** - * If true, chest is the left of a pair; if false, chest is the right of a pair. - */ boolean isLeft) { } diff --git a/core/src/main/java/org/geysermc/geyser/level/block/GeyserCustomBlockData.java b/core/src/main/java/org/geysermc/geyser/level/block/GeyserCustomBlockData.java index 413a4d1ed..dd58ebcb7 100644 --- a/core/src/main/java/org/geysermc/geyser/level/block/GeyserCustomBlockData.java +++ b/core/src/main/java/org/geysermc/geyser/level/block/GeyserCustomBlockData.java @@ -28,6 +28,7 @@ package org.geysermc.geyser.level.block; import it.unimi.dsi.fastutil.objects.*; import lombok.RequiredArgsConstructor; import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.Constants; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.api.block.custom.CustomBlockData; @@ -37,9 +38,6 @@ import org.geysermc.geyser.api.block.custom.component.CustomBlockComponents; import org.geysermc.geyser.api.block.custom.property.CustomBlockProperty; import org.geysermc.geyser.api.block.custom.property.PropertyType; import org.geysermc.geyser.api.util.CreativeCategory; -import org.jetbrains.annotations.NotNull; - -import javax.annotation.Nullable; import java.util.List; import java.util.Map; @@ -142,7 +140,7 @@ public class GeyserCustomBlockData implements CustomBlockData { } @Override - public CustomBlockState.@NotNull Builder blockStateBuilder() { + public CustomBlockState.@NonNull Builder blockStateBuilder() { return new GeyserCustomBlockState.CustomBlockStateBuilder(this); } diff --git a/core/src/main/java/org/geysermc/geyser/level/block/GeyserCustomBlockState.java b/core/src/main/java/org/geysermc/geyser/level/block/GeyserCustomBlockState.java index 576bd9743..d147ffedc 100644 --- a/core/src/main/java/org/geysermc/geyser/level/block/GeyserCustomBlockState.java +++ b/core/src/main/java/org/geysermc/geyser/level/block/GeyserCustomBlockState.java @@ -54,7 +54,7 @@ public class GeyserCustomBlockState implements CustomBlockState { @SuppressWarnings("unchecked") @Override - public @NonNull T property(String propertyName) { + public @NonNull T property(@NonNull String propertyName) { return (T) properties.get(propertyName); } diff --git a/core/src/main/java/org/geysermc/geyser/level/block/GeyserJavaBlockState.java b/core/src/main/java/org/geysermc/geyser/level/block/GeyserJavaBlockState.java index 725afe6df..5604a543e 100644 --- a/core/src/main/java/org/geysermc/geyser/level/block/GeyserJavaBlockState.java +++ b/core/src/main/java/org/geysermc/geyser/level/block/GeyserJavaBlockState.java @@ -52,7 +52,7 @@ public class GeyserJavaBlockState implements JavaBlockState { } @Override - public @NonNull boolean waterlogged() { + public boolean waterlogged() { return waterlogged; } @@ -62,7 +62,7 @@ public class GeyserJavaBlockState implements JavaBlockState { } @Override - public @NonNull boolean canBreakWithHand() { + public boolean canBreakWithHand() { return canBreakWithHand; } @@ -77,7 +77,7 @@ public class GeyserJavaBlockState implements JavaBlockState { } @Override - public @Nullable boolean hasBlockEntity() { + public boolean hasBlockEntity() { return hasBlockEntity; } @@ -118,7 +118,7 @@ public class GeyserJavaBlockState implements JavaBlockState { } @Override - public Builder waterlogged(@NonNull boolean waterlogged) { + public Builder waterlogged(boolean waterlogged) { this.waterlogged = waterlogged; return this; } @@ -130,7 +130,7 @@ public class GeyserJavaBlockState implements JavaBlockState { } @Override - public Builder canBreakWithHand(@NonNull boolean canBreakWithHand) { + public Builder canBreakWithHand(boolean canBreakWithHand) { this.canBreakWithHand = canBreakWithHand; return this; } @@ -148,7 +148,7 @@ public class GeyserJavaBlockState implements JavaBlockState { } @Override - public Builder hasBlockEntity(@Nullable boolean hasBlockEntity) { + public Builder hasBlockEntity(boolean hasBlockEntity) { this.hasBlockEntity = hasBlockEntity; return this; } diff --git a/core/src/main/java/org/geysermc/geyser/level/chunk/bitarray/BitArrayVersion.java b/core/src/main/java/org/geysermc/geyser/level/chunk/bitarray/BitArrayVersion.java index d95767b97..fbfd82144 100644 --- a/core/src/main/java/org/geysermc/geyser/level/chunk/bitarray/BitArrayVersion.java +++ b/core/src/main/java/org/geysermc/geyser/level/chunk/bitarray/BitArrayVersion.java @@ -25,6 +25,7 @@ package org.geysermc.geyser.level.chunk.bitarray; +import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.util.MathUtils; public enum BitArrayVersion { @@ -61,7 +62,7 @@ public enum BitArrayVersion { throw new IllegalArgumentException("Invalid palette version: " + version); } - public static BitArrayVersion forBitsCeil(int bits) { + public static @Nullable BitArrayVersion forBitsCeil(int bits) { for (int i = VALUES.length - 1; i >= 0; i--) { BitArrayVersion version = VALUES[i]; if (version.bits >= bits) { @@ -79,10 +80,6 @@ public enum BitArrayVersion { return maxEntryValue; } - public int getWordsForSize(int size) { - return MathUtils.ceil((float) size / entriesPerWord); - } - public BitArrayVersion next() { return next; } diff --git a/core/src/main/java/org/geysermc/geyser/level/physics/CollisionManager.java b/core/src/main/java/org/geysermc/geyser/level/physics/CollisionManager.java index b983da8b4..2c3da3c41 100644 --- a/core/src/main/java/org/geysermc/geyser/level/physics/CollisionManager.java +++ b/core/src/main/java/org/geysermc/geyser/level/physics/CollisionManager.java @@ -25,6 +25,7 @@ package org.geysermc.geyser.level.physics; +import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.math.GenericMath; import org.cloudburstmc.math.vector.Vector3d; import org.cloudburstmc.math.vector.Vector3f; @@ -133,7 +134,7 @@ public class CollisionManager { * @param teleported whether the Bedrock player has teleported to a new position. If true, movement correction is skipped. * @return the position to send to the Java server, or null to cancel sending the packet */ - public Vector3d adjustBedrockPosition(Vector3f bedrockPosition, boolean onGround, boolean teleported) { + public @Nullable Vector3d adjustBedrockPosition(Vector3f bedrockPosition, boolean onGround, boolean teleported) { PistonCache pistonCache = session.getPistonCache(); // Bedrock clients tend to fall off of honey blocks, so we need to teleport them to the new position if (pistonCache.isPlayerAttachedToHoney()) { diff --git a/core/src/main/java/org/geysermc/geyser/level/physics/Direction.java b/core/src/main/java/org/geysermc/geyser/level/physics/Direction.java index fa5201db9..09ff89800 100644 --- a/core/src/main/java/org/geysermc/geyser/level/physics/Direction.java +++ b/core/src/main/java/org/geysermc/geyser/level/physics/Direction.java @@ -25,10 +25,9 @@ package org.geysermc.geyser.level.physics; -import org.cloudburstmc.math.vector.Vector3i; import lombok.Getter; - -import javax.annotation.Nonnull; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.cloudburstmc.math.vector.Vector3i; public enum Direction { DOWN(1, Vector3i.from(0, -1, 0), Axis.Y, com.github.steveice10.mc.protocol.data.game.entity.object.Direction.DOWN), @@ -66,8 +65,7 @@ public enum Direction { return axis == Axis.X || axis == Axis.Z; } - @Nonnull - public static Direction fromPistonValue(com.github.steveice10.mc.protocol.data.game.entity.object.Direction pistonValue) { + public static @NonNull Direction fromPistonValue(com.github.steveice10.mc.protocol.data.game.entity.object.Direction pistonValue) { for (Direction direction : VALUES) { if (direction.pistonValue == pistonValue) { return direction; diff --git a/core/src/main/java/org/geysermc/geyser/level/physics/PistonBehavior.java b/core/src/main/java/org/geysermc/geyser/level/physics/PistonBehavior.java index a6b25d01e..fa28e7cb8 100644 --- a/core/src/main/java/org/geysermc/geyser/level/physics/PistonBehavior.java +++ b/core/src/main/java/org/geysermc/geyser/level/physics/PistonBehavior.java @@ -25,6 +25,8 @@ package org.geysermc.geyser.level.physics; +import org.checkerframework.checker.nullness.qual.NonNull; + import java.util.Locale; public enum PistonBehavior { @@ -35,7 +37,7 @@ public enum PistonBehavior { private static final PistonBehavior[] VALUES = values(); - public static PistonBehavior getByName(String name) { + public static @NonNull PistonBehavior getByName(String name) { String upperCase = name.toUpperCase(Locale.ROOT); for (PistonBehavior type : VALUES) { if (type.name().equals(upperCase)) { diff --git a/core/src/main/java/org/geysermc/geyser/network/GameProtocol.java b/core/src/main/java/org/geysermc/geyser/network/GameProtocol.java index 4ffdbcf48..11c7bc11e 100644 --- a/core/src/main/java/org/geysermc/geyser/network/GameProtocol.java +++ b/core/src/main/java/org/geysermc/geyser/network/GameProtocol.java @@ -27,6 +27,7 @@ package org.geysermc.geyser.network; import com.github.steveice10.mc.protocol.codec.MinecraftCodec; import com.github.steveice10.mc.protocol.codec.PacketCodec; +import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.protocol.bedrock.codec.BedrockCodec; import org.cloudburstmc.protocol.bedrock.codec.v589.Bedrock_v589; import org.cloudburstmc.protocol.bedrock.codec.v594.Bedrock_v594; @@ -82,7 +83,7 @@ public final class GameProtocol { * @param protocolVersion The protocol version to attempt to find * @return The packet codec, or null if the client's protocol is unsupported */ - public static BedrockCodec getBedrockCodec(int protocolVersion) { + public static @Nullable BedrockCodec getBedrockCodec(int protocolVersion) { for (BedrockCodec packetCodec : SUPPORTED_BEDROCK_CODECS) { if (packetCodec.getProtocolVersion() == protocolVersion) { return packetCodec; diff --git a/core/src/main/java/org/geysermc/geyser/network/GeyserServerInitializer.java b/core/src/main/java/org/geysermc/geyser/network/GeyserServerInitializer.java index f19a46e6a..bb8e87440 100644 --- a/core/src/main/java/org/geysermc/geyser/network/GeyserServerInitializer.java +++ b/core/src/main/java/org/geysermc/geyser/network/GeyserServerInitializer.java @@ -28,6 +28,7 @@ package org.geysermc.geyser.network; import io.netty.channel.Channel; import io.netty.channel.DefaultEventLoopGroup; import io.netty.util.concurrent.DefaultThreadFactory; +import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.protocol.bedrock.BedrockPeer; import org.cloudburstmc.protocol.bedrock.BedrockServerSession; import org.cloudburstmc.protocol.bedrock.netty.initializer.BedrockServerInitializer; @@ -35,7 +36,6 @@ import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.api.event.bedrock.SessionInitializeEvent; import org.geysermc.geyser.session.GeyserSession; -import javax.annotation.Nonnull; import java.net.InetSocketAddress; public class GeyserServerInitializer extends BedrockServerInitializer { @@ -52,7 +52,7 @@ public class GeyserServerInitializer extends BedrockServerInitializer { } @Override - public void initSession(@Nonnull BedrockServerSession bedrockServerSession) { + public void initSession(@NonNull BedrockServerSession bedrockServerSession) { try { if (this.geyser.getGeyserServer().getProxiedAddresses() != null) { InetSocketAddress address = this.geyser.getGeyserServer().getProxiedAddresses().get((InetSocketAddress) bedrockServerSession.getSocketAddress()); diff --git a/core/src/main/java/org/geysermc/geyser/network/netty/ChannelWrapper.java b/core/src/main/java/org/geysermc/geyser/network/netty/ChannelWrapper.java index 26015a96f..a756c70eb 100644 --- a/core/src/main/java/org/geysermc/geyser/network/netty/ChannelWrapper.java +++ b/core/src/main/java/org/geysermc/geyser/network/netty/ChannelWrapper.java @@ -29,6 +29,7 @@ import io.netty.buffer.ByteBufAllocator; import io.netty.channel.*; import io.netty.util.Attribute; import io.netty.util.AttributeKey; +import org.checkerframework.checker.nullness.qual.NonNull; import java.net.SocketAddress; @@ -259,7 +260,7 @@ public class ChannelWrapper implements Channel { } @Override - public int compareTo(Channel o) { + public int compareTo(@NonNull Channel o) { return source.compareTo(o); } } diff --git a/core/src/main/java/org/geysermc/geyser/network/netty/LocalChannelWrapper.java b/core/src/main/java/org/geysermc/geyser/network/netty/LocalChannelWrapper.java index 258fa69eb..53221274f 100644 --- a/core/src/main/java/org/geysermc/geyser/network/netty/LocalChannelWrapper.java +++ b/core/src/main/java/org/geysermc/geyser/network/netty/LocalChannelWrapper.java @@ -30,25 +30,20 @@ import io.netty.channel.local.LocalChannel; import io.netty.channel.local.LocalServerChannel; import java.net.InetSocketAddress; +import java.util.Objects; public class LocalChannelWrapper extends LocalChannel { + private final ChannelWrapper wrapper; + /** * {@link #newChannelPipeline()} is called during super, so this exists until the wrapper can be initialized. */ private volatile ChannelWrapper tempWrapper; - public LocalChannelWrapper() { - wrapper = new ChannelWrapper(this); - } - public LocalChannelWrapper(LocalServerChannel parent, LocalChannel peer) { super(parent, peer); - if (tempWrapper == null) { - this.wrapper = new ChannelWrapper(this); - } else { - this.wrapper = tempWrapper; - } + this.wrapper = Objects.requireNonNullElseGet(tempWrapper, () -> new ChannelWrapper(this)); wrapper.remoteAddress(new InetSocketAddress(0)); } diff --git a/core/src/main/java/org/geysermc/geyser/network/netty/LocalSession.java b/core/src/main/java/org/geysermc/geyser/network/netty/LocalSession.java index 551bc1deb..a2951116f 100644 --- a/core/src/main/java/org/geysermc/geyser/network/netty/LocalSession.java +++ b/core/src/main/java/org/geysermc/geyser/network/netty/LocalSession.java @@ -37,6 +37,7 @@ import io.netty.buffer.ByteBufAllocator; import io.netty.channel.*; import io.netty.channel.unix.PreferredDirectByteBufAllocator; import io.netty.handler.codec.haproxy.*; +import org.checkerframework.checker.nullness.qual.NonNull; import java.net.Inet4Address; import java.net.InetSocketAddress; @@ -75,7 +76,7 @@ public final class LocalSession extends TcpSession { bootstrap.channel(LocalChannelWithRemoteAddress.class); bootstrap.handler(new ChannelInitializer() { @Override - public void initChannel(LocalChannelWithRemoteAddress channel) { + public void initChannel(@NonNull LocalChannelWithRemoteAddress channel) { channel.spoofedRemoteAddress(new InetSocketAddress(clientIp, 0)); PacketProtocol protocol = getPacketProtocol(); protocol.newClientSession(LocalSession.this); @@ -119,7 +120,7 @@ public final class LocalSession extends TcpSession { if (getFlag(BuiltinFlags.ENABLE_CLIENT_PROXY_PROTOCOL, false) && clientAddress != null) { pipeline.addFirst("proxy-protocol-packet-sender", new ChannelInboundHandlerAdapter() { @Override - public void channelActive(ChannelHandlerContext ctx) throws Exception { + public void channelActive(@NonNull ChannelHandlerContext ctx) throws Exception { HAProxyProxiedProtocol proxiedProtocol = clientAddress.getAddress() instanceof Inet4Address ? HAProxyProxiedProtocol.TCP4 : HAProxyProxiedProtocol.TCP6; InetSocketAddress remoteAddress; if (ctx.channel().remoteAddress() instanceof InetSocketAddress) { diff --git a/core/src/main/java/org/geysermc/geyser/network/netty/handler/RakConnectionRequestHandler.java b/core/src/main/java/org/geysermc/geyser/network/netty/handler/RakConnectionRequestHandler.java index 8c0412240..26bda9f2b 100644 --- a/core/src/main/java/org/geysermc/geyser/network/netty/handler/RakConnectionRequestHandler.java +++ b/core/src/main/java/org/geysermc/geyser/network/netty/handler/RakConnectionRequestHandler.java @@ -49,7 +49,7 @@ public class RakConnectionRequestHandler extends ChannelInboundHandlerAdapter { private final GeyserServer server; @Override - public void channelRead(@NonNull ChannelHandlerContext ctx, @NonNull Object msg) throws Exception { + public void channelRead(@NonNull ChannelHandlerContext ctx, @NonNull Object msg) { if (!(msg instanceof DatagramPacket packet)) { ctx.fireChannelRead(msg); return; diff --git a/core/src/main/java/org/geysermc/geyser/network/netty/proxy/ProxyProtocolDecoder.java b/core/src/main/java/org/geysermc/geyser/network/netty/proxy/ProxyProtocolDecoder.java index b14006336..67fb3ecdd 100644 --- a/core/src/main/java/org/geysermc/geyser/network/netty/proxy/ProxyProtocolDecoder.java +++ b/core/src/main/java/org/geysermc/geyser/network/netty/proxy/ProxyProtocolDecoder.java @@ -30,6 +30,7 @@ import io.netty.handler.codec.ProtocolDetectionResult; import io.netty.handler.codec.haproxy.*; import io.netty.util.ByteProcessor; import io.netty.util.CharsetUtil; +import org.checkerframework.checker.nullness.qual.Nullable; import java.util.Objects; @@ -75,7 +76,7 @@ public final class ProxyProtocolDecoder { /** * Protocol specification version */ - private int decodingVersion = -1; + private final int decodingVersion; /** * The latest v2 spec (2014/05/18) allows for additional data to be sent in the proxy protocol header beyond the @@ -87,7 +88,7 @@ public final class ProxyProtocolDecoder { this.decodingVersion = version; } - public static HAProxyMessage decode(ByteBuf packet, int version) { + public static @Nullable HAProxyMessage decode(ByteBuf packet, int version) { if (version == -1) { return null; } @@ -95,7 +96,7 @@ public final class ProxyProtocolDecoder { return decoder.decodeHeader(packet); } - private HAProxyMessage decodeHeader(ByteBuf in) { + private @Nullable HAProxyMessage decodeHeader(ByteBuf in) { final ByteBuf decoded = decodingVersion == 1 ? decodeLine(in) : decodeStruct(in); if (decoded == null) { return null; @@ -233,8 +234,8 @@ public final class ProxyProtocolDecoder { dstPort = header.readUnsignedShort(); } + //noinspection StatementWithEmptyBody while (skipNextTLV(header)) { - } return new HAProxyMessage(ver, cmd, protAndFam, srcAddress, dstAddress, srcPort, dstPort); } @@ -479,7 +480,7 @@ public final class ProxyProtocolDecoder { * @return frame the {@link ByteBuf} which represent the frame or {@code null} if no frame could * be created */ - public ByteBuf extract(ByteBuf buffer) { + public @Nullable ByteBuf extract(ByteBuf buffer) { final int eoh = findEndOfHeader(buffer); if (!discarding) { if (eoh >= 0) { diff --git a/core/src/main/java/org/geysermc/geyser/pack/GeyserResourcePackManifest.java b/core/src/main/java/org/geysermc/geyser/pack/GeyserResourcePackManifest.java index ddcee6ad5..25a0f0ee0 100644 --- a/core/src/main/java/org/geysermc/geyser/pack/GeyserResourcePackManifest.java +++ b/core/src/main/java/org/geysermc/geyser/pack/GeyserResourcePackManifest.java @@ -30,8 +30,8 @@ import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonDeserializer; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.geyser.api.pack.ResourcePackManifest; -import org.jetbrains.annotations.NotNull; import java.io.IOException; import java.util.Collection; @@ -49,7 +49,7 @@ public record GeyserResourcePackManifest(@JsonProperty("format_version") int for public record Version(int major, int minor, int patch) implements ResourcePackManifest.Version { @Override - public @NotNull String toString() { + public @NonNull String toString() { return major + "." + minor + "." + patch; } diff --git a/core/src/main/java/org/geysermc/geyser/pack/SkullResourcePackManager.java b/core/src/main/java/org/geysermc/geyser/pack/SkullResourcePackManager.java index f59ae8026..e7a9f4f1e 100644 --- a/core/src/main/java/org/geysermc/geyser/pack/SkullResourcePackManager.java +++ b/core/src/main/java/org/geysermc/geyser/pack/SkullResourcePackManager.java @@ -27,6 +27,7 @@ package org.geysermc.geyser.pack; import it.unimi.dsi.fastutil.Pair; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; +import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.Constants; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.api.pack.ResourcePackManifest; @@ -63,7 +64,7 @@ public class SkullResourcePackManager { public static final Map SKULL_SKINS = new Object2ObjectOpenHashMap<>(); @SuppressWarnings("ResultOfMethodCallIgnored") - public static Path createResourcePack() { + public static @Nullable Path createResourcePack() { Path cachePath = GeyserImpl.getInstance().getBootstrap().getConfigFolder().resolve("cache"); try { Files.createDirectories(cachePath); @@ -165,7 +166,7 @@ public class SkullResourcePackManager { } private static void addBaseResources(ZipOutputStream zipOS) throws IOException { - try (BufferedReader reader = new BufferedReader(new InputStreamReader(GeyserImpl.getInstance().getBootstrap().getResource("bedrock/skull_resource_pack_files.txt")))) { + try (BufferedReader reader = new BufferedReader(new InputStreamReader(GeyserImpl.getInstance().getBootstrap().getResourceOrThrow("bedrock/skull_resource_pack_files.txt")))) { List lines = reader.lines().toList(); for (String path : lines) { ZipEntry entry = new ZipEntry(path); diff --git a/core/src/main/java/org/geysermc/geyser/ping/GeyserLegacyPingPassthrough.java b/core/src/main/java/org/geysermc/geyser/ping/GeyserLegacyPingPassthrough.java index e3c72c174..64ad2c445 100644 --- a/core/src/main/java/org/geysermc/geyser/ping/GeyserLegacyPingPassthrough.java +++ b/core/src/main/java/org/geysermc/geyser/ping/GeyserLegacyPingPassthrough.java @@ -27,6 +27,7 @@ package org.geysermc.geyser.ping; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; +import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.nbt.util.VarInts; import io.netty.handler.codec.haproxy.HAProxyCommand; import io.netty.handler.codec.haproxy.HAProxyProxiedProtocol; @@ -57,7 +58,7 @@ public class GeyserLegacyPingPassthrough implements IGeyserPingPassthrough, Runn * @param geyser Geyser * @return GeyserPingPassthrough, or null if not initialized */ - public static IGeyserPingPassthrough init(GeyserImpl geyser) { + public static @Nullable IGeyserPingPassthrough init(GeyserImpl geyser) { if (geyser.getConfig().isPassthroughMotd() || geyser.getConfig().isPassthroughPlayerCounts()) { GeyserLegacyPingPassthrough pingPassthrough = new GeyserLegacyPingPassthrough(geyser); // Ensure delay is not zero diff --git a/core/src/main/java/org/geysermc/geyser/ping/IGeyserPingPassthrough.java b/core/src/main/java/org/geysermc/geyser/ping/IGeyserPingPassthrough.java index b6095cce2..318035e32 100644 --- a/core/src/main/java/org/geysermc/geyser/ping/IGeyserPingPassthrough.java +++ b/core/src/main/java/org/geysermc/geyser/ping/IGeyserPingPassthrough.java @@ -25,7 +25,7 @@ package org.geysermc.geyser.ping; -import javax.annotation.Nullable; +import org.checkerframework.checker.nullness.qual.Nullable; import java.net.InetSocketAddress; /** diff --git a/core/src/main/java/org/geysermc/geyser/registry/AbstractMappedRegistry.java b/core/src/main/java/org/geysermc/geyser/registry/AbstractMappedRegistry.java index fc4e3d022..aea7d539e 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/AbstractMappedRegistry.java +++ b/core/src/main/java/org/geysermc/geyser/registry/AbstractMappedRegistry.java @@ -25,9 +25,9 @@ package org.geysermc.geyser.registry; +import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.registry.loader.RegistryLoader; -import javax.annotation.Nullable; import java.util.Map; import java.util.Optional; import java.util.function.Function; diff --git a/core/src/main/java/org/geysermc/geyser/registry/ArrayRegistry.java b/core/src/main/java/org/geysermc/geyser/registry/ArrayRegistry.java index 124aea713..3df3ded58 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/ArrayRegistry.java +++ b/core/src/main/java/org/geysermc/geyser/registry/ArrayRegistry.java @@ -25,9 +25,9 @@ package org.geysermc.geyser.registry; +import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.registry.loader.RegistryLoader; -import javax.annotation.Nullable; import java.util.function.Supplier; /** diff --git a/core/src/main/java/org/geysermc/geyser/registry/BlockRegistries.java b/core/src/main/java/org/geysermc/geyser/registry/BlockRegistries.java index 49fd90cf7..aa9d6fc36 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/BlockRegistries.java +++ b/core/src/main/java/org/geysermc/geyser/registry/BlockRegistries.java @@ -33,7 +33,6 @@ import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import org.geysermc.geyser.api.block.custom.CustomBlockData; import org.geysermc.geyser.api.block.custom.CustomBlockState; -import org.geysermc.geyser.api.block.custom.nonvanilla.JavaBlockItem; import org.geysermc.geyser.api.block.custom.nonvanilla.JavaBlockState; import org.geysermc.geyser.registry.loader.CollisionRegistryLoader; import org.geysermc.geyser.registry.loader.RegistryLoaders; diff --git a/core/src/main/java/org/geysermc/geyser/registry/IntMappedRegistry.java b/core/src/main/java/org/geysermc/geyser/registry/IntMappedRegistry.java index 892f4a6df..981ed0f8c 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/IntMappedRegistry.java +++ b/core/src/main/java/org/geysermc/geyser/registry/IntMappedRegistry.java @@ -26,8 +26,8 @@ package org.geysermc.geyser.registry; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.registry.loader.RegistryLoader; -import org.jetbrains.annotations.Nullable; import java.util.function.Supplier; diff --git a/core/src/main/java/org/geysermc/geyser/registry/Registry.java b/core/src/main/java/org/geysermc/geyser/registry/Registry.java index f6be19af2..8836502b3 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/Registry.java +++ b/core/src/main/java/org/geysermc/geyser/registry/Registry.java @@ -25,7 +25,6 @@ package org.geysermc.geyser.registry; -import org.cloudburstmc.nbt.NbtMap; import org.geysermc.geyser.registry.loader.RegistryLoader; import java.util.function.Consumer; diff --git a/core/src/main/java/org/geysermc/geyser/registry/VersionedRegistry.java b/core/src/main/java/org/geysermc/geyser/registry/VersionedRegistry.java index cfed73d24..ec7665ff0 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/VersionedRegistry.java +++ b/core/src/main/java/org/geysermc/geyser/registry/VersionedRegistry.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.registry; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.geyser.registry.loader.RegistryLoader; import java.util.Map; @@ -53,7 +54,9 @@ public class VersionedRegistry extends AbstractMappedRegistry current = null; for (Int2ObjectMap.Entry entry : this.mappings.int2ObjectEntrySet()) { @@ -69,7 +72,10 @@ public class VersionedRegistry extends AbstractMappedRegistry implements Regi this.mapper = mapper; } + @SuppressWarnings("unchecked") @Override public Map load(String input) { Map entries = new Object2ObjectOpenHashMap<>(); diff --git a/core/src/main/java/org/geysermc/geyser/registry/loader/BiomeIdentifierRegistryLoader.java b/core/src/main/java/org/geysermc/geyser/registry/loader/BiomeIdentifierRegistryLoader.java index f7fb708fb..3205004e4 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/loader/BiomeIdentifierRegistryLoader.java +++ b/core/src/main/java/org/geysermc/geyser/registry/loader/BiomeIdentifierRegistryLoader.java @@ -47,7 +47,7 @@ public class BiomeIdentifierRegistryLoader implements RegistryLoader> biomeEntriesType = new TypeReference<>() { }; Map biomeEntries; - try (InputStream stream = GeyserImpl.getInstance().getBootstrap().getResource("mappings/biomes.json")) { + try (InputStream stream = GeyserImpl.getInstance().getBootstrap().getResourceOrThrow("mappings/biomes.json")) { biomeEntries = GeyserImpl.JSON_MAPPER.readValue(stream, biomeEntriesType); } catch (IOException e) { throw new AssertionError("Unable to load Bedrock runtime biomes", e); diff --git a/core/src/main/java/org/geysermc/geyser/registry/loader/CollisionRegistryLoader.java b/core/src/main/java/org/geysermc/geyser/registry/loader/CollisionRegistryLoader.java index bf2d72b27..95e8bd2c1 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/loader/CollisionRegistryLoader.java +++ b/core/src/main/java/org/geysermc/geyser/registry/loader/CollisionRegistryLoader.java @@ -32,6 +32,7 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import lombok.AllArgsConstructor; +import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.level.physics.BoundingBox; import org.geysermc.geyser.registry.BlockRegistries; @@ -66,7 +67,7 @@ public class CollisionRegistryLoader extends MultiResourceRegistryLoader collisionList; - try (InputStream stream = GeyserImpl.getInstance().getBootstrap().getResource(input.value())) { + try (InputStream stream = GeyserImpl.getInstance().getBootstrap().getResourceOrThrow(input.value())) { ArrayNode collisionNode = (ArrayNode) GeyserImpl.JSON_MAPPER.readTree(stream); collisionList = loadBoundingBoxes(collisionNode); } catch (Exception e) { @@ -101,7 +102,7 @@ public class CollisionRegistryLoader extends MultiResourceRegistryLoader, CollisionInfo> annotationMap, List collisionList) { + private @Nullable BlockCollision instantiateCollision(BlockMapping mapping, Map, CollisionInfo> annotationMap, List collisionList) { String[] blockIdParts = mapping.getJavaIdentifier().split("\\["); String blockName = blockIdParts[0].replace("minecraft:", ""); String params = ""; diff --git a/core/src/main/java/org/geysermc/geyser/registry/loader/EffectRegistryLoader.java b/core/src/main/java/org/geysermc/geyser/registry/loader/EffectRegistryLoader.java index 9e1bbc6aa..aa95c1d56 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/loader/EffectRegistryLoader.java +++ b/core/src/main/java/org/geysermc/geyser/registry/loader/EffectRegistryLoader.java @@ -43,7 +43,7 @@ public abstract class EffectRegistryLoader implements RegistryLoader load(String input) { JsonNode enchantmentsNode; - try (InputStream enchantmentsStream = GeyserImpl.getInstance().getBootstrap().getResource(input)) { + try (InputStream enchantmentsStream = GeyserImpl.getInstance().getBootstrap().getResourceOrThrow(input)) { enchantmentsNode = GeyserImpl.JSON_MAPPER.readTree(enchantmentsStream); } catch (Exception e) { throw new AssertionError("Unable to load enchantment data", e); diff --git a/core/src/main/java/org/geysermc/geyser/registry/loader/NbtRegistryLoader.java b/core/src/main/java/org/geysermc/geyser/registry/loader/NbtRegistryLoader.java index fcdbfcab3..c1f0d4fee 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/loader/NbtRegistryLoader.java +++ b/core/src/main/java/org/geysermc/geyser/registry/loader/NbtRegistryLoader.java @@ -37,7 +37,7 @@ public class NbtRegistryLoader implements RegistryLoader { @Override public NbtMap load(String input) { - try (NBTInputStream nbtInputStream = NbtUtils.createNetworkReader(GeyserImpl.getInstance().getBootstrap().getResource(input), true, true)) { + try (NBTInputStream nbtInputStream = NbtUtils.createNetworkReader(GeyserImpl.getInstance().getBootstrap().getResourceOrThrow(input), true, true)) { return (NbtMap) nbtInputStream.readTag(); } catch (Exception e) { throw new AssertionError("Failed to load registrations for " + input, e); diff --git a/core/src/main/java/org/geysermc/geyser/registry/loader/PotionMixRegistryLoader.java b/core/src/main/java/org/geysermc/geyser/registry/loader/PotionMixRegistryLoader.java index 7d5061382..0eec7cdb6 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/loader/PotionMixRegistryLoader.java +++ b/core/src/main/java/org/geysermc/geyser/registry/loader/PotionMixRegistryLoader.java @@ -27,6 +27,7 @@ package org.geysermc.geyser.registry.loader; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; +import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.protocol.bedrock.data.inventory.crafting.PotionMixData; import org.geysermc.geyser.inventory.item.Potion; import org.geysermc.geyser.item.Items; @@ -44,7 +45,7 @@ import java.util.Set; * Generates a collection of {@link PotionMixData} that enables the * Bedrock client to place brewing items into the brewing stand. * (Does not contain actual potion mixes.) - * + *

* Designed to replicate Java Edition behavior. * (Ex: Bedrock cannot normally place glass bottles or fully upgraded * potions into the brewing stand, but Java can.) diff --git a/core/src/main/java/org/geysermc/geyser/registry/loader/SoundRegistryLoader.java b/core/src/main/java/org/geysermc/geyser/registry/loader/SoundRegistryLoader.java index 6703726ea..318cc08d7 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/loader/SoundRegistryLoader.java +++ b/core/src/main/java/org/geysermc/geyser/registry/loader/SoundRegistryLoader.java @@ -43,7 +43,7 @@ public class SoundRegistryLoader implements RegistryLoader load(String input) { JsonNode soundsTree; - try (InputStream stream = GeyserImpl.getInstance().getBootstrap().getResource(input)) { + try (InputStream stream = GeyserImpl.getInstance().getBootstrap().getResourceOrThrow(input)) { soundsTree = GeyserImpl.JSON_MAPPER.readTree(stream); } catch (IOException e) { throw new AssertionError("Unable to load sound mappings", e); diff --git a/core/src/main/java/org/geysermc/geyser/registry/mappings/MappingsConfigReader.java b/core/src/main/java/org/geysermc/geyser/registry/mappings/MappingsConfigReader.java index 039412957..d09e0b5a1 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/mappings/MappingsConfigReader.java +++ b/core/src/main/java/org/geysermc/geyser/registry/mappings/MappingsConfigReader.java @@ -28,6 +28,7 @@ package org.geysermc.geyser.registry.mappings; import com.fasterxml.jackson.databind.JsonNode; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; +import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.api.item.custom.CustomItemData; import org.geysermc.geyser.registry.mappings.util.CustomBlockMapping; @@ -57,6 +58,8 @@ public class MappingsConfigReader { } } + + @SuppressWarnings("BooleanMethodIsAlwaysInverted") public boolean ensureMappingsDirectory(Path mappingsDirectory) { if (!Files.exists(mappingsDirectory)) { try { @@ -92,7 +95,7 @@ public class MappingsConfigReader { } } - public JsonNode getMappingsRoot(Path file) { + public @Nullable JsonNode getMappingsRoot(Path file) { JsonNode mappingsRoot; try { mappingsRoot = GeyserImpl.JSON_MAPPER.readTree(file.toFile()); @@ -121,9 +124,13 @@ public class MappingsConfigReader { public void readItemMappingsFromJson(Path file, BiConsumer consumer) { JsonNode mappingsRoot = getMappingsRoot(file); + if (mappingsRoot == null) { + return; + } + int formatVersion = getFormatVersion(mappingsRoot, file); - if (formatVersion < 0 || mappingsRoot == null) { + if (formatVersion < 0) { return; } @@ -133,9 +140,13 @@ public class MappingsConfigReader { public void readBlockMappingsFromJson(Path file, BiConsumer consumer) { JsonNode mappingsRoot = getMappingsRoot(file); + if (mappingsRoot == null) { + return; + } + int formatVersion = getFormatVersion(mappingsRoot, file); - if (formatVersion < 0 || mappingsRoot == null) { + if (formatVersion < 0) { return; } diff --git a/core/src/main/java/org/geysermc/geyser/registry/mappings/util/CustomBlockMapping.java b/core/src/main/java/org/geysermc/geyser/registry/mappings/util/CustomBlockMapping.java index 3dbb7908e..10108cc9c 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/mappings/util/CustomBlockMapping.java +++ b/core/src/main/java/org/geysermc/geyser/registry/mappings/util/CustomBlockMapping.java @@ -25,11 +25,11 @@ package org.geysermc.geyser.registry.mappings.util; -import java.util.Map; - import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.geyser.api.block.custom.CustomBlockData; +import java.util.Map; + /** * This class is used to store a custom block mappings, which contain all of the * data required to register a custom block that overrides a group of java block @@ -38,7 +38,7 @@ import org.geysermc.geyser.api.block.custom.CustomBlockData; * @param data The custom block data * @param states The custom block state mappings * @param javaIdentifier The java identifier of the block - * @param overrideItem Whether or not the custom block should override the java item + * @param overrideItem Whether the custom block should override the java item */ public record CustomBlockMapping(@NonNull CustomBlockData data, @NonNull Map states, @NonNull String javaIdentifier, boolean overrideItem) { } diff --git a/core/src/main/java/org/geysermc/geyser/registry/mappings/versions/MappingsReader.java b/core/src/main/java/org/geysermc/geyser/registry/mappings/versions/MappingsReader.java index e76df2834..b2bdd5a01 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/mappings/versions/MappingsReader.java +++ b/core/src/main/java/org/geysermc/geyser/registry/mappings/versions/MappingsReader.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.registry.mappings.versions; import com.fasterxml.jackson.databind.JsonNode; +import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.api.item.custom.CustomItemData; import org.geysermc.geyser.api.item.custom.CustomRenderOffsets; import org.geysermc.geyser.item.exception.InvalidCustomMappingsFileException; @@ -41,7 +42,7 @@ public abstract class MappingsReader { public abstract CustomItemData readItemMappingEntry(JsonNode node) throws InvalidCustomMappingsFileException; public abstract CustomBlockMapping readBlockMappingEntry(String identifier, JsonNode node) throws InvalidCustomMappingsFileException; - protected CustomRenderOffsets fromJsonNode(JsonNode node) { + protected @Nullable CustomRenderOffsets fromJsonNode(JsonNode node) { if (node == null || !node.isObject()) { return null; } @@ -52,7 +53,7 @@ public abstract class MappingsReader { ); } - protected CustomRenderOffsets.Hand getHandOffsets(JsonNode node, String hand) { + protected CustomRenderOffsets.@Nullable Hand getHandOffsets(JsonNode node, String hand) { JsonNode tmpNode = node.get(hand); if (tmpNode == null || !tmpNode.isObject()) { return null; @@ -64,7 +65,7 @@ public abstract class MappingsReader { ); } - protected CustomRenderOffsets.Offset getPerspectiveOffsets(JsonNode node, String perspective) { + protected CustomRenderOffsets.@Nullable Offset getPerspectiveOffsets(JsonNode node, String perspective) { JsonNode tmpNode = node.get(perspective); if (tmpNode == null || !tmpNode.isObject()) { return null; @@ -77,7 +78,7 @@ public abstract class MappingsReader { ); } - protected CustomRenderOffsets.OffsetXYZ getOffsetXYZ(JsonNode node, String offsetType) { + protected CustomRenderOffsets.@Nullable OffsetXYZ getOffsetXYZ(JsonNode node, String offsetType) { JsonNode tmpNode = node.get(offsetType); if (tmpNode == null || !tmpNode.isObject()) { return null; diff --git a/core/src/main/java/org/geysermc/geyser/registry/mappings/versions/MappingsReader_v1.java b/core/src/main/java/org/geysermc/geyser/registry/mappings/versions/MappingsReader_v1.java index fb4a6acbe..1a498c3fa 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/mappings/versions/MappingsReader_v1.java +++ b/core/src/main/java/org/geysermc/geyser/registry/mappings/versions/MappingsReader_v1.java @@ -30,6 +30,7 @@ import com.fasterxml.jackson.databind.node.ArrayNode; import com.github.steveice10.mc.protocol.data.game.Identifier; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; +import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.api.block.custom.CustomBlockData; import org.geysermc.geyser.api.block.custom.CustomBlockPermutation; @@ -405,7 +406,9 @@ public class MappingsReader_v1 extends MappingsReader { if (boneVisibility.isObject()) { Map boneVisibilityMap = new Object2ObjectOpenHashMap<>(); boneVisibility.fields().forEachRemaining(entry -> { - boneVisibilityMap.put(entry.getKey(), entry.getValue().isBoolean() ? (entry.getValue().asBoolean() ? "1" : "0") : entry.getValue().asText()); + String key = entry.getKey(); + String value = entry.getValue().isBoolean() ? (entry.getValue().asBoolean() ? "1" : "0") : entry.getValue().asText(); + boneVisibilityMap.put(key, value); }); geometryBuilder.boneVisibility(boneVisibilityMap); } @@ -483,7 +486,7 @@ public class MappingsReader_v1 extends MappingsReader { String key = entry.getKey(); JsonNode value = entry.getValue(); if (value.isObject()) { - MaterialInstance materialInstance = createMaterialInstanceComponent(value, name); + MaterialInstance materialInstance = createMaterialInstanceComponent(value); builder.materialInstance(key, materialInstance); } }); @@ -583,7 +586,7 @@ public class MappingsReader_v1 extends MappingsReader { * @param javaId the block's Java ID * @return the {@link BoxComponent} or null if the block's collision box would not exceed 16 y units */ - private BoxComponent createExtendedBoxComponent(int javaId) { + private @Nullable BoxComponent createExtendedBoxComponent(int javaId) { BlockCollision blockCollision = BlockUtils.getCollision(javaId); if (blockCollision == null) { return null; @@ -603,7 +606,7 @@ public class MappingsReader_v1 extends MappingsReader { * @param node the JSON node * @return the {@link BoxComponent} */ - private BoxComponent createBoxComponent(JsonNode node) { + private @Nullable BoxComponent createBoxComponent(JsonNode node) { if (node != null && node.isObject()) { if (node.has("origin") && node.has("size")) { JsonNode origin = node.get("origin"); @@ -627,10 +630,9 @@ public class MappingsReader_v1 extends MappingsReader { * The name is used as a fallback if no texture is provided by the node * * @param node the material instance node - * @param name the custom block name * @return the {@link MaterialInstance} */ - private MaterialInstance createMaterialInstanceComponent(JsonNode node, String name) { + private MaterialInstance createMaterialInstanceComponent(JsonNode node) { // Set default values, and use what the user provides if they have provided something String texture = null; if (node.has("texture")) { diff --git a/core/src/main/java/org/geysermc/geyser/registry/populator/BlockRegistryPopulator.java b/core/src/main/java/org/geysermc/geyser/registry/populator/BlockRegistryPopulator.java index e3f4e685d..328f61500 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/populator/BlockRegistryPopulator.java +++ b/core/src/main/java/org/geysermc/geyser/registry/populator/BlockRegistryPopulator.java @@ -79,7 +79,7 @@ public final class BlockRegistryPopulator { PRE_INIT, INIT_JAVA, INIT_BEDROCK, - POST_INIT; + POST_INIT } @FunctionalInterface @@ -103,10 +103,10 @@ public final class BlockRegistryPopulator { public static void populate(Stage stage) { switch (stage) { - case PRE_INIT, POST_INIT -> { nullifyBlocksNode(); } - case INIT_JAVA -> { registerJavaBlocks(); } - case INIT_BEDROCK -> { registerBedrockBlocks(); } - default -> { throw new IllegalArgumentException("Unknown stage: " + stage); } + case PRE_INIT, POST_INIT -> nullifyBlocksNode(); + case INIT_JAVA -> registerJavaBlocks(); + case INIT_BEDROCK -> registerBedrockBlocks(); + default -> throw new IllegalArgumentException("Unknown stage: " + stage); } } @@ -137,14 +137,15 @@ public final class BlockRegistryPopulator { // We can keep this strong as nothing should be garbage collected // Safe to intern since Cloudburst NBT is immutable + //noinspection UnstableApiUsage Interner statesInterner = Interners.newStrongInterner(); for (ObjectIntPair palette : blockMappers.keySet()) { int protocolVersion = palette.valueInt(); List vanillaBlockStates; List blockStates; - try (InputStream stream = GeyserImpl.getInstance().getBootstrap().getResource(String.format("bedrock/block_palette.%s.nbt", palette.key())); - NBTInputStream nbtInputStream = new NBTInputStream(new DataInputStream(new GZIPInputStream(stream)), true, true)) { + try (InputStream stream = GeyserImpl.getInstance().getBootstrap().getResourceOrThrow(String.format("bedrock/block_palette.%s.nbt", palette.key())); + NBTInputStream nbtInputStream = new NBTInputStream(new DataInputStream(new GZIPInputStream(stream)), true, true)) { NbtMap blockPalette = (NbtMap) nbtInputStream.readTag(); vanillaBlockStates = new ArrayList<>(blockPalette.getList("blocks", NbtType.COMPOUND)); @@ -153,6 +154,7 @@ public final class BlockRegistryPopulator { builder.remove("version"); // Remove all nbt tags which are not needed for differentiating states builder.remove("name_hash"); // Quick workaround - was added in 1.19.20 builder.remove("network_id"); // Added in 1.19.80 - ???? + //noinspection UnstableApiUsage builder.putCompound("states", statesInterner.intern((NbtMap) builder.remove("states"))); vanillaBlockStates.set(i, builder.build()); } @@ -323,7 +325,7 @@ public final class BlockRegistryPopulator { builder.bedrockMovingBlock(movingBlockDefinition); Map nonVanillaStateOverrides = BlockRegistries.NON_VANILLA_BLOCK_STATE_OVERRIDES.get(); - if (nonVanillaStateOverrides.size() > 0) { + if (!nonVanillaStateOverrides.isEmpty()) { // First ensure all non vanilla runtime IDs at minimum are air in case they aren't consecutive Arrays.fill(javaToVanillaBedrockBlocks, MIN_CUSTOM_RUNTIME_ID, javaToVanillaBedrockBlocks.length, airDefinition); Arrays.fill(javaToBedrockBlocks, MIN_CUSTOM_RUNTIME_ID, javaToBedrockBlocks.length, airDefinition); @@ -374,7 +376,7 @@ public final class BlockRegistryPopulator { private static void registerJavaBlocks() { JsonNode blocksJson; - try (InputStream stream = GeyserImpl.getInstance().getBootstrap().getResource("mappings/blocks.json")) { + try (InputStream stream = GeyserImpl.getInstance().getBootstrap().getResourceOrThrow("mappings/blocks.json")) { blocksJson = GeyserImpl.JSON_MAPPER.readTree(stream); } catch (Exception e) { throw new AssertionError("Unable to load Java block mappings", e); @@ -382,9 +384,9 @@ public final class BlockRegistryPopulator { JAVA_BLOCKS_SIZE = blocksJson.size(); - if (BlockRegistries.NON_VANILLA_BLOCK_STATE_OVERRIDES.get().size() > 0) { - MIN_CUSTOM_RUNTIME_ID = BlockRegistries.NON_VANILLA_BLOCK_STATE_OVERRIDES.get().keySet().stream().min(Comparator.comparing(JavaBlockState::javaId)).get().javaId(); - int maxCustomRuntimeID = BlockRegistries.NON_VANILLA_BLOCK_STATE_OVERRIDES.get().keySet().stream().max(Comparator.comparing(JavaBlockState::javaId)).get().javaId(); + if (!BlockRegistries.NON_VANILLA_BLOCK_STATE_OVERRIDES.get().isEmpty()) { + MIN_CUSTOM_RUNTIME_ID = BlockRegistries.NON_VANILLA_BLOCK_STATE_OVERRIDES.get().keySet().stream().min(Comparator.comparing(JavaBlockState::javaId)).orElseThrow().javaId(); + int maxCustomRuntimeID = BlockRegistries.NON_VANILLA_BLOCK_STATE_OVERRIDES.get().keySet().stream().max(Comparator.comparing(JavaBlockState::javaId)).orElseThrow().javaId(); if (MIN_CUSTOM_RUNTIME_ID < blocksJson.size()) { throw new RuntimeException("Non vanilla custom block state overrides runtime ID must start after the last vanilla block state (" + JAVA_BLOCKS_SIZE + ")"); @@ -531,7 +533,7 @@ public final class BlockRegistryPopulator { } BlockStateValues.JAVA_WATER_ID = waterRuntimeId; - if (BlockRegistries.NON_VANILLA_BLOCK_STATE_OVERRIDES.get().size() > 0) { + if (!BlockRegistries.NON_VANILLA_BLOCK_STATE_OVERRIDES.get().isEmpty()) { Set usedNonVanillaRuntimeIDs = new HashSet<>(); for (JavaBlockState javaBlockState : BlockRegistries.NON_VANILLA_BLOCK_STATE_OVERRIDES.get().keySet()) { @@ -543,6 +545,7 @@ public final class BlockRegistryPopulator { String javaId = javaBlockState.identifier(); int stateRuntimeId = javaBlockState.javaId(); + String pistonBehavior = javaBlockState.pistonBehavior(); BlockMapping blockMapping = BlockMapping.builder() .canBreakWithHand(javaBlockState.canBreakWithHand()) .pickItem(javaBlockState.pickItem()) @@ -550,7 +553,7 @@ public final class BlockRegistryPopulator { .javaIdentifier(javaId) .javaBlockId(javaBlockState.stateGroupId()) .hardness(javaBlockState.blockHardness()) - .pistonBehavior(javaBlockState.pistonBehavior() == null ? PistonBehavior.NORMAL : PistonBehavior.getByName(javaBlockState.pistonBehavior())) + .pistonBehavior(pistonBehavior == null ? PistonBehavior.NORMAL : PistonBehavior.getByName(pistonBehavior)) .isBlockEntity(javaBlockState.hasBlockEntity()) .build(); @@ -576,7 +579,7 @@ public final class BlockRegistryPopulator { BLOCKS_JSON = blocksJson; JsonNode blockInteractionsJson; - try (InputStream stream = GeyserImpl.getInstance().getBootstrap().getResource("mappings/interactions.json")) { + try (InputStream stream = GeyserImpl.getInstance().getBootstrap().getResourceOrThrow("mappings/interactions.json")) { blockInteractionsJson = GeyserImpl.JSON_MAPPER.readTree(stream); } catch (Exception e) { throw new AssertionError("Unable to load Java block interaction mappings", e); diff --git a/core/src/main/java/org/geysermc/geyser/registry/populator/CreativeItemRegistryPopulator.java b/core/src/main/java/org/geysermc/geyser/registry/populator/CreativeItemRegistryPopulator.java index 6944bbcc3..d27a2ed49 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/populator/CreativeItemRegistryPopulator.java +++ b/core/src/main/java/org/geysermc/geyser/registry/populator/CreativeItemRegistryPopulator.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.registry.populator; import com.fasterxml.jackson.databind.JsonNode; +import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.nbt.NbtMap; import org.cloudburstmc.nbt.NbtMapBuilder; import org.cloudburstmc.nbt.NbtUtils; @@ -61,7 +62,7 @@ public class CreativeItemRegistryPopulator { // Load creative items JsonNode creativeItemEntries; - try (InputStream stream = bootstrap.getResource(String.format("bedrock/creative_items.%s.json", palette.version()))) { + try (InputStream stream = bootstrap.getResourceOrThrow(String.format("bedrock/creative_items.%s.json", palette.version()))) { creativeItemEntries = GeyserImpl.JSON_MAPPER.readTree(stream).get("items"); } catch (Exception e) { throw new AssertionError("Unable to load creative items", e); @@ -78,10 +79,10 @@ public class CreativeItemRegistryPopulator { } } - private static ItemData.Builder createItemData(JsonNode itemNode, BlockMappings blockMappings, Map definitions) { + private static ItemData.@Nullable Builder createItemData(JsonNode itemNode, BlockMappings blockMappings, Map definitions) { int count = 1; int damage = 0; - int bedrockBlockRuntimeId = -1; + int bedrockBlockRuntimeId; NbtMap tag = null; String identifier = itemNode.get("id").textValue(); diff --git a/core/src/main/java/org/geysermc/geyser/registry/populator/CustomBlockRegistryPopulator.java b/core/src/main/java/org/geysermc/geyser/registry/populator/CustomBlockRegistryPopulator.java index e4bf43b93..e4f45ac85 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/populator/CustomBlockRegistryPopulator.java +++ b/core/src/main/java/org/geysermc/geyser/registry/populator/CustomBlockRegistryPopulator.java @@ -48,7 +48,7 @@ public class CustomBlockRegistryPopulator { DEFINITION, VANILLA_REGISTRATION, NON_VANILLA_REGISTRATION, - CUSTOM_REGISTRATION; + CUSTOM_REGISTRATION } /** @@ -62,11 +62,11 @@ public class CustomBlockRegistryPopulator { } switch (stage) { - case DEFINITION -> { populateBedrock(); } - case VANILLA_REGISTRATION -> { populateVanilla(); } - case NON_VANILLA_REGISTRATION -> { populateNonVanilla(); } - case CUSTOM_REGISTRATION -> { registration(); } - default -> { throw new IllegalArgumentException("Unknown stage: " + stage); } + case DEFINITION -> populateBedrock(); + case VANILLA_REGISTRATION -> populateVanilla(); + case NON_VANILLA_REGISTRATION -> populateNonVanilla(); + case CUSTOM_REGISTRATION -> registration(); + default -> throw new IllegalArgumentException("Unknown stage: " + stage); } } @@ -479,7 +479,7 @@ public class CustomBlockRegistryPopulator { } private static CustomBlockData createExtendedCollisionBlock(BoxComponent boxComponent, int extendedCollisionBlock) { - CustomBlockData customBlockData = new CustomBlockDataBuilder() + return new CustomBlockDataBuilder() .name("extended_collision_" + extendedCollisionBlock) .components( new CustomBlockComponentsBuilder() @@ -497,6 +497,5 @@ public class CustomBlockRegistryPopulator { .build()) .build()) .build(); - return customBlockData; } } diff --git a/core/src/main/java/org/geysermc/geyser/registry/populator/CustomItemRegistryPopulator.java b/core/src/main/java/org/geysermc/geyser/registry/populator/CustomItemRegistryPopulator.java index 638e41a5e..6be1aac4c 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/populator/CustomItemRegistryPopulator.java +++ b/core/src/main/java/org/geysermc/geyser/registry/populator/CustomItemRegistryPopulator.java @@ -27,6 +27,7 @@ package org.geysermc.geyser.registry.populator; import com.google.common.collect.Multimap; import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.nbt.NbtMap; import org.cloudburstmc.nbt.NbtMapBuilder; import org.cloudburstmc.nbt.NbtType; @@ -48,7 +49,6 @@ import org.geysermc.geyser.registry.type.GeyserMappingItem; import org.geysermc.geyser.registry.type.ItemMapping; import org.geysermc.geyser.registry.type.NonVanillaItemRegistration; -import javax.annotation.Nullable; import java.util.*; public class CustomItemRegistryPopulator { @@ -171,7 +171,7 @@ public class CustomItemRegistryPopulator { boolean canDestroyInCreative = true; if (mapping.getToolType() != null) { // This is not using the isTool boolean because it is not just a render type here. - canDestroyInCreative = computeToolProperties(mapping.getToolTier(), mapping.getToolType(), itemProperties, componentBuilder); + canDestroyInCreative = computeToolProperties(mapping.getToolType(), itemProperties, componentBuilder); } itemProperties.putBoolean("can_destroy_in_creative", canDestroyInCreative); @@ -192,18 +192,11 @@ public class CustomItemRegistryPopulator { } switch (mapping.getBedrockIdentifier()) { - case "minecraft:fire_charge", "minecraft:flint_and_steel" -> { - computeBlockItemProperties("minecraft:fire", componentBuilder); - } - case "minecraft:bow", "minecraft:crossbow", "minecraft:trident" -> { - computeChargeableProperties(itemProperties, componentBuilder); - } - case "minecraft:honey_bottle", "minecraft:milk_bucket", "minecraft:potion" -> { - computeConsumableProperties(itemProperties, componentBuilder, 2, true); - } - case "minecraft:experience_bottle", "minecraft:egg", "minecraft:ender_pearl", "minecraft:ender_eye", "minecraft:lingering_potion", "minecraft:snowball", "minecraft:splash_potion" -> { - computeThrowableProperties(componentBuilder); - } + case "minecraft:fire_charge", "minecraft:flint_and_steel" -> computeBlockItemProperties("minecraft:fire", componentBuilder); + case "minecraft:bow", "minecraft:crossbow", "minecraft:trident" -> computeChargeableProperties(itemProperties, componentBuilder); + case "minecraft:honey_bottle", "minecraft:milk_bucket", "minecraft:potion" -> computeConsumableProperties(itemProperties, componentBuilder, 2, true); + case "minecraft:experience_bottle", "minecraft:egg", "minecraft:ender_pearl", "minecraft:ender_eye", "minecraft:lingering_potion", "minecraft:snowball", "minecraft:splash_potion" -> + computeThrowableProperties(componentBuilder); } computeRenderOffsets(false, customItemData, componentBuilder); @@ -214,6 +207,7 @@ public class CustomItemRegistryPopulator { return builder; } + @SuppressWarnings("OptionalUsedAsFieldOrParameterType") private static NbtMapBuilder createComponentNbt(NonVanillaCustomItemData customItemData, String customItemName, int customItemId, OptionalInt creativeCategory, String creativeGroup, boolean isHat, boolean displayHandheld) { @@ -228,7 +222,7 @@ public class CustomItemRegistryPopulator { boolean canDestroyInCreative = true; if (customItemData.toolType() != null) { // This is not using the isTool boolean because it is not just a render type here. - canDestroyInCreative = computeToolProperties(customItemData.toolTier(), customItemData.toolType(), itemProperties, componentBuilder); + canDestroyInCreative = computeToolProperties(customItemData.toolType(), itemProperties, componentBuilder); } itemProperties.putBoolean("can_destroy_in_creative", canDestroyInCreative); @@ -300,7 +294,7 @@ public class CustomItemRegistryPopulator { /** * @return can destroy in creative */ - private static boolean computeToolProperties(String toolTier, String toolType, NbtMapBuilder itemProperties, NbtMapBuilder componentBuilder) { + private static boolean computeToolProperties(String toolType, NbtMapBuilder itemProperties, NbtMapBuilder componentBuilder) { boolean canDestroyInCreative = true; float miningSpeed = 1.0f; @@ -467,7 +461,7 @@ public class CustomItemRegistryPopulator { return builder.build(); } - private static NbtMap toNbtMap(CustomRenderOffsets.Hand hand) { + private static @Nullable NbtMap toNbtMap(CustomRenderOffsets.Hand hand) { NbtMap firstPerson = toNbtMap(hand.firstPerson()); NbtMap thirdPerson = toNbtMap(hand.thirdPerson()); @@ -486,7 +480,7 @@ public class CustomItemRegistryPopulator { return builder.build(); } - private static NbtMap toNbtMap(@Nullable CustomRenderOffsets.Offset offset) { + private static @Nullable NbtMap toNbtMap(CustomRenderOffsets.@Nullable Offset offset) { if (offset == null) { return null; } diff --git a/core/src/main/java/org/geysermc/geyser/registry/populator/CustomSkullRegistryPopulator.java b/core/src/main/java/org/geysermc/geyser/registry/populator/CustomSkullRegistryPopulator.java index f66d21572..02d9a75ec 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/populator/CustomSkullRegistryPopulator.java +++ b/core/src/main/java/org/geysermc/geyser/registry/populator/CustomSkullRegistryPopulator.java @@ -27,7 +27,8 @@ package org.geysermc.geyser.registry.populator; import it.unimi.dsi.fastutil.objects.Object2ObjectMaps; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; -import lombok.NonNull; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.GeyserBootstrap; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.api.event.lifecycle.GeyserDefineCustomSkullsEvent; @@ -139,7 +140,7 @@ public class CustomSkullRegistryPopulator { * @param profile the base64 encoded profile * @return the skin hash or null if the profile is invalid */ - private static String getSkinHash(String profile) { + private static @Nullable String getSkinHash(String profile) { try { SkinManager.GameProfileData profileData = SkinManager.GameProfileData.loadFromJson(profile); if (profileData == null) { @@ -159,7 +160,7 @@ public class CustomSkullRegistryPopulator { * @param username the player username * @return the base64 encoded profile or null if the request failed */ - private static String getProfileFromUsername(String username) { + private static @Nullable String getProfileFromUsername(String username) { try { return SkinProvider.requestTexturesFromUsername(username).get(); } catch (InterruptedException | ExecutionException e) { @@ -173,7 +174,7 @@ public class CustomSkullRegistryPopulator { * @param uuid the player UUID * @return the base64 encoded profile or null if the request failed */ - private static String getProfileFromUuid(String uuid) { + private static @Nullable String getProfileFromUuid(String uuid) { try { String uuidDigits = uuid.replace("-", ""); if (uuidDigits.length() != 32) { diff --git a/core/src/main/java/org/geysermc/geyser/registry/populator/ItemRegistryPopulator.java b/core/src/main/java/org/geysermc/geyser/registry/populator/ItemRegistryPopulator.java index fe6e21e6f..f46a49c3a 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/populator/ItemRegistryPopulator.java +++ b/core/src/main/java/org/geysermc/geyser/registry/populator/ItemRegistryPopulator.java @@ -139,7 +139,7 @@ public class ItemRegistryPopulator { TypeReference> mappingItemsType = new TypeReference<>() { }; Map items; - try (InputStream stream = bootstrap.getResource("mappings/items.json")) { + try (InputStream stream = bootstrap.getResourceOrThrow("mappings/items.json")) { // Load item mappings from Java Edition to Bedrock Edition items = GeyserImpl.JSON_MAPPER.readValue(stream, mappingItemsType); } catch (Exception e) { @@ -166,7 +166,7 @@ public class ItemRegistryPopulator { TypeReference> paletteEntriesType = new TypeReference<>() {}; List itemEntries; - try (InputStream stream = bootstrap.getResource(String.format("bedrock/runtime_item_states.%s.json", palette.version()))) { + try (InputStream stream = bootstrap.getResourceOrThrow(String.format("bedrock/runtime_item_states.%s.json", palette.version()))) { itemEntries = GeyserImpl.JSON_MAPPER.readValue(stream, paletteEntriesType); } catch (Exception e) { throw new AssertionError("Unable to load Bedrock runtime item IDs", e); diff --git a/core/src/main/java/org/geysermc/geyser/registry/populator/RecipeRegistryPopulator.java b/core/src/main/java/org/geysermc/geyser/registry/populator/RecipeRegistryPopulator.java index 3e9e2c257..f8929c900 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/populator/RecipeRegistryPopulator.java +++ b/core/src/main/java/org/geysermc/geyser/registry/populator/RecipeRegistryPopulator.java @@ -64,7 +64,7 @@ public class RecipeRegistryPopulator { public static void populate() { JsonNode items; - try (InputStream stream = GeyserImpl.getInstance().getBootstrap().getResource("mappings/recipes.json")) { + try (InputStream stream = GeyserImpl.getInstance().getBootstrap().getResourceOrThrow("mappings/recipes.json")) { items = GeyserImpl.JSON_MAPPER.readTree(stream); } catch (Exception e) { throw new AssertionError(GeyserLocale.getLocaleStringLog("geyser.toolbox.fail.runtime_java"), e); diff --git a/core/src/main/java/org/geysermc/geyser/registry/type/BlockMapping.java b/core/src/main/java/org/geysermc/geyser/registry/type/BlockMapping.java index 9745a8859..0196ac22f 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/type/BlockMapping.java +++ b/core/src/main/java/org/geysermc/geyser/registry/type/BlockMapping.java @@ -27,16 +27,15 @@ package org.geysermc.geyser.registry.type; import lombok.Builder; import lombok.Value; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.level.physics.PistonBehavior; import org.geysermc.geyser.util.BlockUtils; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - @Builder @Value public class BlockMapping { - public static BlockMapping DEFAULT = BlockMapping.builder().javaIdentifier("minecraft:air").pistonBehavior(PistonBehavior.NORMAL).build();; + public static BlockMapping DEFAULT = BlockMapping.builder().javaIdentifier("minecraft:air").pistonBehavior(PistonBehavior.NORMAL).build(); String javaIdentifier; /** @@ -53,8 +52,7 @@ public class BlockMapping { int collisionIndex; @Nullable String pickItem; - @Nonnull - PistonBehavior pistonBehavior; + @NonNull PistonBehavior pistonBehavior; boolean isBlockEntity; boolean isNonVanilla; diff --git a/core/src/main/java/org/geysermc/geyser/registry/type/BlockMappings.java b/core/src/main/java/org/geysermc/geyser/registry/type/BlockMappings.java index 3d06cecac..8c0414a6d 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/type/BlockMappings.java +++ b/core/src/main/java/org/geysermc/geyser/registry/type/BlockMappings.java @@ -29,6 +29,7 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.objects.Object2ObjectMap; import lombok.Builder; import lombok.Value; +import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.nbt.NbtMap; import org.cloudburstmc.protocol.bedrock.data.BlockPropertyData; import org.cloudburstmc.protocol.bedrock.data.definitions.BlockDefinition; @@ -96,14 +97,14 @@ public class BlockMappings implements DefinitionRegistry { } @Override - public GeyserBedrockBlock getDefinition(int bedrockId) { + public @Nullable GeyserBedrockBlock getDefinition(int bedrockId) { if (bedrockId < 0 || bedrockId >= this.bedrockRuntimeMap.length) { return null; } return bedrockRuntimeMap[bedrockId]; } - public GeyserBedrockBlock getDefinition(NbtMap tag) { + public @Nullable GeyserBedrockBlock getDefinition(NbtMap tag) { if (tag == null) { return null; } diff --git a/core/src/main/java/org/geysermc/geyser/registry/type/ParticleMapping.java b/core/src/main/java/org/geysermc/geyser/registry/type/ParticleMapping.java index f8aeb78ee..4108fba1f 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/type/ParticleMapping.java +++ b/core/src/main/java/org/geysermc/geyser/registry/type/ParticleMapping.java @@ -25,10 +25,8 @@ package org.geysermc.geyser.registry.type; +import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.protocol.bedrock.data.LevelEventType; -import javax.annotation.ParametersAreNullableByDefault; - -@ParametersAreNullableByDefault -public record ParticleMapping(LevelEventType levelEventType, String identifier) { +public record ParticleMapping(@Nullable LevelEventType levelEventType, @Nullable String identifier) { } \ No newline at end of file diff --git a/core/src/main/java/org/geysermc/geyser/scoreboard/Objective.java b/core/src/main/java/org/geysermc/geyser/scoreboard/Objective.java index 688666c73..fd9e0fbf3 100644 --- a/core/src/main/java/org/geysermc/geyser/scoreboard/Objective.java +++ b/core/src/main/java/org/geysermc/geyser/scoreboard/Objective.java @@ -29,6 +29,7 @@ import com.github.steveice10.mc.protocol.data.game.scoreboard.ScoreboardPosition import com.github.steveice10.mc.protocol.data.game.scoreboard.TeamColor; import lombok.Getter; import lombok.Setter; +import org.checkerframework.checker.nullness.qual.Nullable; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -150,7 +151,7 @@ public final class Objective { updateType = UpdateType.REMOVE; } - public TeamColor getTeamColor() { + public @Nullable TeamColor getTeamColor() { return switch (displaySlot) { case SIDEBAR_TEAM_RED -> TeamColor.RED; case SIDEBAR_TEAM_AQUA -> TeamColor.AQUA; diff --git a/core/src/main/java/org/geysermc/geyser/scoreboard/Scoreboard.java b/core/src/main/java/org/geysermc/geyser/scoreboard/Scoreboard.java index c49e8afc4..1e0ea5eb1 100644 --- a/core/src/main/java/org/geysermc/geyser/scoreboard/Scoreboard.java +++ b/core/src/main/java/org/geysermc/geyser/scoreboard/Scoreboard.java @@ -26,13 +26,14 @@ package org.geysermc.geyser.scoreboard; import com.github.steveice10.mc.protocol.data.game.scoreboard.ScoreboardPosition; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; +import lombok.Getter; +import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.protocol.bedrock.data.ScoreInfo; import org.cloudburstmc.protocol.bedrock.data.command.CommandEnumConstraint; import org.cloudburstmc.protocol.bedrock.packet.RemoveObjectivePacket; import org.cloudburstmc.protocol.bedrock.packet.SetDisplayObjectivePacket; import org.cloudburstmc.protocol.bedrock.packet.SetScorePacket; -import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; -import lombok.Getter; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserLogger; import org.geysermc.geyser.entity.type.Entity; @@ -41,14 +42,16 @@ import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.text.GeyserLocale; import org.jetbrains.annotations.Contract; -import javax.annotation.Nullable; import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicLong; import java.util.function.Function; import java.util.stream.Collectors; -import static org.geysermc.geyser.scoreboard.UpdateType.*; +import static org.geysermc.geyser.scoreboard.UpdateType.ADD; +import static org.geysermc.geyser.scoreboard.UpdateType.NOTHING; +import static org.geysermc.geyser.scoreboard.UpdateType.REMOVE; +import static org.geysermc.geyser.scoreboard.UpdateType.UPDATE; public final class Scoreboard { private static final boolean SHOW_SCOREBOARD_LOGS = Boolean.parseBoolean(System.getProperty("Geyser.ShowScoreboardLogs", "true")); @@ -89,7 +92,7 @@ public final class Scoreboard { } } - public Objective registerNewObjective(String objectiveId) { + public @Nullable Objective registerNewObjective(String objectiveId) { Objective objective = objectives.get(objectiveId); if (objective != null) { // we have no other choice, or we have to make a new map? diff --git a/core/src/main/java/org/geysermc/geyser/scoreboard/ScoreboardUpdater.java b/core/src/main/java/org/geysermc/geyser/scoreboard/ScoreboardUpdater.java index fed3054b4..8c1ef5296 100644 --- a/core/src/main/java/org/geysermc/geyser/scoreboard/ScoreboardUpdater.java +++ b/core/src/main/java/org/geysermc/geyser/scoreboard/ScoreboardUpdater.java @@ -173,6 +173,7 @@ public final class ScoreboardUpdater extends Thread { @Getter public static final class ScoreboardSession { private final GeyserSession session; + @SuppressWarnings("WriteOnlyObject") private final AtomicInteger pendingPacketsPerSecond = new AtomicInteger(0); private int packetsPerSecond; private long lastUpdate; diff --git a/core/src/main/java/org/geysermc/geyser/scoreboard/Team.java b/core/src/main/java/org/geysermc/geyser/scoreboard/Team.java index e985ca803..9164fec1d 100644 --- a/core/src/main/java/org/geysermc/geyser/scoreboard/Team.java +++ b/core/src/main/java/org/geysermc/geyser/scoreboard/Team.java @@ -32,9 +32,9 @@ import lombok.AccessLevel; import lombok.Getter; import lombok.Setter; import lombok.experimental.Accessors; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; import java.util.HashSet; import java.util.Set; @@ -46,7 +46,7 @@ public final class Team { @Getter(AccessLevel.PACKAGE) private final Set entities; - @Nonnull private NameTagVisibility nameTagVisibility = NameTagVisibility.ALWAYS; + @NonNull private NameTagVisibility nameTagVisibility = NameTagVisibility.ALWAYS; @Setter private TeamColor color; private final TeamData currentData; diff --git a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java index 9bfb4e01c..2f0d47b38 100644 --- a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java +++ b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java @@ -147,7 +147,6 @@ import org.geysermc.geyser.util.ChunkUtils; import org.geysermc.geyser.util.DimensionUtils; import org.geysermc.geyser.util.EntityUtils; import org.geysermc.geyser.util.LoginEncryptionUtils; -import org.jetbrains.annotations.NotNull; import java.net.ConnectException; import java.net.InetSocketAddress; @@ -181,7 +180,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource { @Setter private List certChainData; - @NotNull + @NonNull @Setter private AbstractGeyserboundPacketHandler erosionHandler; @@ -336,7 +335,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource { /** * Tracks the original speed attribute. - * + *

* We need to do this in order to emulate speeds when sneaking under 1.5-blocks-tall areas if the player isn't sneaking, * and when crawling. */ @@ -461,7 +460,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource { /** * Store the last time the player interacted. Used to fix a right-click spam bug. - * See https://github.com/GeyserMC/Geyser/issues/503 for context. + * See this for context. */ @Setter private long lastInteractionTime; @@ -1318,7 +1317,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource { * * @return not null if attributes should be updated. */ - public AttributeData adjustSpeed() { + public @Nullable AttributeData adjustSpeed() { AttributeData currentPlayerSpeed = playerEntity.getAttributes().get(GeyserAttributeType.MOVEMENT_SPEED); if (currentPlayerSpeed != null) { if ((pose.equals(Pose.SNEAKING) && !sneaking && collisionManager.mustPlayerSneakHere()) || @@ -1370,7 +1369,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource { } /** - * For https://github.com/GeyserMC/Geyser/issues/2113 and combating arm ticking activating being delayed in + * For issue 2113 and combating arm ticking activating being delayed in * BedrockAnimateTranslator. */ public void armSwingPending() { @@ -1405,7 +1404,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource { } @Override - public void sendMessage(String message) { + public void sendMessage(@NonNull String message) { TextPacket textPacket = new TextPacket(); textPacket.setPlatformChatId(""); textPacket.setSourceName(""); @@ -1911,7 +1910,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource { } @Override - public String bedrockUsername() { + public @NonNull String bedrockUsername() { return authData.name(); } @@ -1926,7 +1925,7 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource { } @Override - public String xuid() { + public @NonNull String xuid() { return authData.xuid(); } diff --git a/core/src/main/java/org/geysermc/geyser/session/PendingMicrosoftAuthentication.java b/core/src/main/java/org/geysermc/geyser/session/PendingMicrosoftAuthentication.java index 93200dcb6..132de67cb 100644 --- a/core/src/main/java/org/geysermc/geyser/session/PendingMicrosoftAuthentication.java +++ b/core/src/main/java/org/geysermc/geyser/session/PendingMicrosoftAuthentication.java @@ -32,13 +32,13 @@ import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import lombok.Getter; -import lombok.NonNull; import lombok.Setter; import lombok.SneakyThrows; +import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserLogger; -import javax.annotation.Nonnull; +import java.io.Serial; import java.util.concurrent.*; /** @@ -63,12 +63,12 @@ public class PendingMicrosoftAuthentication { }); } - public AuthenticationTask getTask(@Nonnull String userKey) { + public AuthenticationTask getTask(@NonNull String userKey) { return authentications.getIfPresent(userKey); } @SneakyThrows(ExecutionException.class) - public AuthenticationTask getOrCreateTask(@Nonnull String userKey) { + public AuthenticationTask getOrCreateTask(@NonNull String userKey) { return authentications.get(userKey); } @@ -189,6 +189,10 @@ public class PendingMicrosoftAuthentication { * @see PendingMicrosoftAuthentication */ public static class TaskTimeoutException extends Exception { + + @Serial + private static final long serialVersionUID = 1L; + TaskTimeoutException() { super("It took too long to authorize Geyser to access your Microsoft account. " + "Please request new code and try again."); diff --git a/core/src/main/java/org/geysermc/geyser/session/SessionManager.java b/core/src/main/java/org/geysermc/geyser/session/SessionManager.java index 7e5982ab5..14881d059 100644 --- a/core/src/main/java/org/geysermc/geyser/session/SessionManager.java +++ b/core/src/main/java/org/geysermc/geyser/session/SessionManager.java @@ -28,9 +28,10 @@ package org.geysermc.geyser.session; import com.google.common.collect.ImmutableList; import lombok.AccessLevel; import lombok.Getter; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.text.GeyserLocale; -import javax.annotation.Nonnull; import java.util.*; import java.util.concurrent.ConcurrentHashMap; @@ -69,7 +70,7 @@ public final class SessionManager { } } - public GeyserSession sessionByXuid(@Nonnull String xuid) { + public @Nullable GeyserSession sessionByXuid(@NonNull String xuid) { Objects.requireNonNull(xuid); for (GeyserSession session : sessions.values()) { if (session.xuid().equals(xuid)) { diff --git a/core/src/main/java/org/geysermc/geyser/session/cache/AdvancementsCache.java b/core/src/main/java/org/geysermc/geyser/session/cache/AdvancementsCache.java index db0321147..3562f0d4d 100644 --- a/core/src/main/java/org/geysermc/geyser/session/cache/AdvancementsCache.java +++ b/core/src/main/java/org/geysermc/geyser/session/cache/AdvancementsCache.java @@ -140,7 +140,7 @@ public class AdvancementsCache { session.sendDownstreamGamePacket(new ServerboundSeenAdvancementsPacket()); }).validResultHandler((response) -> { - if (response.getClickedButtonId() < visibleAdvancements.size()) { + if (response.clickedButtonId() < visibleAdvancements.size()) { GeyserAdvancement advancement = visibleAdvancements.get(response.clickedButtonId()); buildAndShowInfoForm(advancement); } else { diff --git a/core/src/main/java/org/geysermc/geyser/session/cache/BookEditCache.java b/core/src/main/java/org/geysermc/geyser/session/cache/BookEditCache.java index d1ebd0c78..6a9025bc0 100644 --- a/core/src/main/java/org/geysermc/geyser/session/cache/BookEditCache.java +++ b/core/src/main/java/org/geysermc/geyser/session/cache/BookEditCache.java @@ -33,7 +33,7 @@ import org.geysermc.geyser.session.GeyserSession; /** * Manages updating the current writable book. - * + *

* Java sends book updates less frequently than Bedrock, and this can cause issues with servers that rate limit * book packets. Because of this, we need to ensure packets are only send every second or so at maximum. */ diff --git a/core/src/main/java/org/geysermc/geyser/session/cache/LodestoneCache.java b/core/src/main/java/org/geysermc/geyser/session/cache/LodestoneCache.java index 41f73863e..f118195b9 100644 --- a/core/src/main/java/org/geysermc/geyser/session/cache/LodestoneCache.java +++ b/core/src/main/java/org/geysermc/geyser/session/cache/LodestoneCache.java @@ -30,9 +30,9 @@ import com.github.steveice10.opennbt.tag.builtin.IntTag; import com.github.steveice10.opennbt.tag.builtin.StringTag; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; +import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.inventory.GeyserItemStack; -import javax.annotation.Nullable; import java.util.Map; import java.util.WeakHashMap; @@ -54,6 +54,10 @@ public final class LodestoneCache { public void cacheInventoryItem(GeyserItemStack itemStack) { CompoundTag tag = itemStack.getNbt(); + if (tag == null) { + // invalid + return; + } CompoundTag lodestonePos = tag.get("LodestonePos"); if (lodestonePos == null) { // invalid diff --git a/core/src/main/java/org/geysermc/geyser/session/cache/PreferencesCache.java b/core/src/main/java/org/geysermc/geyser/session/cache/PreferencesCache.java index 9e8597b0f..2aeb83fa8 100644 --- a/core/src/main/java/org/geysermc/geyser/session/cache/PreferencesCache.java +++ b/core/src/main/java/org/geysermc/geyser/session/cache/PreferencesCache.java @@ -67,10 +67,10 @@ public class PreferencesCache { /** * Tell the client to hide or show the coordinates. - * + *

* If {@link #prefersShowCoordinates} is true, coordinates will be shown, unless either of the following conditions apply:
*
- * {@link GeyserSession#reducedDebugInfo} is enabled + * {@link GeyserSession#isReducedDebugInfo()} is enabled * {@link GeyserConfiguration#isShowCoordinates()} is disabled */ public void updateShowCoordinates() { diff --git a/core/src/main/java/org/geysermc/geyser/session/cache/SkullCache.java b/core/src/main/java/org/geysermc/geyser/session/cache/SkullCache.java index d6e376d8f..5b208a41f 100644 --- a/core/src/main/java/org/geysermc/geyser/session/cache/SkullCache.java +++ b/core/src/main/java/org/geysermc/geyser/session/cache/SkullCache.java @@ -25,6 +25,7 @@ package org.geysermc.geyser.session.cache; +import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.math.vector.Vector3i; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; @@ -247,7 +248,7 @@ public class SkullCache { lastPlayerPosition = null; } - private BlockDefinition translateCustomSkull(String skinHash, int blockState) { + private @Nullable BlockDefinition translateCustomSkull(String skinHash, int blockState) { CustomSkull customSkull = BlockRegistries.CUSTOM_SKULLS.get(skinHash); if (customSkull != null) { byte floorRotation = BlockStateValues.getSkullRotation(blockState); diff --git a/core/src/main/java/org/geysermc/geyser/session/cache/WorldBorder.java b/core/src/main/java/org/geysermc/geyser/session/cache/WorldBorder.java index d9b9d8a54..8cb590f57 100644 --- a/core/src/main/java/org/geysermc/geyser/session/cache/WorldBorder.java +++ b/core/src/main/java/org/geysermc/geyser/session/cache/WorldBorder.java @@ -25,6 +25,7 @@ package org.geysermc.geyser.session.cache; +import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.GenericMath; import org.cloudburstmc.math.vector.Vector2d; import org.cloudburstmc.math.vector.Vector3f; @@ -37,13 +38,11 @@ import org.geysermc.geyser.entity.EntityDefinitions; import org.geysermc.geyser.entity.type.player.PlayerEntity; import org.geysermc.geyser.session.GeyserSession; -import javax.annotation.Nonnull; - public class WorldBorder { private static final double DEFAULT_WORLD_BORDER_SIZE = 5.9999968E7D; @Setter - private @Nonnull Vector2d center = Vector2d.ZERO; + private @NonNull Vector2d center = Vector2d.ZERO; /** * The diameter in blocks of the world border before it got changed or similar to newDiameter if not changed. */ diff --git a/core/src/main/java/org/geysermc/geyser/skin/FakeHeadProvider.java b/core/src/main/java/org/geysermc/geyser/skin/FakeHeadProvider.java index 95a2dcb1a..4ae30be19 100644 --- a/core/src/main/java/org/geysermc/geyser/skin/FakeHeadProvider.java +++ b/core/src/main/java/org/geysermc/geyser/skin/FakeHeadProvider.java @@ -34,13 +34,13 @@ import com.google.common.cache.LoadingCache; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.Setter; +import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.entity.type.LivingEntity; import org.geysermc.geyser.entity.type.player.PlayerEntity; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.text.GeyserLocale; -import javax.annotation.Nonnull; import java.awt.*; import java.awt.image.BufferedImage; import java.io.IOException; @@ -58,7 +58,7 @@ public class FakeHeadProvider { .maximumSize(10000) .build(new CacheLoader<>() { @Override - public SkinProvider.SkinData load(@Nonnull FakeHeadEntry fakeHeadEntry) throws Exception { + public SkinProvider.SkinData load(@NonNull FakeHeadEntry fakeHeadEntry) throws Exception { SkinProvider.SkinData skinData = SkinProvider.getOrDefault(SkinProvider.requestSkinData(fakeHeadEntry.getEntity()), null, 5); if (skinData == null) { diff --git a/core/src/main/java/org/geysermc/geyser/skin/SkinManager.java b/core/src/main/java/org/geysermc/geyser/skin/SkinManager.java index f7d6d7510..33a51fe8f 100644 --- a/core/src/main/java/org/geysermc/geyser/skin/SkinManager.java +++ b/core/src/main/java/org/geysermc/geyser/skin/SkinManager.java @@ -29,6 +29,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.ListTag; import com.github.steveice10.opennbt.tag.builtin.StringTag; +import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.protocol.bedrock.data.skin.ImageData; import org.cloudburstmc.protocol.bedrock.data.skin.SerializedSkin; import org.cloudburstmc.protocol.bedrock.packet.PlayerListPacket; @@ -40,7 +41,6 @@ import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.session.auth.BedrockClientData; import org.geysermc.geyser.text.GeyserLocale; -import javax.annotation.Nullable; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.Base64; @@ -277,7 +277,7 @@ public class SkinManager { return null; } - public static GameProfileData loadFromJson(String encodedJson) throws IOException, IllegalArgumentException { + public static @Nullable GameProfileData loadFromJson(String encodedJson) throws IOException, IllegalArgumentException { JsonNode skinObject; try { skinObject = GeyserImpl.JSON_MAPPER.readTree(new String(Base64.getDecoder().decode(encodedJson), StandardCharsets.UTF_8)); diff --git a/core/src/main/java/org/geysermc/geyser/skin/SkinProvider.java b/core/src/main/java/org/geysermc/geyser/skin/SkinProvider.java index f491473be..23985c33f 100644 --- a/core/src/main/java/org/geysermc/geyser/skin/SkinProvider.java +++ b/core/src/main/java/org/geysermc/geyser/skin/SkinProvider.java @@ -32,6 +32,8 @@ import it.unimi.dsi.fastutil.bytes.ByteArrays; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.api.network.AuthType; import org.geysermc.geyser.entity.type.player.PlayerEntity; @@ -40,8 +42,6 @@ import org.geysermc.geyser.text.GeyserLocale; import org.geysermc.geyser.util.FileUtils; import org.geysermc.geyser.util.WebUtils; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; import javax.imageio.ImageIO; import java.awt.*; import java.awt.image.BufferedImage; @@ -217,7 +217,7 @@ public class SkinProvider { /** * Used as a fallback if an official Java cape doesn't exist for this user. */ - @Nonnull + @NonNull private static Cape getCachedBedrockCape(UUID uuid) { GeyserSession session = GeyserImpl.getInstance().connectionByUuid(uuid); if (session != null) { @@ -545,7 +545,7 @@ public class SkinProvider { BufferedImage image = null; // First see if we have a cached file. We also update the modification stamp so we know when the file was last used - File imageFile = GeyserImpl.getInstance().getBootstrap().getConfigFolder().resolve("cache").resolve("images").resolve(UUID.nameUUIDFromBytes(imageUrl.getBytes()).toString() + ".png").toFile(); + File imageFile = GeyserImpl.getInstance().getBootstrap().getConfigFolder().resolve("cache").resolve("images").resolve(UUID.nameUUIDFromBytes(imageUrl.getBytes()) + ".png").toFile(); if (imageFile.exists()) { try { GeyserImpl.getInstance().getLogger().debug("Reading cached image from file " + imageFile.getPath() + " for " + imageUrl); @@ -617,7 +617,7 @@ public class SkinProvider { * @param uuid the player's UUID without any hyphens * @return a completable GameProfile with textures included */ - public static CompletableFuture requestTexturesFromUUID(String uuid) { + public static CompletableFuture<@Nullable String> requestTexturesFromUUID(String uuid) { return CompletableFuture.supplyAsync(() -> { try { JsonNode node = WebUtils.getJson("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid); @@ -643,7 +643,7 @@ public class SkinProvider { * @param username the player's username * @return a completable GameProfile with textures included */ - public static CompletableFuture requestTexturesFromUsername(String username) { + public static CompletableFuture<@Nullable String> requestTexturesFromUsername(String username) { return CompletableFuture.supplyAsync(() -> { try { // Offline skin, or no present UUID @@ -669,20 +669,25 @@ public class SkinProvider { } private static BufferedImage downloadImage(String imageUrl, CapeProvider provider) throws IOException { - if (provider == CapeProvider.FIVEZIG) - return readFiveZigCape(imageUrl); + BufferedImage image; + if (provider == CapeProvider.FIVEZIG) { + image = readFiveZigCape(imageUrl); + } else { + HttpURLConnection con = (HttpURLConnection) new URL(imageUrl).openConnection(); + con.setRequestProperty("User-Agent", "Geyser-" + GeyserImpl.getInstance().getPlatformType().toString() + "/" + GeyserImpl.VERSION); + con.setConnectTimeout(10000); + con.setReadTimeout(10000); - HttpURLConnection con = (HttpURLConnection) new URL(imageUrl).openConnection(); - con.setRequestProperty("User-Agent", "Geyser-" + GeyserImpl.getInstance().getPlatformType().toString() + "/" + GeyserImpl.VERSION); - con.setConnectTimeout(10000); - con.setReadTimeout(10000); + image = ImageIO.read(con.getInputStream()); + } - BufferedImage image = ImageIO.read(con.getInputStream()); - if (image == null) throw new NullPointerException(); + if (image == null) { + throw new IllegalArgumentException("Failed to read image from: %s (cape provider=%s)".formatted(imageUrl, provider)); + } return image; } - private static BufferedImage readFiveZigCape(String url) throws IOException { + private static @Nullable BufferedImage readFiveZigCape(String url) throws IOException { JsonNode element = GeyserImpl.JSON_MAPPER.readTree(WebUtils.getBody(url)); if (element != null && element.isObject()) { JsonNode capeElement = element.get("d"); diff --git a/core/src/main/java/org/geysermc/geyser/text/AsteriskSerializer.java b/core/src/main/java/org/geysermc/geyser/text/AsteriskSerializer.java index 69dbb558e..702fded92 100644 --- a/core/src/main/java/org/geysermc/geyser/text/AsteriskSerializer.java +++ b/core/src/main/java/org/geysermc/geyser/text/AsteriskSerializer.java @@ -35,6 +35,7 @@ import com.fasterxml.jackson.databind.ser.ContextualSerializer; import com.fasterxml.jackson.databind.ser.std.StdSerializer; import java.io.IOException; +import java.io.Serial; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -43,6 +44,9 @@ import java.util.Optional; public class AsteriskSerializer extends StdSerializer implements ContextualSerializer { + @Serial + private static final long serialVersionUID = 1L; + public static final String[] NON_SENSITIVE_ADDRESSES = {"", "0.0.0.0", "localhost", "127.0.0.1", "auto", "unknown"}; public static boolean showSensitive = false; @@ -64,10 +68,6 @@ public class AsteriskSerializer extends StdSerializer implements Context String asterisk; boolean isIp; - public AsteriskSerializer() { - super(Object.class); - } - public AsteriskSerializer(String asterisk, boolean isIp) { super(Object.class); this.asterisk = asterisk; @@ -79,7 +79,7 @@ public class AsteriskSerializer extends StdSerializer implements Context Optional anno = Optional.ofNullable(property) .map(prop -> prop.getAnnotation(Asterisk.class)); - return new AsteriskSerializer(anno.map(Asterisk::value).orElse(null), anno.map(Asterisk::isIp).orElse(null)); + return new AsteriskSerializer(anno.map(Asterisk::value).orElse(null), anno.map(Asterisk::isIp).orElse(false)); } @Override diff --git a/core/src/main/java/org/geysermc/geyser/text/ChatTypeEntry.java b/core/src/main/java/org/geysermc/geyser/text/ChatTypeEntry.java index 41528c1e4..500f44d0b 100644 --- a/core/src/main/java/org/geysermc/geyser/text/ChatTypeEntry.java +++ b/core/src/main/java/org/geysermc/geyser/text/ChatTypeEntry.java @@ -26,13 +26,12 @@ package org.geysermc.geyser.text; import com.github.steveice10.mc.protocol.data.game.chat.BuiltinChatType; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.protocol.bedrock.packet.TextPacket; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -public record ChatTypeEntry(@Nonnull TextPacket.Type bedrockChatType, @Nullable TextDecoration textDecoration) { +public record ChatTypeEntry(TextPacket.@NonNull Type bedrockChatType, @Nullable TextDecoration textDecoration) { private static final ChatTypeEntry CHAT = new ChatTypeEntry(TextPacket.Type.CHAT, null); private static final ChatTypeEntry RAW = new ChatTypeEntry(TextPacket.Type.RAW, null); diff --git a/core/src/main/java/org/geysermc/geyser/text/DummyLegacyHoverEventSerializer.java b/core/src/main/java/org/geysermc/geyser/text/DummyLegacyHoverEventSerializer.java index e934fc124..a6edffcd3 100644 --- a/core/src/main/java/org/geysermc/geyser/text/DummyLegacyHoverEventSerializer.java +++ b/core/src/main/java/org/geysermc/geyser/text/DummyLegacyHoverEventSerializer.java @@ -30,7 +30,7 @@ import net.kyori.adventure.text.Component; import net.kyori.adventure.text.event.HoverEvent; import net.kyori.adventure.text.serializer.json.LegacyHoverEventSerializer; import net.kyori.adventure.util.Codec; -import org.jetbrains.annotations.NotNull; +import org.checkerframework.checker.nullness.qual.NonNull; import java.nio.charset.StandardCharsets; import java.util.UUID; @@ -46,23 +46,23 @@ public final class DummyLegacyHoverEventSerializer implements LegacyHoverEventSe } @Override - public HoverEvent.@NotNull ShowItem deserializeShowItem(@NotNull Component input) { + public HoverEvent.@NonNull ShowItem deserializeShowItem(@NonNull Component input) { return dummyShowItem; } @Override - public HoverEvent.@NotNull ShowEntity deserializeShowEntity(@NotNull Component input, + public HoverEvent.@NonNull ShowEntity deserializeShowEntity(@NonNull Component input, Codec.Decoder componentDecoder) { return dummyShowEntity; } @Override - public @NotNull Component serializeShowItem(HoverEvent.@NotNull ShowItem input) { + public @NonNull Component serializeShowItem(HoverEvent.@NonNull ShowItem input) { return Component.empty(); } @Override - public @NotNull Component serializeShowEntity(HoverEvent.@NotNull ShowEntity input, + public @NonNull Component serializeShowEntity(HoverEvent.@NonNull ShowEntity input, Codec.Encoder componentEncoder) { return Component.empty(); } diff --git a/core/src/main/java/org/geysermc/geyser/text/GeyserLocale.java b/core/src/main/java/org/geysermc/geyser/text/GeyserLocale.java index 340674119..c6a58e75e 100644 --- a/core/src/main/java/org/geysermc/geyser/text/GeyserLocale.java +++ b/core/src/main/java/org/geysermc/geyser/text/GeyserLocale.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.text; import it.unimi.dsi.fastutil.objects.ObjectArrays; +import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.GeyserBootstrap; import org.geysermc.geyser.GeyserImpl; @@ -110,7 +111,7 @@ public class GeyserLocale { loadGeyserLocale(locale, geyser.getBootstrap()); } - private static String loadGeyserLocale(String locale, GeyserBootstrap bootstrap) { + private static @Nullable String loadGeyserLocale(String locale, GeyserBootstrap bootstrap) { locale = formatLocale(locale); // Don't load the locale if it's already loaded. if (LOCALE_MAPPINGS.containsKey(locale)) { diff --git a/core/src/main/java/org/geysermc/geyser/text/GsonComponentSerializerWrapper.java b/core/src/main/java/org/geysermc/geyser/text/GsonComponentSerializerWrapper.java index 2140dcc88..aaf100009 100644 --- a/core/src/main/java/org/geysermc/geyser/text/GsonComponentSerializerWrapper.java +++ b/core/src/main/java/org/geysermc/geyser/text/GsonComponentSerializerWrapper.java @@ -30,7 +30,7 @@ import com.google.gson.GsonBuilder; import com.google.gson.JsonElement; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; -import org.jetbrains.annotations.NotNull; +import org.checkerframework.checker.nullness.qual.NonNull; import java.util.function.UnaryOperator; @@ -40,28 +40,28 @@ import java.util.function.UnaryOperator; public record GsonComponentSerializerWrapper(GsonComponentSerializer source) implements GsonComponentSerializer { @Override - public @NotNull Gson serializer() { + public @NonNull Gson serializer() { return this.source.serializer(); } @Override - public @NotNull UnaryOperator populator() { + public @NonNull UnaryOperator populator() { return this.source.populator(); } @Override - public @NotNull Component deserializeFromTree(@NotNull JsonElement input) { + public @NonNull Component deserializeFromTree(@NonNull JsonElement input) { // This has yet to be an issue, so it won't be overridden unless we have to return this.source.deserializeFromTree(input); } @Override - public @NotNull JsonElement serializeToTree(@NotNull Component component) { + public @NonNull JsonElement serializeToTree(@NonNull Component component) { return this.source.serializeToTree(component); } @Override - public @NotNull Component deserialize(@NotNull String input) { + public @NonNull Component deserialize(@NonNull String input) { // See https://github.com/KyoriPowered/adventure/issues/447 Component component = this.serializer().fromJson(input, Component.class); if (component == null) { @@ -72,12 +72,12 @@ public record GsonComponentSerializerWrapper(GsonComponentSerializer source) imp } @Override - public @NotNull String serialize(@NotNull Component component) { + public @NonNull String serialize(@NonNull Component component) { return this.source.serialize(component); } @Override - public @NotNull Builder toBuilder() { + public @NonNull Builder toBuilder() { return this.source.toBuilder(); } } diff --git a/core/src/main/java/org/geysermc/geyser/text/MinecraftLocale.java b/core/src/main/java/org/geysermc/geyser/text/MinecraftLocale.java index 00866eda3..fa1b322a5 100644 --- a/core/src/main/java/org/geysermc/geyser/text/MinecraftLocale.java +++ b/core/src/main/java/org/geysermc/geyser/text/MinecraftLocale.java @@ -26,12 +26,12 @@ package org.geysermc.geyser.text; import com.fasterxml.jackson.databind.JsonNode; +import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.util.AssetUtils; import org.geysermc.geyser.util.FileUtils; import org.geysermc.geyser.util.WebUtils; -import javax.annotation.Nullable; import java.io.*; import java.nio.file.Files; import java.nio.file.Path; @@ -217,8 +217,7 @@ public class MinecraftLocale { * @param locale Locale to translate to * @return Translated string or null if it was not found in the given locale */ - @Nullable - public static String getLocaleStringIfPresent(String messageText, String locale) { + public static @Nullable String getLocaleStringIfPresent(String messageText, String locale) { Map localeStrings = LOCALE_MAPPINGS.get(locale.toLowerCase(Locale.ROOT)); if (localeStrings != null) { return localeStrings.get(messageText); diff --git a/core/src/main/java/org/geysermc/geyser/text/MinecraftTranslationRegistry.java b/core/src/main/java/org/geysermc/geyser/text/MinecraftTranslationRegistry.java index 3310859d0..b59b4db8e 100644 --- a/core/src/main/java/org/geysermc/geyser/text/MinecraftTranslationRegistry.java +++ b/core/src/main/java/org/geysermc/geyser/text/MinecraftTranslationRegistry.java @@ -26,9 +26,9 @@ package org.geysermc.geyser.text; import net.kyori.adventure.text.renderer.TranslatableComponentRenderer; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; import java.text.MessageFormat; import java.util.Locale; import java.util.regex.Matcher; @@ -44,12 +44,12 @@ public class MinecraftTranslationRegistry extends TranslatableComponentRenderer< // Exists to maintain compatibility with Velocity's older Adventure version @Override - public @Nullable MessageFormat translate(@Nonnull String key, @Nonnull String locale) { + public @Nullable MessageFormat translate(@NonNull String key, @NonNull String locale) { return this.translate(key, null, locale); } @Override - protected @Nullable MessageFormat translate(@Nonnull String key, @Nullable String fallback, @Nonnull String locale) { + protected @Nullable MessageFormat translate(@NonNull String key, @Nullable String fallback, @NonNull String locale) { // Get the locale string String localeString = MinecraftLocale.getLocaleStringIfPresent(key, locale); if (localeString == null) { @@ -66,7 +66,7 @@ public class MinecraftTranslationRegistry extends TranslatableComponentRenderer< // Replace the `%s` with numbered inserts `{0}` Pattern p = stringReplacement; Matcher m = p.matcher(localeString); - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); int i = 0; while (m.find()) { m.appendReplacement(sb, "{" + (i++) + "}"); @@ -76,7 +76,7 @@ public class MinecraftTranslationRegistry extends TranslatableComponentRenderer< // Replace the `%x$s` with numbered inserts `{x}` p = positionalStringReplacement; m = p.matcher(sb.toString()); - sb = new StringBuffer(); + sb = new StringBuilder(); while (m.find()) { i = Integer.parseInt(m.group(1)) - 1; m.appendReplacement(sb, "{" + i + "}"); diff --git a/core/src/main/java/org/geysermc/geyser/translator/collision/BlockCollision.java b/core/src/main/java/org/geysermc/geyser/translator/collision/BlockCollision.java index f7e39718b..e82b994c7 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/collision/BlockCollision.java +++ b/core/src/main/java/org/geysermc/geyser/translator/collision/BlockCollision.java @@ -54,7 +54,7 @@ public class BlockCollision { /** * This is used to control the maximum distance a face of a bounding box can push the player away */ - protected double pushAwayTolerance = CollisionManager.COLLISION_TOLERANCE * 1.1; + protected final double pushAwayTolerance = CollisionManager.COLLISION_TOLERANCE * 1.1; protected BlockCollision(BoundingBox[] boxes) { this.boundingBoxes = boxes; diff --git a/core/src/main/java/org/geysermc/geyser/translator/collision/SpawnerCollision.java b/core/src/main/java/org/geysermc/geyser/translator/collision/SpawnerCollision.java deleted file mode 100644 index 7d4dfedc2..000000000 --- a/core/src/main/java/org/geysermc/geyser/translator/collision/SpawnerCollision.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * @author GeyserMC - * @link https://github.com/GeyserMC/Geyser - */ - -package org.geysermc.geyser.translator.collision; - -import lombok.EqualsAndHashCode; - -@EqualsAndHashCode(callSuper = true) -@CollisionRemapper(regex = "^spawner$") -public class SpawnerCollision extends SolidCollision { - public SpawnerCollision(String params) { - super(params); - // Increase pushAwayTolerance to work around https://bugs.mojang.com/browse/MCPE-41996 - pushAwayTolerance = 0.0002; - } -} diff --git a/core/src/main/java/org/geysermc/geyser/translator/inventory/InventoryTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/inventory/InventoryTranslator.java index 106613e25..5262f048b 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/inventory/InventoryTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/inventory/InventoryTranslator.java @@ -129,7 +129,7 @@ public abstract class InventoryTranslator { /** * Should be overwritten in cases where specific inventories should reject an item being in a specific spot. * For examples, looms use this to reject items that are dyes in Bedrock but not in Java. - * + *

* The source/destination slot will be -1 if the cursor is the slot * * @return true if this transfer should be rejected diff --git a/core/src/main/java/org/geysermc/geyser/translator/inventory/item/ItemTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/inventory/item/ItemTranslator.java index 336809e8a..856b22c9b 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/inventory/item/ItemTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/inventory/item/ItemTranslator.java @@ -68,7 +68,6 @@ import org.geysermc.geyser.text.ChatColor; import org.geysermc.geyser.text.MinecraftLocale; import org.geysermc.geyser.translator.text.MessageTranslator; -import javax.annotation.Nonnull; import java.text.DecimalFormat; import java.util.*; @@ -98,7 +97,7 @@ public final class ItemTranslator { ItemStack itemStack = javaItem.translateToJava(data, bedrockItem, mappings); - if (itemStack != null && itemStack.getNbt() != null) { + if (itemStack.getNbt() != null) { javaItem.translateNbtToJava(itemStack.getNbt(), bedrockItem); if (itemStack.getNbt().isEmpty()) { // Otherwise, seems to cause issues with villagers accepting books, and I don't see how this will break anything else. - Camotoy @@ -108,8 +107,7 @@ public final class ItemTranslator { return itemStack; } - @Nonnull - public static ItemData.Builder translateToBedrock(GeyserSession session, int javaId, int count, CompoundTag tag) { + public static ItemData.@NonNull Builder translateToBedrock(GeyserSession session, int javaId, int count, CompoundTag tag) { ItemMapping bedrockItem = session.getItemMappings().getMapping(javaId); if (bedrockItem == ItemMapping.AIR) { session.getGeyser().getLogger().debug("ItemMapping returned air: " + javaId); @@ -118,7 +116,7 @@ public final class ItemTranslator { return translateToBedrock(session, Registries.JAVA_ITEMS.get().get(javaId), bedrockItem, count, tag); } - @Nonnull + @NonNull public static ItemData translateToBedrock(GeyserSession session, ItemStack stack) { if (stack == null) { return ItemData.AIR; @@ -134,8 +132,7 @@ public final class ItemTranslator { .build(); } - @Nonnull - private static ItemData.Builder translateToBedrock(GeyserSession session, Item javaItem, ItemMapping bedrockItem, int count, CompoundTag tag) { + private static ItemData.@NonNull Builder translateToBedrock(GeyserSession session, Item javaItem, ItemMapping bedrockItem, int count, CompoundTag tag) { CompoundTag nbt = tag != null ? tag.clone() : null; if (nbt != null) { @@ -365,7 +362,7 @@ public final class ItemTranslator { * @param canModifyJava the list of items in Java * @return the new list of items in Bedrock */ - private static String[] getCanModify(ListTag canModifyJava) { + private static String @Nullable [] getCanModify(ListTag canModifyJava) { if (canModifyJava != null && canModifyJava.size() > 0) { String[] canModifyBedrock = new String[canModifyJava.size()]; for (int i = 0; i < canModifyBedrock.length; i++) { @@ -384,7 +381,7 @@ public final class ItemTranslator { * Given an item stack, determine the Bedrock item definition that should be applied to Bedrock players. */ @NonNull - public static ItemDefinition getBedrockItemDefinition(GeyserSession session, @Nonnull GeyserItemStack itemStack) { + public static ItemDefinition getBedrockItemDefinition(GeyserSession session, @NonNull GeyserItemStack itemStack) { if (itemStack.isEmpty()) { return ItemDefinition.AIR; } @@ -429,7 +426,7 @@ public final class ItemTranslator { return NbtMap.EMPTY; } - private static Object translateToBedrockNBT(Tag tag) { + private static @Nullable Object translateToBedrockNBT(Tag tag) { if (tag instanceof CompoundTag compoundTag) { return translateNbtToBedrock(compoundTag); } @@ -443,6 +440,7 @@ public final class ItemTranslator { if (!tagList.isEmpty()) { type = NbtType.byClass(tagList.get(0).getClass()); } + //noinspection unchecked,rawtypes return new NbtList(type, tagList); } @@ -473,7 +471,7 @@ public final class ItemTranslator { return javaTag; } - private static Tag translateToJavaNBT(String name, Object object) { + private static @Nullable Tag translateToJavaNBT(String name, Object object) { if (object instanceof int[]) { return new IntArrayTag(name, (int[]) object); } @@ -610,7 +608,7 @@ public final class ItemTranslator { builder.blockDefinition(blockDefinition); } - private static CustomSkull getCustomSkull(GeyserSession session, CompoundTag nbt) { + private static @Nullable CustomSkull getCustomSkull(GeyserSession session, CompoundTag nbt) { if (nbt != null && nbt.contains("SkullOwner")) { if (!(nbt.get("SkullOwner") instanceof CompoundTag skullOwner)) { // It's a username give up d: diff --git a/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/BedrockOnlyBlockEntity.java b/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/BedrockOnlyBlockEntity.java index c43dfe8bc..07b075690 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/BedrockOnlyBlockEntity.java +++ b/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/BedrockOnlyBlockEntity.java @@ -25,6 +25,7 @@ package org.geysermc.geyser.translator.level.block.entity; +import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.math.vector.Vector3i; import org.cloudburstmc.nbt.NbtList; import org.cloudburstmc.nbt.NbtMap; @@ -57,7 +58,7 @@ public interface BedrockOnlyBlockEntity extends RequiresBlockState { * @param blockState Java BlockState of block. * @return Bedrock tag, or null if not a Bedrock-only Block Entity */ - static NbtMap getTag(GeyserSession session, Vector3i position, int blockState) { + static @Nullable NbtMap getTag(GeyserSession session, Vector3i position, int blockState) { if (FlowerPotBlockEntityTranslator.isFlowerBlock(blockState)) { return FlowerPotBlockEntityTranslator.getTag(session, blockState, position); } else if (PistonBlockEntityTranslator.isBlock(blockState)) { diff --git a/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/ShulkerBoxBlockEntityTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/ShulkerBoxBlockEntityTranslator.java index db7b3073f..bbe6a0725 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/ShulkerBoxBlockEntityTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/ShulkerBoxBlockEntityTranslator.java @@ -27,12 +27,11 @@ package org.geysermc.geyser.translator.level.block.entity; import com.github.steveice10.mc.protocol.data.game.level.block.BlockEntityType; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; +import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.nbt.NbtMapBuilder; import org.geysermc.geyser.level.block.BlockStateValues; import org.geysermc.geyser.translator.inventory.ShulkerInventoryTranslator; -import javax.annotation.Nullable; - @BlockEntity(type = BlockEntityType.SHULKER_BOX) public class ShulkerBoxBlockEntityTranslator extends BlockEntityTranslator implements RequiresBlockState { /** diff --git a/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/SkullBlockEntityTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/SkullBlockEntityTranslator.java index 7f87f9465..9ac9126db 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/SkullBlockEntityTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/level/block/entity/SkullBlockEntityTranslator.java @@ -30,6 +30,7 @@ import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.IntArrayTag; import com.github.steveice10.opennbt.tag.builtin.ListTag; import com.github.steveice10.opennbt.tag.builtin.StringTag; +import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.protocol.bedrock.data.definitions.BlockDefinition; import org.cloudburstmc.protocol.bedrock.packet.UpdateBlockPacket; import org.geysermc.geyser.GeyserImpl; @@ -99,7 +100,7 @@ public class SkullBlockEntityTranslator extends BlockEntityTranslator implements return CompletableFuture.completedFuture(texture.getValue()); } - public static BlockDefinition translateSkull(GeyserSession session, CompoundTag tag, Vector3i blockPosition, int blockState) { + public static @Nullable BlockDefinition translateSkull(GeyserSession session, CompoundTag tag, Vector3i blockPosition, int blockState) { CompoundTag owner = tag.get("SkullOwner"); if (owner == null) { session.getSkullCache().removeSkull(blockPosition); diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockInventoryTransactionTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockInventoryTransactionTranslator.java index bf437311d..29a78daf3 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockInventoryTransactionTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockInventoryTransactionTranslator.java @@ -635,16 +635,16 @@ public class BedrockInventoryTransactionTranslator extends PacketTranslator * The position between the intended click position and the player can be determined with two triangles. * First, we compute the difference of the X and Z coordinates: - * + *

* Player position (0, 0) * | * | * | * |_____________ Intended target (-3, 2) - * + *

* We then use the Pythagorean Theorem to find the direct line (hypotenuse) on the XZ plane. Finding the angle of the * triangle from there, closest to the player, gives us our yaw rotation value * Then doing the same using the new XZ distance and Y difference, we can find the direct line of sight from the diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockItemFrameDropItemTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockItemFrameDropItemTranslator.java index f11fd202c..8632dc4e1 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockItemFrameDropItemTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockItemFrameDropItemTranslator.java @@ -37,7 +37,7 @@ import org.geysermc.geyser.translator.protocol.Translator; /** * Pre-1.16.210: used for both survival and creative item frame item removal - * + *

* 1.16.210: only used in creative. */ @Translator(packet = ItemFrameDropItemPacket.class) diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/BedrockEntityEventTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/BedrockEntityEventTranslator.java index 58d5c2018..17a80aa39 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/BedrockEntityEventTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/entity/BedrockEntityEventTranslator.java @@ -60,6 +60,6 @@ public class BedrockEntityEventTranslator extends PacketTranslatorissue 3411. Not a perfect solution. */ private static String getEnumDataName(CommandNode node) { if (node.getProperties() instanceof ResourceProperties properties) { diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaLoginDisconnectTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaLoginDisconnectTranslator.java index 56309c058..daf42a68e 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaLoginDisconnectTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaLoginDisconnectTranslator.java @@ -83,8 +83,8 @@ public class JavaLoginDisconnectTranslator extends PacketTranslator children = component.children(); - for (int i = 0; i < children.size(); i++) { - if (children.get(i) instanceof TextComponent child && child.content().startsWith("Outdated server!")) { + for (Component value : children) { + if (value instanceof TextComponent child && child.content().startsWith("Outdated server!")) { // Reproduced on Paper 1.17.1 return true; } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaUpdateRecipesTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaUpdateRecipesTranslator.java index 71cb6019a..344e06c96 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaUpdateRecipesTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/JavaUpdateRecipesTranslator.java @@ -68,6 +68,7 @@ import static org.geysermc.geyser.util.InventoryUtils.LAST_RECIPE_NET_ID; /** * Used to send all valid recipes from Java to Bedrock. + *

* Bedrock REQUIRES a CraftingDataPacket to be sent in order to craft anything. */ @Translator(packet = ClientboundUpdateRecipesPacket.class) diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAnimateTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAnimateTranslator.java index 7df6b710c..1aa147314 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAnimateTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaAnimateTranslator.java @@ -56,13 +56,13 @@ public class JavaAnimateTranslator extends PacketTranslator { animatePacket.setAction(AnimatePacket.Action.SWING_ARM); if (entity.getEntityId() == session.getPlayerEntity().getEntityId()) { session.activateArmAnimationTicking(); } - break; - case SWING_OFFHAND: + } + case SWING_OFFHAND -> { // Use the OptionalPack to trigger the animation AnimateEntityPacket offHandPacket = new AnimateEntityPacket(); offHandPacket.setAnimation("animation.player.attack.rotations.offhand"); @@ -71,14 +71,13 @@ public class JavaAnimateTranslator extends PacketTranslator animatePacket.setAction(AnimatePacket.Action.CRITICAL_HIT); + case ENCHANTMENT_CRITICAL_HIT -> { animatePacket.setAction(AnimatePacket.Action.MAGIC_CRITICAL_HIT); // Unsure if this does anything + // Spawn custom particle SpawnParticleEffectPacket stringPacket = new SpawnParticleEffectPacket(); stringPacket.setIdentifier("geyseropt:enchanted_hit_multiple"); @@ -87,13 +86,12 @@ public class JavaAnimateTranslator extends PacketTranslator animatePacket.setAction(AnimatePacket.Action.WAKE_UP); + default -> { session.getGeyser().getLogger().debug("Unhandled java animation: " + animation); return; + } } session.sendUpstreamPacket(animatePacket); diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaTakeItemEntityTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaTakeItemEntityTranslator.java index 3b93f0df8..cc2b4b030 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaTakeItemEntityTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/JavaTakeItemEntityTranslator.java @@ -27,7 +27,6 @@ package org.geysermc.geyser.translator.protocol.java.entity; import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.ClientboundTakeItemEntityPacket; import org.cloudburstmc.protocol.bedrock.data.LevelEvent; -import org.cloudburstmc.protocol.bedrock.data.LevelEventType; import org.cloudburstmc.protocol.bedrock.packet.LevelEventPacket; import org.cloudburstmc.protocol.bedrock.packet.TakeItemEntityPacket; import org.geysermc.geyser.entity.type.Entity; diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaPlayerCombatKillTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaPlayerCombatKillTranslator.java index 4e8bd89b3..4b0cafed3 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaPlayerCombatKillTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/entity/player/JavaPlayerCombatKillTranslator.java @@ -28,7 +28,6 @@ package org.geysermc.geyser.translator.protocol.java.entity.player; import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.player.ClientboundPlayerCombatKillPacket; import org.cloudburstmc.protocol.bedrock.packet.DeathInfoPacket; import net.kyori.adventure.text.Component; -import org.geysermc.geyser.network.GameProtocol; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.translator.protocol.PacketTranslator; import org.geysermc.geyser.translator.protocol.Translator; diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaBlockDestructionTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaBlockDestructionTranslator.java index fc5d69443..49d043c62 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaBlockDestructionTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaBlockDestructionTranslator.java @@ -28,7 +28,6 @@ package org.geysermc.geyser.translator.protocol.java.level; import com.github.steveice10.mc.protocol.packet.ingame.clientbound.level.ClientboundBlockDestructionPacket; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import org.cloudburstmc.protocol.bedrock.data.LevelEvent; -import org.cloudburstmc.protocol.bedrock.data.LevelEventType; import org.cloudburstmc.protocol.bedrock.packet.LevelEventPacket; import org.geysermc.geyser.registry.BlockRegistries; import org.geysermc.geyser.registry.type.ItemMapping; diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaLevelParticlesTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaLevelParticlesTranslator.java index 6adb053d7..11d9dbddf 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaLevelParticlesTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/java/level/JavaLevelParticlesTranslator.java @@ -35,6 +35,7 @@ import com.github.steveice10.mc.protocol.data.game.level.particle.VibrationParti import com.github.steveice10.mc.protocol.data.game.level.particle.positionsource.BlockPositionSource; import com.github.steveice10.mc.protocol.data.game.level.particle.positionsource.EntityPositionSource; import com.github.steveice10.mc.protocol.packet.ingame.clientbound.level.ClientboundLevelParticlesPacket; +import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.nbt.NbtMap; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.LevelEvent; @@ -92,7 +93,7 @@ public class JavaLevelParticlesTranslator extends PacketTranslator createParticle(GeyserSession session, Particle particle) { + private @Nullable Function createParticle(GeyserSession session, Particle particle) { switch (particle.getType()) { case BLOCK -> { int blockState = session.getBlockMappings().getBedrockBlockId(((BlockParticleData) particle.getData()).getBlockState()); diff --git a/core/src/main/java/org/geysermc/geyser/translator/sound/SoundTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/sound/SoundTranslator.java index 0146c534e..7b42790ac 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/sound/SoundTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/sound/SoundTranslator.java @@ -38,7 +38,7 @@ public @interface SoundTranslator { /** * The identifier(s) that the placed block must contain * one of. Leave empty to ignore. - * + *

* Only applies to interaction handlers that are an * instance of {@link BlockSoundInteractionTranslator}. * diff --git a/core/src/main/java/org/geysermc/geyser/translator/sound/block/ComparatorSoundInteractionTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/sound/block/ComparatorSoundInteractionTranslator.java index 450078362..e77539e6e 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/sound/block/ComparatorSoundInteractionTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/sound/block/ComparatorSoundInteractionTranslator.java @@ -27,7 +27,6 @@ package org.geysermc.geyser.translator.sound.block; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.LevelEvent; -import org.cloudburstmc.protocol.bedrock.data.LevelEventType; import org.cloudburstmc.protocol.bedrock.packet.LevelEventPacket; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.translator.sound.BlockSoundInteractionTranslator; diff --git a/core/src/main/java/org/geysermc/geyser/translator/sound/block/DoorSoundInteractionTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/sound/block/DoorSoundInteractionTranslator.java index 107807fe0..8f8ab8bf6 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/sound/block/DoorSoundInteractionTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/sound/block/DoorSoundInteractionTranslator.java @@ -27,7 +27,6 @@ package org.geysermc.geyser.translator.sound.block; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.LevelEvent; -import org.cloudburstmc.protocol.bedrock.data.LevelEventType; import org.cloudburstmc.protocol.bedrock.packet.LevelEventPacket; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.translator.sound.BlockSoundInteractionTranslator; diff --git a/core/src/main/java/org/geysermc/geyser/translator/sound/block/LeverSoundInteractionTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/sound/block/LeverSoundInteractionTranslator.java index 08a8792e8..17b8768bc 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/sound/block/LeverSoundInteractionTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/sound/block/LeverSoundInteractionTranslator.java @@ -27,7 +27,6 @@ package org.geysermc.geyser.translator.sound.block; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.LevelEvent; -import org.cloudburstmc.protocol.bedrock.data.LevelEventType; import org.cloudburstmc.protocol.bedrock.packet.LevelEventPacket; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.translator.sound.BlockSoundInteractionTranslator; diff --git a/core/src/main/java/org/geysermc/geyser/translator/text/MessageTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/text/MessageTranslator.java index 5f811ab49..d93123cff 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/text/MessageTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/text/MessageTranslator.java @@ -201,7 +201,7 @@ public class MessageTranslator { /** * Verifies the message is valid JSON in case it's plaintext. Works around GsonComponentSerializer not using lenient mode. - * See https://wiki.vg/Chat for messages sent in lenient mode, and for a description on leniency. + * See here for messages sent in lenient mode, and for a description on leniency. * * @param message Potentially lenient JSON message * @param locale Locale to use for translation strings diff --git a/core/src/main/java/org/geysermc/geyser/util/AttributeUtils.java b/core/src/main/java/org/geysermc/geyser/util/AttributeUtils.java index 17502eae8..e1fe6e6f2 100644 --- a/core/src/main/java/org/geysermc/geyser/util/AttributeUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/AttributeUtils.java @@ -32,7 +32,7 @@ import com.github.steveice10.mc.protocol.data.game.entity.attribute.ModifierOper public class AttributeUtils { /** * Retrieve the base attribute value with all modifiers applied. - * https://minecraft.wiki/w/Attribute#Modifiers + * See here * @param attribute The attribute to calculate the total value. * @return The finished attribute with all modifiers applied. */ diff --git a/core/src/main/java/org/geysermc/geyser/util/BlockEntityUtils.java b/core/src/main/java/org/geysermc/geyser/util/BlockEntityUtils.java index 9964ed08b..31a2ddee9 100644 --- a/core/src/main/java/org/geysermc/geyser/util/BlockEntityUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/BlockEntityUtils.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.util; import com.github.steveice10.mc.protocol.data.game.level.block.BlockEntityType; +import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.math.vector.Vector3i; import org.cloudburstmc.nbt.NbtMap; import org.cloudburstmc.protocol.bedrock.packet.BlockEntityDataPacket; @@ -35,7 +36,6 @@ import org.geysermc.geyser.translator.level.block.entity.BedrockOnlyBlockEntity; import org.geysermc.geyser.translator.level.block.entity.BlockEntityTranslator; import org.geysermc.geyser.translator.level.block.entity.FlowerPotBlockEntityTranslator; -import javax.annotation.Nonnull; import java.util.List; import java.util.Locale; import java.util.Map; @@ -83,7 +83,7 @@ public class BlockEntityUtils { return Registries.BLOCK_ENTITIES.get(type); } - public static void updateBlockEntity(GeyserSession session, @Nonnull NbtMap blockEntity, Vector3i position) { + public static void updateBlockEntity(GeyserSession session, @NonNull NbtMap blockEntity, Vector3i position) { BlockEntityDataPacket blockEntityPacket = new BlockEntityDataPacket(); blockEntityPacket.setBlockPosition(position); blockEntityPacket.setData(blockEntity); diff --git a/core/src/main/java/org/geysermc/geyser/util/BlockUtils.java b/core/src/main/java/org/geysermc/geyser/util/BlockUtils.java index 23949d020..81a67a521 100644 --- a/core/src/main/java/org/geysermc/geyser/util/BlockUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/BlockUtils.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.util; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; +import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.math.vector.Vector3i; import org.geysermc.geyser.inventory.GeyserItemStack; import org.geysermc.geyser.inventory.PlayerInventory; @@ -36,8 +37,6 @@ import org.geysermc.geyser.registry.type.ItemMapping; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.translator.collision.BlockCollision; -import javax.annotation.Nullable; - public final class BlockUtils { private static boolean correctTool(GeyserSession session, BlockMapping blockMapping, String itemToolType) { diff --git a/core/src/main/java/org/geysermc/geyser/util/CooldownUtils.java b/core/src/main/java/org/geysermc/geyser/util/CooldownUtils.java index c00e389fd..60838686f 100644 --- a/core/src/main/java/org/geysermc/geyser/util/CooldownUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/CooldownUtils.java @@ -35,7 +35,7 @@ import java.util.concurrent.TimeUnit; /** * Manages the sending of a cooldown indicator to the Bedrock player as there is no cooldown indicator in Bedrock. - * Much of the work here is from the wonderful folks from ViaRewind: https://github.com/ViaVersion/ViaRewind + * Much of the work here is from the wonderful folks from ViaRewind */ public class CooldownUtils { private static CooldownType DEFAULT_SHOW_COOLDOWN; diff --git a/core/src/main/java/org/geysermc/geyser/util/CpuUtils.java b/core/src/main/java/org/geysermc/geyser/util/CpuUtils.java index 622722e5a..9f7bd9e61 100644 --- a/core/src/main/java/org/geysermc/geyser/util/CpuUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/CpuUtils.java @@ -49,7 +49,7 @@ public final class CpuUtils { /** * Much of the code here was copied from the OSHI project. This is simply stripped down to only get the CPU model. - * https://github.com/oshi/oshi/ + * See here */ private static String getLinuxProcessorName() throws Exception { List lines = Files.readAllLines(Paths.get("/proc/cpuinfo"), StandardCharsets.UTF_8); @@ -64,7 +64,7 @@ public final class CpuUtils { } /** - * https://stackoverflow.com/a/6327663 + * See here */ private static String getWindowsProcessorName() throws Exception { final String cpuNameCmd = "reg query \"HKLM\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0\" /v ProcessorNameString"; @@ -83,7 +83,7 @@ public final class CpuUtils { int p = result.indexOf(regstrToken); if (p == -1) { - return null; + return "unknown"; } return result.substring(p + regstrToken.length()).trim(); diff --git a/core/src/main/java/org/geysermc/geyser/util/FileUtils.java b/core/src/main/java/org/geysermc/geyser/util/FileUtils.java index 99e8f8d7d..c8cd31058 100644 --- a/core/src/main/java/org/geysermc/geyser/util/FileUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/FileUtils.java @@ -79,7 +79,7 @@ public class FileUtils { //noinspection ResultOfMethodCallIgnored file.createNewFile(); try (FileOutputStream fos = new FileOutputStream(file)) { - try (InputStream input = bootstrap.getResource(name)) { + try (InputStream input = bootstrap.getResourceOrThrow(name)) { byte[] bytes = new byte[input.available()]; //noinspection ResultOfMethodCallIgnored @@ -170,7 +170,7 @@ public class FileUtils { * @return the byte array of an InputStream */ public static byte[] readAllBytes(String resource) { - try (InputStream stream = GeyserImpl.getInstance().getBootstrap().getResource(resource)) { + try (InputStream stream = GeyserImpl.getInstance().getBootstrap().getResourceOrThrow(resource)) { return stream.readAllBytes(); } catch (IOException e) { throw new RuntimeException("Error while trying to read internal input stream!", e); @@ -225,7 +225,7 @@ public class FileUtils { * @return a set of all the classes annotated by the given annotation */ public static Set> getGeneratedClassesForAnnotation(String input) { - try (InputStream annotatedClass = GeyserImpl.getInstance().getBootstrap().getResource(input); + try (InputStream annotatedClass = GeyserImpl.getInstance().getBootstrap().getResourceOrThrow(input); BufferedReader reader = new BufferedReader(new InputStreamReader(annotatedClass))) { return reader.lines().map(className -> { try { diff --git a/core/src/main/java/org/geysermc/geyser/util/InventoryUtils.java b/core/src/main/java/org/geysermc/geyser/util/InventoryUtils.java index 0348eca11..f1bf03d90 100644 --- a/core/src/main/java/org/geysermc/geyser/util/InventoryUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/InventoryUtils.java @@ -31,6 +31,7 @@ import com.github.steveice10.mc.protocol.data.game.recipe.Ingredient; import com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.ServerboundPickItemPacket; import com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.ServerboundSetCreativeModeSlotPacket; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; +import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.math.vector.Vector3i; import org.cloudburstmc.nbt.NbtMap; import org.cloudburstmc.nbt.NbtMapBuilder; @@ -53,6 +54,7 @@ import org.geysermc.geyser.item.Items; import org.geysermc.geyser.level.BedrockDimension; import org.geysermc.geyser.registry.Registries; import org.geysermc.geyser.registry.type.ItemMapping; +import org.geysermc.geyser.registry.type.ItemMappings; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.text.ChatColor; import org.geysermc.geyser.text.GeyserLocale; @@ -60,7 +62,6 @@ import org.geysermc.geyser.translator.inventory.InventoryTranslator; import org.geysermc.geyser.translator.inventory.LecternInventoryTranslator; import org.geysermc.geyser.translator.inventory.chest.DoubleChestInventoryTranslator; -import javax.annotation.Nullable; import java.util.Arrays; import java.util.Collections; import java.util.Objects; @@ -129,7 +130,7 @@ public class InventoryUtils { session.setOpenInventory(null); } - public static Inventory getInventory(GeyserSession session, int javaId) { + public static @Nullable Inventory getInventory(GeyserSession session, int javaId) { if (javaId == 0) { return session.getPlayerInventory(); } else { @@ -207,12 +208,13 @@ public class InventoryUtils { } private static ItemDefinition getUnusableSpaceBlockDefinition(int protocolVersion) { + ItemMappings mappings = Registries.ITEMS.forVersion(protocolVersion); String unusableSpaceBlock = GeyserImpl.getInstance().getConfig().getUnusableSpaceBlock(); - ItemDefinition itemDefinition = Registries.ITEMS.forVersion(protocolVersion).getDefinition(unusableSpaceBlock); + ItemDefinition itemDefinition = mappings.getDefinition(unusableSpaceBlock); if (itemDefinition == null) { GeyserImpl.getInstance().getLogger().error("Invalid value " + unusableSpaceBlock + ". Resorting to barrier block."); - return Registries.ITEMS.forVersion(protocolVersion).getStoredItems().barrier().getBedrockDefinition(); + return mappings.getStoredItems().barrier().getBedrockDefinition(); } else { return itemDefinition; } @@ -284,7 +286,7 @@ public class InventoryUtils { * If it is found in another part of the inventory, move it. * If it is not found and the user is in creative mode, create the item, * overriding the current item slot if no other hotbar slots are empty, or otherwise selecting the empty slot. - * + *

* This attempts to mimic Java Edition behavior as best as it can. * @param session the Bedrock client's session * @param itemName the Java identifier of the item to search/select @@ -455,6 +457,7 @@ public class InventoryUtils { for (int col = firstCol; col < width + firstCol; col++) { GeyserItemStack geyserItemStack = inventoryGetter.apply(col + (row * gridDimensions) + 1); if (geyserItemStack.isEmpty()) { + //noinspection ConstantValue inventoryHasItem = itemStack == null || itemStack.getId() == 0; if (inventoryHasItem) { break crafting; @@ -476,6 +479,7 @@ public class InventoryUtils { return null; } + @SuppressWarnings("BooleanMethodIsAlwaysInverted") private static boolean testShapedRecipe(final Ingredient[] ingredients, final IntFunction inventoryGetter, final int gridDimensions, final int firstRow, final int height, final int firstCol, final int width) { int ingredientIndex = 0; diff --git a/core/src/main/java/org/geysermc/geyser/util/ItemUtils.java b/core/src/main/java/org/geysermc/geyser/util/ItemUtils.java index c528de741..a116c5cf2 100644 --- a/core/src/main/java/org/geysermc/geyser/util/ItemUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/ItemUtils.java @@ -29,12 +29,11 @@ import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.ListTag; import com.github.steveice10.opennbt.tag.builtin.StringTag; import com.github.steveice10.opennbt.tag.builtin.Tag; +import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.item.Items; import org.geysermc.geyser.item.type.FishingRodItem; import org.geysermc.geyser.item.type.Item; -import javax.annotation.Nullable; - public class ItemUtils { public static int getEnchantmentLevel(@Nullable CompoundTag itemNBTData, String enchantmentId) { @@ -74,7 +73,7 @@ public class ItemUtils { * @param itemTag the NBT tag of the item * @return the custom name of the item */ - public static String getCustomName(CompoundTag itemTag) { + public static @Nullable String getCustomName(CompoundTag itemTag) { if (itemTag != null) { if (itemTag.get("display") instanceof CompoundTag displayTag) { if (displayTag.get("Name") instanceof StringTag nameTag) { diff --git a/core/src/main/java/org/geysermc/geyser/util/JavaCodecUtil.java b/core/src/main/java/org/geysermc/geyser/util/JavaCodecUtil.java index f0b8ee6bc..795d45490 100644 --- a/core/src/main/java/org/geysermc/geyser/util/JavaCodecUtil.java +++ b/core/src/main/java/org/geysermc/geyser/util/JavaCodecUtil.java @@ -28,8 +28,8 @@ package org.geysermc.geyser.util; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.ListTag; import com.github.steveice10.opennbt.tag.builtin.Tag; +import org.checkerframework.checker.nullness.qual.NonNull; -import javax.annotation.Nonnull; import java.util.Iterator; public final class JavaCodecUtil { @@ -41,7 +41,7 @@ public final class JavaCodecUtil { ListTag value = tag.get("value"); Iterator originalIterator = value.iterator(); return new Iterable<>() { - @Nonnull + @NonNull @Override public Iterator iterator() { return new Iterator<>() { diff --git a/core/src/main/java/org/geysermc/geyser/util/Metrics.java b/core/src/main/java/org/geysermc/geyser/util/Metrics.java index e88d5a971..a4ef301e3 100644 --- a/core/src/main/java/org/geysermc/geyser/util/Metrics.java +++ b/core/src/main/java/org/geysermc/geyser/util/Metrics.java @@ -29,6 +29,8 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.GeyserImpl; import javax.net.ssl.HttpsURLConnection; @@ -48,8 +50,8 @@ import java.util.zip.GZIPOutputStream; /** * bStats collects some data for plugin authors. - * - * Check out https://bStats.org/ to learn more about bStats! + *

+ * Check out bStats to learn more about bStats! */ public class Metrics { @@ -140,7 +142,7 @@ public class Metrics { } customCharts.add(chart); } - data.put("customCharts", customCharts); + data.set("customCharts", customCharts); return data; } @@ -233,10 +235,7 @@ public class Metrics { * @return The gzipped String. * @throws IOException If the compression failed. */ - private static byte[] compress(final String str) throws IOException { - if (str == null) { - return null; - } + private static byte @NonNull [] compress(final @NonNull String str) throws IOException { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); GZIPOutputStream gzip = new GZIPOutputStream(outputStream); gzip.write(str.getBytes(StandardCharsets.UTF_8)); @@ -264,7 +263,7 @@ public class Metrics { this.chartId = chartId; } - private ObjectNode getRequestJsonNode() { + private @Nullable ObjectNode getRequestJsonNode() { ObjectNode chart = new ObjectMapper().createObjectNode(); chart.put("chartId", chartId); try { @@ -308,7 +307,7 @@ public class Metrics { } @Override - protected ObjectNode getChartData() throws Exception { + protected @Nullable ObjectNode getChartData() throws Exception { ObjectNode data = mapper.createObjectNode(); String value = callable.call(); if (value == null || value.isEmpty()) { @@ -339,7 +338,7 @@ public class Metrics { } @Override - protected ObjectNode getChartData() throws Exception { + protected @Nullable ObjectNode getChartData() throws Exception { ObjectNode data = mapper.createObjectNode(); ObjectNode values = mapper.createObjectNode(); Map map = callable.call(); @@ -383,7 +382,7 @@ public class Metrics { } @Override - public ObjectNode getChartData() throws Exception { + public @Nullable ObjectNode getChartData() throws Exception { ObjectNode data = mapper.createObjectNode(); ObjectNode values = mapper.createObjectNode(); Map> map = callable.call(); @@ -432,7 +431,7 @@ public class Metrics { } @Override - protected ObjectNode getChartData() throws Exception { + protected @Nullable ObjectNode getChartData() throws Exception { ObjectNode data = mapper.createObjectNode(); int value = callable.call(); if (value == 0) { @@ -445,135 +444,4 @@ public class Metrics { } - /** - * Represents a custom multi line chart. - */ - public static class MultiLineChart extends CustomChart { - - private final Callable> callable; - - /** - * Class constructor. - * - * @param chartId The id of the chart. - * @param callable The callable which is used to request the chart data. - */ - public MultiLineChart(String chartId, Callable> callable) { - super(chartId); - this.callable = callable; - } - - @Override - protected ObjectNode getChartData() throws Exception { - ObjectNode data = mapper.createObjectNode(); - ObjectNode values = mapper.createObjectNode(); - Map map = callable.call(); - if (map == null || map.isEmpty()) { - // Null = skip the chart - return null; - } - boolean allSkipped = true; - for (Map.Entry entry : map.entrySet()) { - if (entry.getValue() == 0) { - continue; // Skip this invalid - } - allSkipped = false; - values.put(entry.getKey(), entry.getValue()); - } - if (allSkipped) { - // Null = skip the chart - return null; - } - data.putPOJO("values", values); - return data; - } - - } - - /** - * Represents a custom simple bar chart. - */ - public static class SimpleBarChart extends CustomChart { - - private final Callable> callable; - - /** - * Class constructor. - * - * @param chartId The id of the chart. - * @param callable The callable which is used to request the chart data. - */ - public SimpleBarChart(String chartId, Callable> callable) { - super(chartId); - this.callable = callable; - } - - @Override - protected ObjectNode getChartData() throws Exception { - ObjectNode data = mapper.createObjectNode(); - ObjectNode values = mapper.createObjectNode(); - Map map = callable.call(); - if (map == null || map.isEmpty()) { - // Null = skip the chart - return null; - } - for (Map.Entry entry : map.entrySet()) { - ArrayNode categoryValues = mapper.createArrayNode(); - categoryValues.add(entry.getValue()); - values.putPOJO(entry.getKey(), categoryValues); - } - data.putPOJO("values", values); - return data; - } - - } - - /** - * Represents a custom advanced bar chart. - */ - public static class AdvancedBarChart extends CustomChart { - - private final Callable> callable; - - /** - * Class constructor. - * - * @param chartId The id of the chart. - * @param callable The callable which is used to request the chart data. - */ - public AdvancedBarChart(String chartId, Callable> callable) { - super(chartId); - this.callable = callable; - } - - @Override - protected ObjectNode getChartData() throws Exception { - ObjectNode data = mapper.createObjectNode(); - ObjectNode values = mapper.createObjectNode(); - Map map = callable.call(); - if (map == null || map.isEmpty()) { - // Null = skip the chart - return null; - } - boolean allSkipped = true; - for (Map.Entry entry : map.entrySet()) { - if (entry.getValue().length == 0) { - continue; // Skip this invalid - } - allSkipped = false; - ArrayNode categoryValues = mapper.createArrayNode(); - for (int categoryValue : entry.getValue()) { - categoryValues.add(categoryValue); - } - values.putPOJO(entry.getKey(), categoryValues); - } - if (allSkipped) { - // Null = skip the chart - return null; - } - data.putPOJO("values", values); - return data; - } - - } } \ No newline at end of file diff --git a/core/src/main/java/org/geysermc/geyser/util/SignUtils.java b/core/src/main/java/org/geysermc/geyser/util/SignUtils.java index fd2d98ba9..3a4ec4f2c 100644 --- a/core/src/main/java/org/geysermc/geyser/util/SignUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/SignUtils.java @@ -25,8 +25,6 @@ package org.geysermc.geyser.util; -import org.geysermc.geyser.level.block.BlockStateValues; - /** * Provides utilities for interacting with signs. Mainly, it deals with the widths of each character. * Since Bedrock auto-wraps signs and Java does not, we have to take this into account when translating signs. diff --git a/core/src/main/java/org/geysermc/geyser/util/SoundUtils.java b/core/src/main/java/org/geysermc/geyser/util/SoundUtils.java index b56d9873b..4c5f6b68f 100644 --- a/core/src/main/java/org/geysermc/geyser/util/SoundUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/SoundUtils.java @@ -26,6 +26,7 @@ package org.geysermc.geyser.util; import com.github.steveice10.mc.protocol.data.game.level.sound.Sound; +import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.math.vector.Vector3f; import org.cloudburstmc.protocol.bedrock.data.LevelEvent; import org.cloudburstmc.protocol.bedrock.data.SoundEvent; @@ -50,7 +51,7 @@ public final class SoundUtils { * @param sound the sound name * @return a sound event from the given sound */ - private static SoundEvent toSoundEvent(String sound) { + private static @Nullable SoundEvent toSoundEvent(String sound) { try { return SoundEvent.valueOf(sound.toUpperCase(Locale.ROOT).replace(".", "_")); } catch (Exception ex) { diff --git a/core/src/main/java/org/geysermc/geyser/util/VersionCheckUtils.java b/core/src/main/java/org/geysermc/geyser/util/VersionCheckUtils.java index c0fd10232..cf90a6bcd 100644 --- a/core/src/main/java/org/geysermc/geyser/util/VersionCheckUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/VersionCheckUtils.java @@ -31,6 +31,7 @@ import net.kyori.adventure.text.TextReplacementConfig; import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.TextDecoration; +import org.checkerframework.checker.nullness.qual.NonNull; import org.geysermc.geyser.Constants; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.GeyserLogger; @@ -38,7 +39,6 @@ import org.geysermc.geyser.command.GeyserCommandSource; import org.geysermc.geyser.network.GameProtocol; import org.geysermc.geyser.text.GeyserLocale; -import javax.annotation.Nonnull; import java.util.OptionalInt; import java.util.concurrent.CompletableFuture; import java.util.function.Supplier; @@ -46,7 +46,8 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; public final class VersionCheckUtils { - private static @Nonnull OptionalInt LATEST_BEDROCK_RELEASE = OptionalInt.empty(); + @SuppressWarnings("OptionalUsedAsFieldOrParameterType") + private static @NonNull OptionalInt LATEST_BEDROCK_RELEASE = OptionalInt.empty(); private static final int SUPPORTED_JAVA_VERSION = 17; public static void checkForOutdatedFloodgate(GeyserLogger logger) { @@ -125,7 +126,7 @@ public final class VersionCheckUtils { }); } - public static @Nonnull OptionalInt getLatestBedrockRelease() { + public static @NonNull OptionalInt getLatestBedrockRelease() { return LATEST_BEDROCK_RELEASE; } diff --git a/core/src/main/java/org/geysermc/geyser/util/WebUtils.java b/core/src/main/java/org/geysermc/geyser/util/WebUtils.java index e4a98b3fc..fbcbd4a3c 100644 --- a/core/src/main/java/org/geysermc/geyser/util/WebUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/WebUtils.java @@ -26,9 +26,9 @@ package org.geysermc.geyser.util; import com.fasterxml.jackson.databind.JsonNode; +import org.checkerframework.checker.nullness.qual.Nullable; import org.geysermc.geyser.GeyserImpl; -import javax.annotation.Nullable; import javax.naming.directory.Attribute; import javax.naming.directory.InitialDirContext; import java.io.*; @@ -101,7 +101,7 @@ public class WebUtils { * @param reqURL URL to post to * @param postContent String data to post * @return String returned by the server - * @throws IOException + * @throws IOException If the request fails */ public static String post(String reqURL, String postContent) throws IOException { URL url = new URL(reqURL); @@ -123,7 +123,7 @@ public class WebUtils { * * @param con The connection to get the string from * @return The body of the returned page - * @throws IOException + * @throws IOException If the request fails */ private static String connectionToString(HttpURLConnection con) throws IOException { // Send the request (we dont use this but its required for getErrorStream() to work) @@ -156,7 +156,7 @@ public class WebUtils { * @param reqURL URL to post to * @param fields Form data to post * @return String returned by the server - * @throws IOException + * @throws IOException If the request fails */ public static String postForm(String reqURL, Map fields) throws IOException { URL url = new URL(reqURL); @@ -169,15 +169,14 @@ public class WebUtils { try (OutputStream out = con.getOutputStream()) { // Write the form data to the output for (Map.Entry field : fields.entrySet()) { - out.write((field.getKey() + "=" + URLEncoder.encode(field.getValue(), StandardCharsets.UTF_8.toString()) + "&").getBytes(StandardCharsets.UTF_8)); + out.write((field.getKey() + "=" + URLEncoder.encode(field.getValue(), StandardCharsets.UTF_8) + "&").getBytes(StandardCharsets.UTF_8)); } } return connectionToString(con); } - @Nullable - public static String[] findSrvRecord(GeyserImpl geyser, String remoteAddress) { + public static String @Nullable [] findSrvRecord(GeyserImpl geyser, String remoteAddress) { try { // Searches for a server address and a port from a SRV record of the specified host name InitialDirContext ctx = new InitialDirContext(); diff --git a/core/src/main/java/org/geysermc/geyser/util/collection/FixedInt2BooleanMap.java b/core/src/main/java/org/geysermc/geyser/util/collection/FixedInt2BooleanMap.java index 832a7bcae..dc4545529 100644 --- a/core/src/main/java/org/geysermc/geyser/util/collection/FixedInt2BooleanMap.java +++ b/core/src/main/java/org/geysermc/geyser/util/collection/FixedInt2BooleanMap.java @@ -28,7 +28,13 @@ package org.geysermc.geyser.util.collection; import it.unimi.dsi.fastutil.ints.AbstractInt2BooleanMap; import it.unimi.dsi.fastutil.objects.ObjectSet; +import java.io.Serial; + public class FixedInt2BooleanMap extends AbstractInt2BooleanMap { + + @Serial + private static final long serialVersionUID = 1L; + protected boolean[] value; protected int start = -1; diff --git a/core/src/main/java/org/geysermc/geyser/util/collection/FixedInt2ByteMap.java b/core/src/main/java/org/geysermc/geyser/util/collection/FixedInt2ByteMap.java index ee37d612f..46cb2a2ca 100644 --- a/core/src/main/java/org/geysermc/geyser/util/collection/FixedInt2ByteMap.java +++ b/core/src/main/java/org/geysermc/geyser/util/collection/FixedInt2ByteMap.java @@ -29,7 +29,13 @@ import it.unimi.dsi.fastutil.ints.AbstractInt2ByteMap; import it.unimi.dsi.fastutil.ints.Int2ByteMap; import it.unimi.dsi.fastutil.objects.ObjectSet; +import java.io.Serial; + public class FixedInt2ByteMap extends AbstractInt2ByteMap { + + @Serial + private static final long serialVersionUID = 1L; + protected byte[] value; protected int start = -1; diff --git a/core/src/main/java/org/geysermc/geyser/util/collection/FixedInt2IntMap.java b/core/src/main/java/org/geysermc/geyser/util/collection/FixedInt2IntMap.java index f5bd89d64..4a27d51a9 100644 --- a/core/src/main/java/org/geysermc/geyser/util/collection/FixedInt2IntMap.java +++ b/core/src/main/java/org/geysermc/geyser/util/collection/FixedInt2IntMap.java @@ -29,10 +29,15 @@ import it.unimi.dsi.fastutil.ints.AbstractInt2IntMap; import it.unimi.dsi.fastutil.ints.Int2IntMap; import it.unimi.dsi.fastutil.objects.ObjectSet; +import java.io.Serial; + public class FixedInt2IntMap extends AbstractInt2IntMap { protected int[] value; protected int start = -1; + @Serial + private static final long serialVersionUID = 1L; + @Override public int size() { return value.length; diff --git a/core/src/main/java/org/geysermc/geyser/util/collection/LecternHasBookMap.java b/core/src/main/java/org/geysermc/geyser/util/collection/LecternHasBookMap.java index bafb2924c..42d0da803 100644 --- a/core/src/main/java/org/geysermc/geyser/util/collection/LecternHasBookMap.java +++ b/core/src/main/java/org/geysermc/geyser/util/collection/LecternHasBookMap.java @@ -32,11 +32,16 @@ import org.geysermc.geyser.level.WorldManager; import org.geysermc.geyser.session.GeyserSession; import org.geysermc.geyser.util.BlockEntityUtils; +import java.io.Serial; + /** * Map that takes advantage of its internals for fast operations on block states to determine if they are lecterns. */ public class LecternHasBookMap extends FixedInt2BooleanMap { + @Serial + private static final long serialVersionUID = 1L; + /** * Update a potential lectern within the world. This is a map method so it can use the internal fields to * optimize lectern determining. diff --git a/core/src/main/java/org/geysermc/geyser/util/collection/package-info.java b/core/src/main/java/org/geysermc/geyser/util/collection/package-info.java index e17a38877..46fa5df11 100644 --- a/core/src/main/java/org/geysermc/geyser/util/collection/package-info.java +++ b/core/src/main/java/org/geysermc/geyser/util/collection/package-info.java @@ -25,7 +25,7 @@ /** * Contains useful collections for use in Geyser. - * + *

* Of note are the fixed int maps. Designed for use with block states that are positive and sequential, they do not allow keys to be * added that are not greater by one versus the previous key. Because of this, speedy operations of {@link java.util.Map#get(java.lang.Object)} * and {@link java.util.Map#containsKey(java.lang.Object)} can be performed by simply checking the bounds of the map