diff --git a/src/main/java/net/minestom/server/advancements/AdvancementTab.java b/src/main/java/net/minestom/server/advancements/AdvancementTab.java index 5f3d041a1..d7c69dbfe 100644 --- a/src/main/java/net/minestom/server/advancements/AdvancementTab.java +++ b/src/main/java/net/minestom/server/advancements/AdvancementTab.java @@ -9,6 +9,7 @@ import net.minestom.server.utils.PacketUtils; import net.minestom.server.utils.advancement.AdvancementUtils; import net.minestom.server.utils.validate.Check; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.*; @@ -38,7 +39,7 @@ public class AdvancementTab implements Viewable { // will never change (since the root identifier is always the same) protected final ByteBuf removeBuffer; - protected AdvancementTab(String rootIdentifier, AdvancementRoot root) { + protected AdvancementTab(@NotNull String rootIdentifier, @NotNull AdvancementRoot root) { this.root = root; cacheAdvancement(rootIdentifier, root, null); @@ -53,7 +54,8 @@ public class AdvancementTab implements Viewable { * @param player the player to get the tabs from * @return all the advancement tabs that the player sees */ - public static Set getTabs(Player player) { + @NotNull + public static Set getTabs(@NotNull Player player) { return PLAYER_TAB_MAP.getOrDefault(player, null); } @@ -62,6 +64,7 @@ public class AdvancementTab implements Viewable { * * @return the root advancement */ + @NotNull public AdvancementRoot getRoot() { return root; } @@ -73,7 +76,7 @@ public class AdvancementTab implements Viewable { * @param advancement the advancement to add * @param parent the parent of this advancement, it cannot be null */ - public void createAdvancement(String identifier, Advancement advancement, Advancement parent) { + public void createAdvancement(@NotNull String identifier, @NotNull Advancement advancement, @NotNull Advancement parent) { Check.argCondition(identifier == null, "the advancement identifier cannot be null"); Check.stateCondition(!advancementMap.containsKey(parent), "You tried to set a parent which doesn't exist or isn't registered"); @@ -96,6 +99,7 @@ public class AdvancementTab implements Viewable { * * @return the packet adding this advancement tab and all its advancements */ + @NotNull protected AdvancementsPacket createPacket() { AdvancementsPacket advancementsPacket = new AdvancementsPacket(); advancementsPacket.resetAdvancements = false; @@ -120,9 +124,9 @@ public class AdvancementTab implements Viewable { * * @param identifier the identifier of the advancement * @param advancement the advancement - * @param parent the parent of this advancement + * @param parent the parent of this advancement, only null for the root advancement */ - private void cacheAdvancement(String identifier, Advancement advancement, Advancement parent) { + private void cacheAdvancement(@NotNull String identifier, @NotNull Advancement advancement, @Nullable Advancement parent) { Check.stateCondition(advancement.getTab() != null, "You tried to add an advancement already linked to a tab"); advancement.setTab(this); @@ -178,7 +182,7 @@ public class AdvancementTab implements Viewable { * * @param player the player */ - private void addPlayer(Player player) { + private void addPlayer(@NotNull Player player) { Set tabs = PLAYER_TAB_MAP.computeIfAbsent(player, p -> new HashSet<>()); tabs.add(this); } @@ -188,7 +192,7 @@ public class AdvancementTab implements Viewable { * * @param player the player */ - private void removePlayer(Player player) { + private void removePlayer(@NotNull Player player) { if (!PLAYER_TAB_MAP.containsKey(player)) { return; } diff --git a/src/main/java/net/minestom/server/attribute/Attribute.java b/src/main/java/net/minestom/server/attribute/Attribute.java index 654743693..94a634a3a 100644 --- a/src/main/java/net/minestom/server/attribute/Attribute.java +++ b/src/main/java/net/minestom/server/attribute/Attribute.java @@ -23,7 +23,7 @@ public enum Attribute { private final float defaultValue; private final float maxVanillaValue; - Attribute(String key, float defaultValue, float maxVanillaValue) { + Attribute(@NotNull String key, float defaultValue, float maxVanillaValue) { this.key = key; this.defaultValue = defaultValue; this.maxVanillaValue = maxVanillaValue; diff --git a/src/main/java/net/minestom/server/command/CommandManager.java b/src/main/java/net/minestom/server/command/CommandManager.java index 34334ad44..c7454e99a 100644 --- a/src/main/java/net/minestom/server/command/CommandManager.java +++ b/src/main/java/net/minestom/server/command/CommandManager.java @@ -22,6 +22,8 @@ import net.minestom.server.network.packet.server.play.DeclareCommandsPacket; import net.minestom.server.utils.ArrayUtils; import net.minestom.server.utils.validate.Check; import org.apache.commons.lang3.tuple.Pair; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.*; import java.util.function.Consumer; @@ -75,7 +77,7 @@ public final class CommandManager { * * @param command the command to register */ - public void register(Command command) { + public void register(@NotNull Command command) { this.dispatcher.register(command); } @@ -85,7 +87,8 @@ public final class CommandManager { * @param commandName the command name * @return the command associated with the name, null if not any */ - public Command getCommand(String commandName) { + @Nullable + public Command getCommand(@NotNull String commandName) { return dispatcher.findCommand(commandName); } @@ -94,7 +97,7 @@ public final class CommandManager { * * @param commandProcessor the command to register */ - public void register(CommandProcessor commandProcessor) { + public void register(@NotNull CommandProcessor commandProcessor) { this.commandProcessorMap.put(commandProcessor.getCommandName().toLowerCase(), commandProcessor); // Register aliases final String[] aliases = commandProcessor.getAliases(); @@ -111,7 +114,8 @@ public final class CommandManager { * @param commandName the command name * @return the command associated with the name, null if not any */ - public CommandProcessor getCommandProcessor(String commandName) { + @Nullable + public CommandProcessor getCommandProcessor(@NotNull String commandName) { return commandProcessorMap.get(commandName.toLowerCase()); } @@ -122,7 +126,7 @@ public final class CommandManager { * @param command the raw command string (without the command prefix) * @return true if the command hadn't been cancelled and has been successful */ - public boolean execute(CommandSender sender, String command) { + public boolean execute(@NotNull CommandSender sender, @NotNull String command) { Check.notNull(sender, "Source cannot be null"); Check.notNull(command, "Command string cannot be null"); @@ -165,6 +169,7 @@ public final class CommandManager { * * @return the {@link ConsoleSender} */ + @NotNull public ConsoleSender getConsoleSender() { return consoleSender; } @@ -177,7 +182,8 @@ public final class CommandManager { * @param player the player to get the commands packet * @return the {@link DeclareCommandsPacket} for {@code player} */ - public DeclareCommandsPacket createDeclareCommandsPacket(Player player) { + @NotNull + public DeclareCommandsPacket createDeclareCommandsPacket(@NotNull Player player) { return buildPacket(player); } @@ -187,7 +193,8 @@ public final class CommandManager { * @param player the player to build the packet for * @return the commands packet for the specific player */ - private DeclareCommandsPacket buildPacket(Player player) { + @NotNull + private DeclareCommandsPacket buildPacket(@NotNull Player player) { DeclareCommandsPacket declareCommandsPacket = new DeclareCommandsPacket(); List nodes = new ArrayList<>(); @@ -282,7 +289,11 @@ public final class CommandManager { * @param syntaxes the syntaxes of the command * @param rootChildren the children of the main node (all commands name) */ - private void createCommand(List nodes, IntList cmdChildren, String name, Collection syntaxes, IntList rootChildren) { + private void createCommand(@NotNull List nodes, + @NotNull IntList cmdChildren, + @NotNull String name, + @NotNull Collection syntaxes, + @NotNull IntList rootChildren) { DeclareCommandsPacket.Node literalNode = createMainNode(name, syntaxes.isEmpty()); @@ -347,7 +358,8 @@ public final class CommandManager { } } - private DeclareCommandsPacket.Node createMainNode(String name, boolean executable) { + @NotNull + private DeclareCommandsPacket.Node createMainNode(@NotNull String name, boolean executable) { DeclareCommandsPacket.Node literalNode = new DeclareCommandsPacket.Node(); literalNode.flags = getFlag(NodeType.LITERAL, executable, false, false); literalNode.name = name; @@ -362,7 +374,8 @@ public final class CommandManager { * @param executable true if this is the last argument, false otherwise * @return the list of nodes that the argument require */ - private List toNodes(Argument argument, boolean executable) { + @NotNull + private List toNodes(@NotNull Argument argument, boolean executable) { List nodes = new ArrayList<>(); // You can uncomment this to test any brigadier parser on the client @@ -526,7 +539,7 @@ public final class CommandManager { return nodes; } - private byte getNumberProperties(ArgumentNumber argumentNumber) { + private byte getNumberProperties(@NotNull ArgumentNumber argumentNumber) { byte result = 0; if (argumentNumber.hasMin()) result += 1; @@ -543,8 +556,9 @@ public final class CommandManager { * @param executable true if this will be the last argument, false otherwise * @return the created {@link DeclareCommandsPacket.Node} */ - private DeclareCommandsPacket.Node simpleArgumentNode(List nodes, - Argument argument, boolean executable, boolean suggestion) { + @NotNull + private DeclareCommandsPacket.Node simpleArgumentNode(@NotNull List nodes, + @NotNull Argument argument, boolean executable, boolean suggestion) { DeclareCommandsPacket.Node argumentNode = new DeclareCommandsPacket.Node(); nodes.add(argumentNode); @@ -554,7 +568,7 @@ public final class CommandManager { return argumentNode; } - private byte getFlag(NodeType type, boolean executable, boolean redirect, boolean suggestionType) { + private byte getFlag(@NotNull NodeType type, boolean executable, boolean redirect, boolean suggestionType) { byte result = (byte) type.mask; if (executable) { diff --git a/src/main/java/net/minestom/server/command/CommandProcessor.java b/src/main/java/net/minestom/server/command/CommandProcessor.java index 08cecc69a..9b9cefebc 100644 --- a/src/main/java/net/minestom/server/command/CommandProcessor.java +++ b/src/main/java/net/minestom/server/command/CommandProcessor.java @@ -1,6 +1,8 @@ package net.minestom.server.command; import net.minestom.server.entity.Player; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * Represents a simple command which give you the whole string representation @@ -18,6 +20,7 @@ public interface CommandProcessor { * * @return the main command's name */ + @NotNull String getCommandName(); /** @@ -27,6 +30,7 @@ public interface CommandProcessor { * * @return the command aliases */ + @Nullable String[] getAliases(); /** @@ -37,7 +41,7 @@ public interface CommandProcessor { * @param args an array containing all the args (split by space char) * @return true when the command is successful, false otherwise */ - boolean process(CommandSender sender, String command, String[] args); + boolean process(@NotNull CommandSender sender, @NotNull String command, @NotNull String[] args); /** * Called to know if a player has access to the command. @@ -48,7 +52,7 @@ public interface CommandProcessor { * @param player the player to check the access * @return true if the player has access to the command, false otherwise */ - boolean hasAccess(Player player); + boolean hasAccess(@NotNull Player player); /** * Needed to enable {@link #onWrite(String)} callback. @@ -71,7 +75,8 @@ public interface CommandProcessor { * @return the array containing all the suggestion for the current arg (split " "), can be null * @see #enableWritingTracking() */ - default String[] onWrite(String text) { + @Nullable + default String[] onWrite(@NotNull String text) { return null; } } diff --git a/src/main/java/net/minestom/server/command/CommandSender.java b/src/main/java/net/minestom/server/command/CommandSender.java index a5ab19a92..40c2807ec 100644 --- a/src/main/java/net/minestom/server/command/CommandSender.java +++ b/src/main/java/net/minestom/server/command/CommandSender.java @@ -2,6 +2,7 @@ package net.minestom.server.command; import net.minestom.server.entity.Player; import net.minestom.server.permission.Permission; +import org.jetbrains.annotations.NotNull; import java.util.Collection; @@ -17,14 +18,14 @@ public interface CommandSender { * * @param message the message to send */ - void sendMessage(String message); + void sendMessage(@NotNull String message); /** * Sends multiple raw string messages. * * @param messages the messages to send */ - default void sendMessage(String[] messages) { + default void sendMessage(@NotNull String[] messages) { for (String message : messages) { sendMessage(message); } @@ -36,6 +37,7 @@ public interface CommandSender { * * @return the permissions of this command sender. */ + @NotNull Collection getAllPermissions(); /** @@ -43,7 +45,7 @@ public interface CommandSender { * * @param permission the permission to add */ - default void addPermission(Permission permission) { + default void addPermission(@NotNull Permission permission) { getAllPermissions().add(permission); } @@ -52,7 +54,7 @@ public interface CommandSender { * * @param permission the permission to remove */ - default void removePermission(Permission permission) { + default void removePermission(@NotNull Permission permission) { getAllPermissions().remove(permission); } @@ -63,7 +65,7 @@ public interface CommandSender { * @param p permission to check against * @return true if the sender has the permission and validate {@link Permission#isValidFor(CommandSender)} */ - default boolean hasPermission(Permission p) { + default boolean hasPermission(@NotNull Permission p) { return getAllPermissions().contains(p) && p.isValidFor(this); } @@ -76,7 +78,7 @@ public interface CommandSender { * @return true if the sender has the permission and validate {@link Permission#isValidFor(CommandSender)} * @see #getAllPermissions() */ - default boolean hasPermission(Class permissionClass) { + default boolean hasPermission(@NotNull Class permissionClass) { boolean result = true; boolean foundPerm = false; for (Permission p : getAllPermissions()) { diff --git a/src/main/java/net/minestom/server/command/ConsoleSender.java b/src/main/java/net/minestom/server/command/ConsoleSender.java index a171b4c43..b7bd6eac0 100644 --- a/src/main/java/net/minestom/server/command/ConsoleSender.java +++ b/src/main/java/net/minestom/server/command/ConsoleSender.java @@ -1,6 +1,7 @@ package net.minestom.server.command; import net.minestom.server.permission.Permission; +import org.jetbrains.annotations.NotNull; import java.util.Collection; import java.util.LinkedList; @@ -14,10 +15,11 @@ public class ConsoleSender implements CommandSender { private final List permissions = new LinkedList<>(); @Override - public void sendMessage(String message) { + public void sendMessage(@NotNull String message) { System.out.println(message); } + @NotNull @Override public Collection getAllPermissions() { return permissions; diff --git a/src/main/java/net/minestom/server/command/builder/ArgumentCallback.java b/src/main/java/net/minestom/server/command/builder/ArgumentCallback.java index fc2623c72..0c0cf563b 100644 --- a/src/main/java/net/minestom/server/command/builder/ArgumentCallback.java +++ b/src/main/java/net/minestom/server/command/builder/ArgumentCallback.java @@ -2,6 +2,7 @@ package net.minestom.server.command.builder; import net.minestom.server.command.CommandSender; import net.minestom.server.command.builder.arguments.Argument; +import org.jetbrains.annotations.NotNull; /** * Callback executed when an error is found within the {@link Argument}. @@ -16,5 +17,5 @@ public interface ArgumentCallback { * @param value the raw string argument which is responsible for the error * @param error the error id (you can check its meaning in the specific argument class or ask the developer about it) */ - void apply(CommandSender source, String value, int error); + void apply(@NotNull CommandSender source, @NotNull String value, int error); } diff --git a/src/main/java/net/minestom/server/command/builder/Arguments.java b/src/main/java/net/minestom/server/command/builder/Arguments.java index 499987fd9..787941a0b 100644 --- a/src/main/java/net/minestom/server/command/builder/Arguments.java +++ b/src/main/java/net/minestom/server/command/builder/Arguments.java @@ -10,6 +10,7 @@ import net.minestom.server.potion.PotionEffect; import net.minestom.server.utils.math.FloatRange; import net.minestom.server.utils.math.IntRange; import net.minestom.server.utils.time.UpdateOption; +import org.jetbrains.annotations.NotNull; import org.jglrxavpok.hephaistos.nbt.NBT; import org.jglrxavpok.hephaistos.nbt.NBTCompound; @@ -18,97 +19,97 @@ import java.util.List; import java.util.Map; /** - * Class used to retrieve argument data + * Class used to retrieve argument data. */ public class Arguments { private final Map args = new HashMap<>(); - public boolean getBoolean(String id) { + public boolean getBoolean(@NotNull String id) { return (boolean) getObject(id); } - public long getLong(String id) { + public long getLong(@NotNull String id) { return (long) getObject(id); } - public int getInteger(String id) { + public int getInteger(@NotNull String id) { return (int) getObject(id); } - public double getDouble(String id) { + public double getDouble(@NotNull String id) { return (double) getObject(id); } - public float getFloat(String id) { + public float getFloat(@NotNull String id) { return (float) getObject(id); } - public String getString(String id) { + public String getString(@NotNull String id) { return (String) getObject(id); } - public String getWord(String id) { + public String getWord(@NotNull String id) { return getString(id); } - public String[] getStringArray(String id) { + public String[] getStringArray(@NotNull String id) { return (String[]) getObject(id); } - public ChatColor getColor(String id) { + public ChatColor getColor(@NotNull String id) { return (ChatColor) getObject(id); } - public UpdateOption getTime(String id) { + public UpdateOption getTime(@NotNull String id) { return (UpdateOption) getObject(id); } - public Enchantment getEnchantment(String id) { + public Enchantment getEnchantment(@NotNull String id) { return (Enchantment) getObject(id); } - public Particle getParticle(String id) { + public Particle getParticle(@NotNull String id) { return (Particle) getObject(id); } - public PotionEffect getPotionEffect(String id) { + public PotionEffect getPotionEffect(@NotNull String id) { return (PotionEffect) getObject(id); } - public EntityType getEntityType(String id) { + public EntityType getEntityType(@NotNull String id) { return (EntityType) getObject(id); } - public IntRange getIntRange(String id) { + public IntRange getIntRange(@NotNull String id) { return (IntRange) getObject(id); } - public FloatRange getFloatRange(String id) { + public FloatRange getFloatRange(@NotNull String id) { return (FloatRange) getObject(id); } - public List getEntities(String id) { + public List getEntities(@NotNull String id) { return (List) getObject(id); } - public ItemStack getItemStack(String id) { + public ItemStack getItemStack(@NotNull String id) { return (ItemStack) getObject(id); } - public NBTCompound getNbtCompound(String id) { + public NBTCompound getNbtCompound(@NotNull String id) { return (NBTCompound) getObject(id); } - public NBT getNBT(String id) { + public NBT getNBT(@NotNull String id) { return (NBT) getObject(id); } - public Object getObject(String id) { + public Object getObject(@NotNull String id) { return args.getOrDefault(id, null); } - protected void setArg(String id, Object value) { + protected void setArg(@NotNull String id, Object value) { this.args.put(id, value); } diff --git a/src/main/java/net/minestom/server/command/builder/Command.java b/src/main/java/net/minestom/server/command/builder/Command.java index 3ce3782e3..69d032ea0 100644 --- a/src/main/java/net/minestom/server/command/builder/Command.java +++ b/src/main/java/net/minestom/server/command/builder/Command.java @@ -6,6 +6,8 @@ import net.minestom.server.command.builder.arguments.ArgumentDynamicStringArray; import net.minestom.server.command.builder.arguments.ArgumentDynamicWord; import net.minestom.server.command.builder.arguments.ArgumentType; import net.minestom.server.command.builder.condition.CommandCondition; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Collection; @@ -48,7 +50,7 @@ public class Command { * @param aliases the command aliases * @see #Command(String) */ - public Command(String name, String... aliases) { + public Command(@NotNull String name, @Nullable String... aliases) { this.name = name; this.aliases = aliases; @@ -61,7 +63,7 @@ public class Command { * @param name the name of the command * @see #Command(String, String...) */ - public Command(String name) { + public Command(@NotNull String name) { this(name, new String[0]); } @@ -94,7 +96,7 @@ public class Command { * @param callback the callback for the argument * @param argument the argument which get the callback */ - public void setArgumentCallback(ArgumentCallback callback, Argument argument) { + public void setArgumentCallback(@NotNull ArgumentCallback callback, @NotNull Argument argument) { argument.setCallback(callback); } @@ -106,9 +108,8 @@ public class Command { * @param executor the executor to call when the syntax is successfully received * @param args all the arguments of the syntax */ - public void addSyntax(CommandExecutor executor, Argument... args) { - CommandSyntax syntax = new CommandSyntax(args); - syntax.setExecutor(executor); + public void addSyntax(@NotNull CommandExecutor executor, @NotNull Argument... args) { + final CommandSyntax syntax = new CommandSyntax(executor, args); this.syntaxes.add(syntax); } @@ -117,6 +118,7 @@ public class Command { * * @return the main command's name */ + @NotNull public String getName() { return name; } @@ -128,6 +130,7 @@ public class Command { * * @return the command aliases */ + @Nullable public String[] getAliases() { return aliases; } @@ -138,6 +141,7 @@ public class Command { * * @return the default executor */ + @Nullable public CommandExecutor getDefaultExecutor() { return defaultExecutor; } @@ -147,7 +151,7 @@ public class Command { * * @param executor the new default executor */ - public void setDefaultExecutor(CommandExecutor executor) { + public void setDefaultExecutor(@Nullable CommandExecutor executor) { this.defaultExecutor = executor; } @@ -156,6 +160,7 @@ public class Command { * * @return a collection containing all this command syntaxes */ + @NotNull public Collection getSyntaxes() { return syntaxes; } @@ -167,7 +172,8 @@ public class Command { * @param text the whole player's text * @return the array containing all the suggestion for the current arg (split " "), can be null */ - public String[] onDynamicWrite(String text) { + @Nullable + public String[] onDynamicWrite(@NotNull String text) { return null; } @@ -183,7 +189,7 @@ public class Command { * @param arguments the UNCHECKED arguments of the command, some can be null even when unexpected * @param command the raw UNCHECKED received command */ - public void globalListener(CommandSender sender, Arguments arguments, String command) { + public void globalListener(@NotNull CommandSender sender, @NotNull Arguments arguments, @NotNull String command) { } } diff --git a/src/main/java/net/minestom/server/command/builder/CommandExecutor.java b/src/main/java/net/minestom/server/command/builder/CommandExecutor.java index 84fed0f62..ef6010964 100644 --- a/src/main/java/net/minestom/server/command/builder/CommandExecutor.java +++ b/src/main/java/net/minestom/server/command/builder/CommandExecutor.java @@ -1,6 +1,7 @@ package net.minestom.server.command.builder; import net.minestom.server.command.CommandSender; +import org.jetbrains.annotations.NotNull; /** * Callback executed once a syntax has been found for a {@link Command}. @@ -9,5 +10,5 @@ import net.minestom.server.command.CommandSender; */ @FunctionalInterface public interface CommandExecutor { - void apply(CommandSender source, Arguments args); + void apply(@NotNull CommandSender source, @NotNull Arguments args); } \ No newline at end of file diff --git a/src/main/java/net/minestom/server/command/builder/CommandSyntax.java b/src/main/java/net/minestom/server/command/builder/CommandSyntax.java index 4cfab1b82..609367863 100644 --- a/src/main/java/net/minestom/server/command/builder/CommandSyntax.java +++ b/src/main/java/net/minestom/server/command/builder/CommandSyntax.java @@ -1,6 +1,7 @@ package net.minestom.server.command.builder; import net.minestom.server.command.builder.arguments.Argument; +import org.jetbrains.annotations.NotNull; /** * Represents a syntax in {@link Command}. @@ -10,7 +11,8 @@ public class CommandSyntax { private final Argument[] args; private CommandExecutor executor; - protected CommandSyntax(Argument... args) { + protected CommandSyntax(@NotNull CommandExecutor commandExecutor, @NotNull Argument... args) { + this.executor = commandExecutor; this.args = args; } @@ -19,6 +21,7 @@ public class CommandSyntax { * * @return the required arguments */ + @NotNull public Argument[] getArguments() { return args; } @@ -28,6 +31,7 @@ public class CommandSyntax { * * @return the executor of this syntax */ + @NotNull public CommandExecutor getExecutor() { return executor; } @@ -37,7 +41,7 @@ public class CommandSyntax { * * @param executor the new executor */ - public void setExecutor(CommandExecutor executor) { + public void setExecutor(@NotNull CommandExecutor executor) { this.executor = executor; } diff --git a/src/main/java/net/minestom/server/command/builder/arguments/Argument.java b/src/main/java/net/minestom/server/command/builder/arguments/Argument.java index 2e27e02dc..e6827c52f 100644 --- a/src/main/java/net/minestom/server/command/builder/arguments/Argument.java +++ b/src/main/java/net/minestom/server/command/builder/arguments/Argument.java @@ -2,6 +2,8 @@ package net.minestom.server.command.builder.arguments; import net.minestom.server.command.builder.ArgumentCallback; import net.minestom.server.command.builder.Command; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * An argument is meant to be parsed when added into a {@link Command} syntax. @@ -26,17 +28,17 @@ public abstract class Argument { private ArgumentCallback callback; - public Argument(String id, boolean allowSpace, boolean useRemaining) { + public Argument(@NotNull String id, boolean allowSpace, boolean useRemaining) { this.id = id; this.allowSpace = allowSpace; this.useRemaining = useRemaining; } - public Argument(String id, boolean allowSpace) { + public Argument(@NotNull String id, boolean allowSpace) { this(id, allowSpace, false); } - public Argument(String id) { + public Argument(@NotNull String id) { this(id, false, false); } @@ -46,7 +48,7 @@ public abstract class Argument { * @param value The received argument * @return The success/error code */ - public abstract int getCorrectionResult(String value); + public abstract int getCorrectionResult(@NotNull String value); /** * The argument syntax is correct, parsed here to the correct type. @@ -54,7 +56,8 @@ public abstract class Argument { * @param value The correct argument * @return The parsed argument */ - public abstract T parse(String value); + @NotNull + public abstract T parse(@NotNull String value); /** * The argument is at least partially correct (the syntax is good and the argument has been parsed) @@ -63,7 +66,7 @@ public abstract class Argument { * @param value The parsed argument * @return The success/error code */ - public abstract int getConditionResult(T value); + public abstract int getConditionResult(@NotNull T value); /** * Gets the ID of the argument, showed in-game above the chat bar @@ -71,6 +74,7 @@ public abstract class Argument { * * @return the argument id */ + @NotNull public String getId() { return id; } @@ -101,6 +105,7 @@ public abstract class Argument { * * @return the argument callback */ + @Nullable public ArgumentCallback getCallback() { return callback; } @@ -110,7 +115,7 @@ public abstract class Argument { * * @param callback the argument callback */ - public void setCallback(ArgumentCallback callback) { + public void setCallback(@Nullable ArgumentCallback callback) { this.callback = callback; } diff --git a/src/main/java/net/minestom/server/command/builder/arguments/ArgumentBoolean.java b/src/main/java/net/minestom/server/command/builder/arguments/ArgumentBoolean.java index 16bec43c9..7020bd490 100644 --- a/src/main/java/net/minestom/server/command/builder/arguments/ArgumentBoolean.java +++ b/src/main/java/net/minestom/server/command/builder/arguments/ArgumentBoolean.java @@ -1,5 +1,7 @@ package net.minestom.server.command.builder.arguments; +import org.jetbrains.annotations.NotNull; + /** * Represents a boolean value. *

@@ -14,18 +16,19 @@ public class ArgumentBoolean extends Argument { } @Override - public int getCorrectionResult(String value) { + public int getCorrectionResult(@NotNull String value) { return (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("false")) ? SUCCESS : NOT_BOOLEAN_ERROR; } + @NotNull @Override - public Boolean parse(String value) { + public Boolean parse(@NotNull String value) { return Boolean.parseBoolean(value); } @Override - public int getConditionResult(Boolean value) { + public int getConditionResult(@NotNull Boolean value) { return SUCCESS; } diff --git a/src/main/java/net/minestom/server/command/builder/arguments/ArgumentDynamicStringArray.java b/src/main/java/net/minestom/server/command/builder/arguments/ArgumentDynamicStringArray.java index d503f7f0c..e254e07f4 100644 --- a/src/main/java/net/minestom/server/command/builder/arguments/ArgumentDynamicStringArray.java +++ b/src/main/java/net/minestom/server/command/builder/arguments/ArgumentDynamicStringArray.java @@ -1,5 +1,7 @@ package net.minestom.server.command.builder.arguments; +import org.jetbrains.annotations.NotNull; + import java.util.regex.Pattern; /** @@ -13,17 +15,18 @@ public class ArgumentDynamicStringArray extends Argument { } @Override - public int getCorrectionResult(String value) { + public int getCorrectionResult(@NotNull String value) { return SUCCESS; } + @NotNull @Override - public String[] parse(String value) { + public String[] parse(@NotNull String value) { return value.split(Pattern.quote(" ")); } @Override - public int getConditionResult(String[] value) { + public int getConditionResult(@NotNull String[] value) { return SUCCESS; } } diff --git a/src/main/java/net/minestom/server/command/builder/arguments/ArgumentDynamicWord.java b/src/main/java/net/minestom/server/command/builder/arguments/ArgumentDynamicWord.java index 7e186c056..c4b88384e 100644 --- a/src/main/java/net/minestom/server/command/builder/arguments/ArgumentDynamicWord.java +++ b/src/main/java/net/minestom/server/command/builder/arguments/ArgumentDynamicWord.java @@ -1,5 +1,7 @@ package net.minestom.server.command.builder.arguments; +import org.jetbrains.annotations.NotNull; + /** * Same as {@link ArgumentWord} with the exception * that this argument can trigger {@link net.minestom.server.command.builder.Command#onDynamicWrite(String)}. @@ -11,17 +13,18 @@ public class ArgumentDynamicWord extends Argument { } @Override - public int getCorrectionResult(String value) { + public int getCorrectionResult(@NotNull String value) { return SUCCESS; } + @NotNull @Override - public String parse(String value) { + public String parse(@NotNull String value) { return value; } @Override - public int getConditionResult(String value) { + public int getConditionResult(@NotNull String value) { return SUCCESS; } } diff --git a/src/main/java/net/minestom/server/command/builder/arguments/ArgumentString.java b/src/main/java/net/minestom/server/command/builder/arguments/ArgumentString.java index eb6bbfb08..b390aaf0e 100644 --- a/src/main/java/net/minestom/server/command/builder/arguments/ArgumentString.java +++ b/src/main/java/net/minestom/server/command/builder/arguments/ArgumentString.java @@ -1,5 +1,7 @@ package net.minestom.server.command.builder.arguments; +import org.jetbrains.annotations.NotNull; + /** * Argument which will take a quoted string. *

@@ -14,7 +16,7 @@ public class ArgumentString extends Argument { } @Override - public int getCorrectionResult(String value) { + public int getCorrectionResult(@NotNull String value) { // Check if value start and end with quote final char first = value.charAt(0); final char last = value.charAt(value.length() - 1); @@ -38,8 +40,9 @@ public class ArgumentString extends Argument { return QUOTE_ERROR; } + @NotNull @Override - public String parse(String value) { + public String parse(@NotNull String value) { // Remove first and last characters (quote) value = value.substring(1, value.length() - 1); @@ -50,7 +53,7 @@ public class ArgumentString extends Argument { } @Override - public int getConditionResult(String value) { + public int getConditionResult(@NotNull String value) { return SUCCESS; } } diff --git a/src/main/java/net/minestom/server/command/builder/arguments/ArgumentStringArray.java b/src/main/java/net/minestom/server/command/builder/arguments/ArgumentStringArray.java index acc33076a..8f2a53bd2 100644 --- a/src/main/java/net/minestom/server/command/builder/arguments/ArgumentStringArray.java +++ b/src/main/java/net/minestom/server/command/builder/arguments/ArgumentStringArray.java @@ -1,5 +1,7 @@ package net.minestom.server.command.builder.arguments; +import org.jetbrains.annotations.NotNull; + import java.util.regex.Pattern; /** @@ -14,17 +16,18 @@ public class ArgumentStringArray extends Argument { } @Override - public int getCorrectionResult(String value) { + public int getCorrectionResult(@NotNull String value) { return SUCCESS; } + @NotNull @Override - public String[] parse(String value) { + public String[] parse(@NotNull String value) { return value.split(Pattern.quote(" ")); } @Override - public int getConditionResult(String[] value) { + public int getConditionResult(@NotNull String[] value) { return SUCCESS; } } diff --git a/src/main/java/net/minestom/server/command/builder/arguments/ArgumentType.java b/src/main/java/net/minestom/server/command/builder/arguments/ArgumentType.java index a2534179b..494340390 100644 --- a/src/main/java/net/minestom/server/command/builder/arguments/ArgumentType.java +++ b/src/main/java/net/minestom/server/command/builder/arguments/ArgumentType.java @@ -9,6 +9,7 @@ import net.minestom.server.command.builder.arguments.number.ArgumentDouble; import net.minestom.server.command.builder.arguments.number.ArgumentFloat; import net.minestom.server.command.builder.arguments.number.ArgumentInteger; import net.minestom.server.command.builder.arguments.number.ArgumentLong; +import org.jetbrains.annotations.NotNull; /** * Convenient class listing all the basics {@link Argument}. @@ -17,94 +18,94 @@ import net.minestom.server.command.builder.arguments.number.ArgumentLong; */ public class ArgumentType { - public static ArgumentBoolean Boolean(String id) { + public static ArgumentBoolean Boolean(@NotNull String id) { return new ArgumentBoolean(id); } - public static ArgumentLong Long(String id) { + public static ArgumentLong Long(@NotNull String id) { return new ArgumentLong(id); } - public static ArgumentInteger Integer(String id) { + public static ArgumentInteger Integer(@NotNull String id) { return new ArgumentInteger(id); } - public static ArgumentDouble Double(String id) { + public static ArgumentDouble Double(@NotNull String id) { return new ArgumentDouble(id); } - public static ArgumentFloat Float(String id) { + public static ArgumentFloat Float(@NotNull String id) { return new ArgumentFloat(id); } - public static ArgumentString String(String id) { + public static ArgumentString String(@NotNull String id) { return new ArgumentString(id); } - public static ArgumentWord Word(String id) { + public static ArgumentWord Word(@NotNull String id) { return new ArgumentWord(id); } - public static ArgumentDynamicWord DynamicWord(String id) { + public static ArgumentDynamicWord DynamicWord(@NotNull String id) { return new ArgumentDynamicWord(id); } - public static ArgumentStringArray StringArray(String id) { + public static ArgumentStringArray StringArray(@NotNull String id) { return new ArgumentStringArray(id); } - public static ArgumentDynamicStringArray DynamicStringArray(String id) { + public static ArgumentDynamicStringArray DynamicStringArray(@NotNull String id) { return new ArgumentDynamicStringArray(id); } // Minecraft specific arguments - public static ArgumentColor Color(String id) { + public static ArgumentColor Color(@NotNull String id) { return new ArgumentColor(id); } - public static ArgumentTime Time(String id) { + public static ArgumentTime Time(@NotNull String id) { return new ArgumentTime(id); } - public static ArgumentEnchantment Enchantment(String id) { + public static ArgumentEnchantment Enchantment(@NotNull String id) { return new ArgumentEnchantment(id); } - public static ArgumentParticle Particle(String id) { + public static ArgumentParticle Particle(@NotNull String id) { return new ArgumentParticle(id); } - public static ArgumentPotionEffect Potion(String id) { + public static ArgumentPotionEffect Potion(@NotNull String id) { return new ArgumentPotionEffect(id); } - public static ArgumentEntityType EntityType(String id) { + public static ArgumentEntityType EntityType(@NotNull String id) { return new ArgumentEntityType(id); } - public static ArgumentIntRange IntRange(String id) { + public static ArgumentIntRange IntRange(@NotNull String id) { return new ArgumentIntRange(id); } - public static ArgumentFloatRange FloatRange(String id) { + public static ArgumentFloatRange FloatRange(@NotNull String id) { return new ArgumentFloatRange(id); } @Deprecated - public static ArgumentEntities Entities(String id) { + public static ArgumentEntities Entities(@NotNull String id) { return new ArgumentEntities(id); } - public static ArgumentItemStack ItemStack(String id) { + public static ArgumentItemStack ItemStack(@NotNull String id) { return new ArgumentItemStack(id); } - public static ArgumentNbtCompoundTag NbtCompound(String id) { + public static ArgumentNbtCompoundTag NbtCompound(@NotNull String id) { return new ArgumentNbtCompoundTag(id); } - public static ArgumentNbtTag NBT(String id) { + public static ArgumentNbtTag NBT(@NotNull String id) { return new ArgumentNbtTag(id); } diff --git a/src/main/java/net/minestom/server/command/builder/arguments/ArgumentWord.java b/src/main/java/net/minestom/server/command/builder/arguments/ArgumentWord.java index e9541688b..5c6460843 100644 --- a/src/main/java/net/minestom/server/command/builder/arguments/ArgumentWord.java +++ b/src/main/java/net/minestom/server/command/builder/arguments/ArgumentWord.java @@ -1,5 +1,7 @@ package net.minestom.server.command.builder.arguments; +import org.jetbrains.annotations.NotNull; + /** * Represents a single word in the command. *

@@ -24,20 +26,21 @@ public class ArgumentWord extends Argument { } @Override - public int getCorrectionResult(String value) { + public int getCorrectionResult(@NotNull String value) { if (value.contains(" ")) return SPACE_ERROR; return SUCCESS; } + @NotNull @Override - public String parse(String value) { + public String parse(@NotNull String value) { return value; } @Override - public int getConditionResult(String value) { + public int getConditionResult(@NotNull String value) { // Check restrictions if (restrictions != null && restrictions.length > 0) { for (String r : restrictions) { diff --git a/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentColor.java b/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentColor.java index 4d9196bad..0d8478a3a 100644 --- a/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentColor.java +++ b/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentColor.java @@ -2,6 +2,7 @@ package net.minestom.server.command.builder.arguments.minecraft; import net.minestom.server.chat.ChatColor; import net.minestom.server.command.builder.arguments.Argument; +import org.jetbrains.annotations.NotNull; /** * Represents an argument which will give you a {@link ChatColor}. @@ -17,18 +18,19 @@ public class ArgumentColor extends Argument { } @Override - public int getCorrectionResult(String value) { + public int getCorrectionResult(@NotNull String value) { final ChatColor color = ChatColor.fromName(value); return color == ChatColor.NO_COLOR ? UNDEFINED_COLOR : SUCCESS; } + @NotNull @Override - public ChatColor parse(String value) { + public ChatColor parse(@NotNull String value) { return ChatColor.fromName(value); } @Override - public int getConditionResult(ChatColor value) { + public int getConditionResult(@NotNull ChatColor value) { return SUCCESS; } } diff --git a/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentEntities.java b/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentEntities.java index e97914db2..e6462d737 100644 --- a/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentEntities.java +++ b/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentEntities.java @@ -4,6 +4,7 @@ import net.minestom.server.MinecraftServer; import net.minestom.server.command.builder.arguments.Argument; import net.minestom.server.entity.Entity; import net.minestom.server.network.ConnectionManager; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.Arrays; @@ -46,7 +47,7 @@ public class ArgumentEntities extends Argument> { } @Override - public int getCorrectionResult(String value) { + public int getCorrectionResult(@NotNull String value) { System.out.println("check: " + value); // Check for raw player name @@ -112,13 +113,14 @@ public class ArgumentEntities extends Argument> { return finalIndex; } + @NotNull @Override - public ArrayList parse(String value) { + public ArrayList parse(@NotNull String value) { return null; } @Override - public int getConditionResult(ArrayList value) { + public int getConditionResult(@NotNull ArrayList value) { return SUCCESS; } diff --git a/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentFloatRange.java b/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentFloatRange.java index 81e25c284..eb6b1433b 100644 --- a/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentFloatRange.java +++ b/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentFloatRange.java @@ -1,6 +1,7 @@ package net.minestom.server.command.builder.arguments.minecraft; import net.minestom.server.utils.math.FloatRange; +import org.jetbrains.annotations.NotNull; import java.util.regex.Pattern; @@ -16,7 +17,7 @@ public class ArgumentFloatRange extends ArgumentRange { } @Override - public int getCorrectionResult(String value) { + public int getCorrectionResult(@NotNull String value) { try { Float.valueOf(value); return SUCCESS; // Is a single number @@ -43,8 +44,9 @@ public class ArgumentFloatRange extends ArgumentRange { } } + @NotNull @Override - public FloatRange parse(String value) { + public FloatRange parse(@NotNull String value) { if (value.contains("..")) { final int index = value.indexOf('.'); final String[] split = value.split(Pattern.quote("..")); diff --git a/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentIntRange.java b/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentIntRange.java index 4db7e278d..1f4849ec5 100644 --- a/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentIntRange.java +++ b/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentIntRange.java @@ -1,6 +1,7 @@ package net.minestom.server.command.builder.arguments.minecraft; import net.minestom.server.utils.math.IntRange; +import org.jetbrains.annotations.NotNull; import java.util.regex.Pattern; @@ -16,7 +17,7 @@ public class ArgumentIntRange extends ArgumentRange { } @Override - public int getCorrectionResult(String value) { + public int getCorrectionResult(@NotNull String value) { try { Integer.valueOf(value); return SUCCESS; // Is a single number @@ -43,8 +44,9 @@ public class ArgumentIntRange extends ArgumentRange { } } + @NotNull @Override - public IntRange parse(String value) { + public IntRange parse(@NotNull String value) { if (value.contains("..")) { final int index = value.indexOf('.'); final String[] split = value.split(Pattern.quote("..")); diff --git a/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentItemStack.java b/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentItemStack.java index 799b368c7..023db8573 100644 --- a/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentItemStack.java +++ b/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentItemStack.java @@ -5,6 +5,7 @@ import net.minestom.server.item.ItemStack; import net.minestom.server.item.Material; import net.minestom.server.registry.Registries; import net.minestom.server.utils.NBTUtils; +import org.jetbrains.annotations.NotNull; import org.jglrxavpok.hephaistos.nbt.NBT; import org.jglrxavpok.hephaistos.nbt.NBTCompound; import org.jglrxavpok.hephaistos.nbt.NBTException; @@ -29,7 +30,7 @@ public class ArgumentItemStack extends Argument { } @Override - public int getCorrectionResult(String value) { + public int getCorrectionResult(@NotNull String value) { if (value.startsWith("{")) { return NO_MATERIAL; } @@ -51,8 +52,9 @@ public class ArgumentItemStack extends Argument { } } + @NotNull @Override - public ItemStack parse(String value) { + public ItemStack parse(@NotNull String value) { final int nbtIndex = value.indexOf("{"); if (nbtIndex == -1) { @@ -83,7 +85,7 @@ public class ArgumentItemStack extends Argument { } @Override - public int getConditionResult(ItemStack value) { + public int getConditionResult(@NotNull ItemStack value) { return SUCCESS; } } diff --git a/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentNbtCompoundTag.java b/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentNbtCompoundTag.java index d0dd2d6fe..67d5f6122 100644 --- a/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentNbtCompoundTag.java +++ b/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentNbtCompoundTag.java @@ -1,6 +1,7 @@ package net.minestom.server.command.builder.arguments.minecraft; import net.minestom.server.command.builder.arguments.Argument; +import org.jetbrains.annotations.NotNull; import org.jglrxavpok.hephaistos.nbt.NBT; import org.jglrxavpok.hephaistos.nbt.NBTCompound; import org.jglrxavpok.hephaistos.nbt.NBTException; @@ -22,7 +23,7 @@ public class ArgumentNbtCompoundTag extends Argument { } @Override - public int getCorrectionResult(String value) { + public int getCorrectionResult(@NotNull String value) { try { NBT nbt = new SNBTParser(new StringReader(value)).parse(); return nbt instanceof NBTCompound ? SUCCESS : INVALID_NBT; @@ -31,8 +32,9 @@ public class ArgumentNbtCompoundTag extends Argument { } } + @NotNull @Override - public NBTCompound parse(String value) { + public NBTCompound parse(@NotNull String value) { try { NBT nbt = new SNBTParser(new StringReader(value)).parse(); return (NBTCompound) nbt; @@ -42,7 +44,7 @@ public class ArgumentNbtCompoundTag extends Argument { } @Override - public int getConditionResult(NBTCompound value) { + public int getConditionResult(@NotNull NBTCompound value) { return SUCCESS; } } diff --git a/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentNbtTag.java b/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentNbtTag.java index 981be0efe..c715b4dde 100644 --- a/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentNbtTag.java +++ b/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentNbtTag.java @@ -1,6 +1,7 @@ package net.minestom.server.command.builder.arguments.minecraft; import net.minestom.server.command.builder.arguments.Argument; +import org.jetbrains.annotations.NotNull; import org.jglrxavpok.hephaistos.nbt.NBT; import org.jglrxavpok.hephaistos.nbt.NBTException; import org.jglrxavpok.hephaistos.nbt.SNBTParser; @@ -23,7 +24,7 @@ public class ArgumentNbtTag extends Argument { } @Override - public int getCorrectionResult(String value) { + public int getCorrectionResult(@NotNull String value) { try { NBT nbt = new SNBTParser(new StringReader(value)).parse(); return nbt != null ? SUCCESS : INVALID_NBT; @@ -32,8 +33,9 @@ public class ArgumentNbtTag extends Argument { } } + @NotNull @Override - public NBT parse(String value) { + public NBT parse(@NotNull String value) { try { NBT nbt = new SNBTParser(new StringReader(value)).parse(); return nbt; @@ -43,7 +45,7 @@ public class ArgumentNbtTag extends Argument { } @Override - public int getConditionResult(NBT value) { + public int getConditionResult(@NotNull NBT value) { return SUCCESS; } } diff --git a/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentRange.java b/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentRange.java index 968b2f021..394d0c02d 100644 --- a/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentRange.java +++ b/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentRange.java @@ -1,6 +1,7 @@ package net.minestom.server.command.builder.arguments.minecraft; import net.minestom.server.command.builder.arguments.Argument; +import org.jetbrains.annotations.NotNull; /** * Abstract class used by {@link ArgumentIntRange} and {@link ArgumentFloatRange}. @@ -16,7 +17,7 @@ public abstract class ArgumentRange extends Argument { } @Override - public int getConditionResult(T value) { + public int getConditionResult(@NotNull T value) { return SUCCESS; } } diff --git a/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentTime.java b/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentTime.java index 6a40188ff..e64bd36e6 100644 --- a/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentTime.java +++ b/src/main/java/net/minestom/server/command/builder/arguments/minecraft/ArgumentTime.java @@ -5,6 +5,7 @@ import it.unimi.dsi.fastutil.chars.CharList; import net.minestom.server.command.builder.arguments.Argument; import net.minestom.server.utils.time.TimeUnit; import net.minestom.server.utils.time.UpdateOption; +import org.jetbrains.annotations.NotNull; /** * Represents an argument giving a time (day/second/tick). @@ -23,7 +24,7 @@ public class ArgumentTime extends Argument { } @Override - public int getCorrectionResult(String value) { + public int getCorrectionResult(@NotNull String value) { final char lastChar = value.charAt(value.length() - 1); if (!SUFFIXES.contains(lastChar)) return INVALID_TIME_FORMAT; @@ -39,8 +40,9 @@ public class ArgumentTime extends Argument { } } + @NotNull @Override - public UpdateOption parse(String value) { + public UpdateOption parse(@NotNull String value) { final char lastChar = value.charAt(value.length() - 1); TimeUnit timeUnit = null; if (lastChar == 'd') { @@ -57,7 +59,7 @@ public class ArgumentTime extends Argument { } @Override - public int getConditionResult(UpdateOption value) { + public int getConditionResult(@NotNull UpdateOption value) { return SUCCESS; } } diff --git a/src/main/java/net/minestom/server/command/builder/arguments/minecraft/registry/ArgumentRegistry.java b/src/main/java/net/minestom/server/command/builder/arguments/minecraft/registry/ArgumentRegistry.java index 24f87faba..02e3ef6ca 100644 --- a/src/main/java/net/minestom/server/command/builder/arguments/minecraft/registry/ArgumentRegistry.java +++ b/src/main/java/net/minestom/server/command/builder/arguments/minecraft/registry/ArgumentRegistry.java @@ -1,6 +1,7 @@ package net.minestom.server.command.builder.arguments.minecraft.registry; import net.minestom.server.command.builder.arguments.Argument; +import org.jetbrains.annotations.NotNull; public abstract class ArgumentRegistry extends Argument { @@ -13,17 +14,18 @@ public abstract class ArgumentRegistry extends Argument { public abstract T getRegistry(String value); @Override - public int getCorrectionResult(String value) { + public int getCorrectionResult(@NotNull String value) { return getRegistry(value) == null ? INVALID_NAME : SUCCESS; } + @NotNull @Override - public T parse(String value) { + public T parse(@NotNull String value) { return getRegistry(value); } @Override - public int getConditionResult(T value) { + public int getConditionResult(@NotNull T value) { return SUCCESS; } } diff --git a/src/main/java/net/minestom/server/command/builder/arguments/number/ArgumentDouble.java b/src/main/java/net/minestom/server/command/builder/arguments/number/ArgumentDouble.java index aca7e987d..f60b35ee6 100644 --- a/src/main/java/net/minestom/server/command/builder/arguments/number/ArgumentDouble.java +++ b/src/main/java/net/minestom/server/command/builder/arguments/number/ArgumentDouble.java @@ -1,5 +1,7 @@ package net.minestom.server.command.builder.arguments.number; +import org.jetbrains.annotations.NotNull; + public class ArgumentDouble extends ArgumentNumber { public ArgumentDouble(String id) { @@ -9,7 +11,7 @@ public class ArgumentDouble extends ArgumentNumber { } @Override - public int getCorrectionResult(String value) { + public int getCorrectionResult(@NotNull String value) { try { String parsed = parseValue(value); int radix = getRadix(value); @@ -24,8 +26,9 @@ public class ArgumentDouble extends ArgumentNumber { } } + @NotNull @Override - public Double parse(String value) { + public Double parse(@NotNull String value) { String parsed = parseValue(value); int radix = getRadix(value); if (radix != 10) { @@ -35,7 +38,7 @@ public class ArgumentDouble extends ArgumentNumber { } @Override - public int getConditionResult(Double value) { + public int getConditionResult(@NotNull Double value) { // Check range if (hasMin && value < min) { return RANGE_ERROR; diff --git a/src/main/java/net/minestom/server/command/builder/arguments/number/ArgumentFloat.java b/src/main/java/net/minestom/server/command/builder/arguments/number/ArgumentFloat.java index 1e7a16f0e..c0c1a66a8 100644 --- a/src/main/java/net/minestom/server/command/builder/arguments/number/ArgumentFloat.java +++ b/src/main/java/net/minestom/server/command/builder/arguments/number/ArgumentFloat.java @@ -1,5 +1,7 @@ package net.minestom.server.command.builder.arguments.number; +import org.jetbrains.annotations.NotNull; + public class ArgumentFloat extends ArgumentNumber { public ArgumentFloat(String id) { @@ -9,7 +11,7 @@ public class ArgumentFloat extends ArgumentNumber { } @Override - public int getCorrectionResult(String value) { + public int getCorrectionResult(@NotNull String value) { try { String parsed = parseValue(value); int radix = getRadix(value); @@ -24,8 +26,9 @@ public class ArgumentFloat extends ArgumentNumber { } } + @NotNull @Override - public Float parse(String value) { + public Float parse(@NotNull String value) { String parsed = parseValue(value); int radix = getRadix(value); if (radix != 10) { @@ -35,7 +38,7 @@ public class ArgumentFloat extends ArgumentNumber { } @Override - public int getConditionResult(Float value) { + public int getConditionResult(@NotNull Float value) { // Check range if (hasMin && value < min) { return RANGE_ERROR; diff --git a/src/main/java/net/minestom/server/command/builder/arguments/number/ArgumentInteger.java b/src/main/java/net/minestom/server/command/builder/arguments/number/ArgumentInteger.java index b2e4d5e1d..2dff21b04 100644 --- a/src/main/java/net/minestom/server/command/builder/arguments/number/ArgumentInteger.java +++ b/src/main/java/net/minestom/server/command/builder/arguments/number/ArgumentInteger.java @@ -1,5 +1,7 @@ package net.minestom.server.command.builder.arguments.number; +import org.jetbrains.annotations.NotNull; + public class ArgumentInteger extends ArgumentNumber { public ArgumentInteger(String id) { @@ -9,7 +11,7 @@ public class ArgumentInteger extends ArgumentNumber { } @Override - public int getCorrectionResult(String value) { + public int getCorrectionResult(@NotNull String value) { try { Integer.parseInt(parseValue(value), getRadix(value)); return SUCCESS; @@ -18,13 +20,14 @@ public class ArgumentInteger extends ArgumentNumber { } } + @NotNull @Override - public Integer parse(String value) { + public Integer parse(@NotNull String value) { return Integer.parseInt(parseValue(value), getRadix(value)); } @Override - public int getConditionResult(Integer value) { + public int getConditionResult(@NotNull Integer value) { // Check range if (hasMin && value < min) { return RANGE_ERROR; diff --git a/src/main/java/net/minestom/server/command/builder/arguments/number/ArgumentLong.java b/src/main/java/net/minestom/server/command/builder/arguments/number/ArgumentLong.java index e955d0e36..b925443f6 100644 --- a/src/main/java/net/minestom/server/command/builder/arguments/number/ArgumentLong.java +++ b/src/main/java/net/minestom/server/command/builder/arguments/number/ArgumentLong.java @@ -1,5 +1,7 @@ package net.minestom.server.command.builder.arguments.number; +import org.jetbrains.annotations.NotNull; + public class ArgumentLong extends ArgumentNumber { public ArgumentLong(String id) { @@ -9,7 +11,7 @@ public class ArgumentLong extends ArgumentNumber { } @Override - public int getCorrectionResult(String value) { + public int getCorrectionResult(@NotNull String value) { try { Long.parseLong(parseValue(value), getRadix(value)); return SUCCESS; @@ -18,13 +20,14 @@ public class ArgumentLong extends ArgumentNumber { } } + @NotNull @Override - public Long parse(String value) { + public Long parse(@NotNull String value) { return Long.parseLong(parseValue(value), getRadix(value)); } @Override - public int getConditionResult(Long value) { + public int getConditionResult(@NotNull Long value) { // Check range if (hasMin && value < min) { return RANGE_ERROR; diff --git a/src/main/java/net/minestom/server/command/builder/arguments/number/ArgumentNumber.java b/src/main/java/net/minestom/server/command/builder/arguments/number/ArgumentNumber.java index 62e252285..a51b94864 100644 --- a/src/main/java/net/minestom/server/command/builder/arguments/number/ArgumentNumber.java +++ b/src/main/java/net/minestom/server/command/builder/arguments/number/ArgumentNumber.java @@ -1,6 +1,8 @@ package net.minestom.server.command.builder.arguments.number; import net.minestom.server.command.builder.arguments.Argument; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.math.BigDecimal; import java.util.regex.Pattern; @@ -17,20 +19,23 @@ public abstract class ArgumentNumber extends Argument { super(id, false); } - public ArgumentNumber min(T value) { + @NotNull + public ArgumentNumber min(@NotNull T value) { this.min = value; this.hasMin = true; return this; } - public ArgumentNumber max(T value) { + @NotNull + public ArgumentNumber max(@NotNull T value) { this.max = value; this.hasMax = true; return this; } - public ArgumentNumber between(T min, T max) { + @NotNull + public ArgumentNumber between(@NotNull T min, @NotNull T max) { this.min = min; this.max = max; this.hasMin = true; @@ -52,6 +57,7 @@ public abstract class ArgumentNumber extends Argument { * * @return the minimum of this argument */ + @NotNull public T getMin() { return min; } @@ -70,11 +76,12 @@ public abstract class ArgumentNumber extends Argument { * * @return the maximum of this argument */ + @NotNull public T getMax() { return max; } - protected String parseValue(String value) { + protected String parseValue(@NotNull String value) { if (value.startsWith("0b")) { value = value.replaceFirst(Pattern.quote("0b"), ""); } else if (value.startsWith("0x")) { @@ -86,7 +93,7 @@ public abstract class ArgumentNumber extends Argument { return value; } - protected int getRadix(String value) { + protected int getRadix(@NotNull String value) { if (value.startsWith("0b")) { return 2; } else if (value.startsWith("0x")) { @@ -95,7 +102,8 @@ public abstract class ArgumentNumber extends Argument { return 10; } - protected String removeScientificNotation(String value) { + @Nullable + protected String removeScientificNotation(@NotNull String value) { try { return new BigDecimal(value).toPlainString(); } catch (NumberFormatException e) { diff --git a/src/main/java/net/minestom/server/command/builder/condition/CommandCondition.java b/src/main/java/net/minestom/server/command/builder/condition/CommandCondition.java index 288d04454..243872ba9 100644 --- a/src/main/java/net/minestom/server/command/builder/condition/CommandCondition.java +++ b/src/main/java/net/minestom/server/command/builder/condition/CommandCondition.java @@ -1,10 +1,11 @@ package net.minestom.server.command.builder.condition; import net.minestom.server.command.CommandSender; +import org.jetbrains.annotations.NotNull; /** - * Used to know if the {@link CommandSender} is allowed to run the command + * Used to know if the {@link CommandSender} is allowed to run the command. */ public interface CommandCondition { - boolean apply(CommandSender source); + boolean apply(@NotNull CommandSender source); } diff --git a/src/main/java/net/minestom/server/data/Data.java b/src/main/java/net/minestom/server/data/Data.java index 9d35c56c6..aa830ea5f 100644 --- a/src/main/java/net/minestom/server/data/Data.java +++ b/src/main/java/net/minestom/server/data/Data.java @@ -39,6 +39,7 @@ public interface Data { return true; } + @NotNull @Override public Data clone() { return this; @@ -79,7 +80,7 @@ public interface Data { * @return {@link #get(String)} if found, {@code defaultValue} otherwise */ @Nullable - T getOrDefault(@NotNull String key, T defaultValue); + T getOrDefault(@NotNull String key, @Nullable T defaultValue); /** * Gets if the data has a key. @@ -109,6 +110,7 @@ public interface Data { * * @return a cloned data object */ + @NotNull Data clone(); } diff --git a/src/main/java/net/minestom/server/data/DataImpl.java b/src/main/java/net/minestom/server/data/DataImpl.java index bac02e354..5c44b9eb1 100644 --- a/src/main/java/net/minestom/server/data/DataImpl.java +++ b/src/main/java/net/minestom/server/data/DataImpl.java @@ -44,6 +44,7 @@ public class DataImpl implements Data { return data.isEmpty(); } + @NotNull @Override public Data clone() { DataImpl data = new DataImpl(); diff --git a/src/main/java/net/minestom/server/data/DataManager.java b/src/main/java/net/minestom/server/data/DataManager.java index 517a44109..44758988d 100644 --- a/src/main/java/net/minestom/server/data/DataManager.java +++ b/src/main/java/net/minestom/server/data/DataManager.java @@ -7,6 +7,8 @@ import net.minestom.server.inventory.Inventory; import net.minestom.server.item.ItemStack; import net.minestom.server.utils.PrimitiveConversion; import net.minestom.server.utils.validate.Check; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.HashMap; import java.util.Map; @@ -62,7 +64,7 @@ public final class DataManager { * @param the data type * @throws IllegalStateException if the type {@code clazz} is already registered */ - public void registerType(Class clazz, DataType dataType) { + public void registerType(@NotNull Class clazz, @NotNull DataType dataType) { clazz = PrimitiveConversion.getObjectClass(clazz); Check.stateCondition(dataTypeMap.containsKey(clazz), "Type " + clazz.getName() + " has already been registered"); @@ -78,7 +80,8 @@ public final class DataManager { * @return the {@link DataType} associated to the class * @throws NullPointerException if none is found */ - public DataType getDataType(Class clazz) { + @Nullable + public DataType getDataType(@NotNull Class clazz) { clazz = PrimitiveConversion.getObjectClass(clazz); return dataTypeMap.get(clazz); } diff --git a/src/main/java/net/minestom/server/data/DataType.java b/src/main/java/net/minestom/server/data/DataType.java index 6b15f52ec..3cee713dc 100644 --- a/src/main/java/net/minestom/server/data/DataType.java +++ b/src/main/java/net/minestom/server/data/DataType.java @@ -2,6 +2,7 @@ package net.minestom.server.data; import net.minestom.server.utils.binary.BinaryReader; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; /** * Represents an object which can be encoded and decoded back. @@ -14,19 +15,20 @@ import net.minestom.server.utils.binary.BinaryWriter; public abstract class DataType { /** - * Encode the data type + * Encodes the data type. * * @param writer the data writer * @param value the value to encode */ - public abstract void encode(BinaryWriter writer, T value); + public abstract void encode(@NotNull BinaryWriter writer, @NotNull T value); /** - * Decode the data type + * Decodes the data type. * * @param reader the data reader * @return the decoded value */ - public abstract T decode(BinaryReader reader); + @NotNull + public abstract T decode(@NotNull BinaryReader reader); } \ No newline at end of file diff --git a/src/main/java/net/minestom/server/data/SerializableData.java b/src/main/java/net/minestom/server/data/SerializableData.java index 778e5a87a..274e2d3ea 100644 --- a/src/main/java/net/minestom/server/data/SerializableData.java +++ b/src/main/java/net/minestom/server/data/SerializableData.java @@ -5,6 +5,7 @@ import it.unimi.dsi.fastutil.objects.Object2ShortOpenHashMap; import net.minestom.server.MinecraftServer; import net.minestom.server.utils.binary.BinaryReader; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; /** * Represents a {@link Data} object which can be serialized and read back. @@ -16,63 +17,66 @@ public interface SerializableData extends Data { DataManager DATA_MANAGER = MinecraftServer.getDataManager(); /** - * Serialize the data into an array of bytes + * Serializes the data into an array of bytes. *

* Use {@link #readIndexedSerializedData(BinaryReader)} if {@code indexed} is true, * {@link #readSerializedData(BinaryReader, Object2ShortMap)} otherwise with the index map - * to convert it back to a {@link SerializableData} + * to convert it back to a {@link SerializableData}. * * @param typeToIndexMap the type to index map, will create entries if new types are discovered. * The map is not thread-safe * @param indexed true to add the types index in the header * @return the array representation of this data object */ - byte[] getSerializedData(Object2ShortMap typeToIndexMap, boolean indexed); + @NotNull + byte[] getSerializedData(@NotNull Object2ShortMap typeToIndexMap, boolean indexed); /** - * Read the data of a {@link SerializableData} when you already have the index map + * Reads the data of a {@link SerializableData} when you already have the index map. *

- * WARNING: the data to read should not have any index to read and your index map should be COMPLETE - * Use {@link #readIndexedSerializedData(BinaryReader)} if you need to read the header + * WARNING: the data to read should not have any index to read and your index map should be COMPLETE. + * Use {@link #readIndexedSerializedData(BinaryReader)} if you need to read the header. * * @param reader the binary reader * @param typeToIndexMap the index map */ - void readSerializedData(BinaryReader reader, Object2ShortMap typeToIndexMap); + void readSerializedData(@NotNull BinaryReader reader, @NotNull Object2ShortMap typeToIndexMap); /** - * Serialize the data into an array of bytes + * Serializes the data into an array of bytes. *

* Use {@link #readIndexedSerializedData(BinaryReader)} - * to convert it back to a {@link SerializableData} + * to convert it back to a {@link SerializableData}. *

- * This will create a type index map which will be present in the header + * This will create a type index map which will be present in the header. * * @return the array representation of this data object */ + @NotNull default byte[] getIndexedSerializedData() { return getSerializedData(new Object2ShortOpenHashMap<>(), true); } /** - * Read the index map and the data of a serialized {@link SerializableData} - * Got from {@link #getIndexedSerializedData()} + * Reads the index map and the data of a serialized {@link SerializableData}. + * + * Got from {@link #getIndexedSerializedData()}. * * @param reader the binary reader */ - default void readIndexedSerializedData(BinaryReader reader) { + default void readIndexedSerializedData(@NotNull BinaryReader reader) { final Object2ShortMap typeToIndexMap = SerializableData.readDataIndexes(reader); readSerializedData(reader, typeToIndexMap); } /** - * Write the index info (class name -> class index), used to write the header for indexed serialized data + * Writes the index info (class name -> class index), used to write the header for indexed serialized data. *

- * Sized by a var-int + * Sized by a var-int. * * @param typeToIndexMap the data index map */ - static void writeDataIndexHeader(BinaryWriter indexWriter, Object2ShortMap typeToIndexMap) { + static void writeDataIndexHeader(@NotNull BinaryWriter indexWriter, @NotNull Object2ShortMap typeToIndexMap) { // Write the size of the following index list (class name-> class index) indexWriter.writeVarInt(typeToIndexMap.size()); @@ -88,14 +92,15 @@ public interface SerializableData extends Data { } /** - * Read a data index map (type name -> type index) + * Reads a data index map (type name -> type index). *

- * Can then be used with {@link SerializableData#readSerializedData(BinaryReader, Object2ShortMap)} + * Can then be used with {@link SerializableData#readSerializedData(BinaryReader, Object2ShortMap)}. * * @param binaryReader the reader * @return a map containing the indexes of your data */ - static Object2ShortMap readDataIndexes(BinaryReader binaryReader) { + @NotNull + static Object2ShortMap readDataIndexes(@NotNull BinaryReader binaryReader) { Object2ShortMap typeToIndexMap = new Object2ShortOpenHashMap<>(); { final int dataIndexSize = binaryReader.readVarInt(); diff --git a/src/main/java/net/minestom/server/data/SerializableDataImpl.java b/src/main/java/net/minestom/server/data/SerializableDataImpl.java index 8c5a82882..af5d4dda5 100644 --- a/src/main/java/net/minestom/server/data/SerializableDataImpl.java +++ b/src/main/java/net/minestom/server/data/SerializableDataImpl.java @@ -49,6 +49,7 @@ public class SerializableDataImpl extends DataImpl implements SerializableData { this.dataType.put(key, type); } + @NotNull @Override public Data clone() { SerializableDataImpl data = new SerializableDataImpl(); @@ -57,8 +58,9 @@ public class SerializableDataImpl extends DataImpl implements SerializableData { return data; } + @NotNull @Override - public byte[] getSerializedData(Object2ShortMap typeToIndexMap, boolean indexed) { + public byte[] getSerializedData(@NotNull Object2ShortMap typeToIndexMap, boolean indexed) { // Get the current max index, it supposes that the index keep being incremented by 1 short lastIndex = (short) typeToIndexMap.size(); @@ -113,7 +115,7 @@ public class SerializableDataImpl extends DataImpl implements SerializableData { } @Override - public void readSerializedData(BinaryReader reader, Object2ShortMap typeToIndexMap) { + public void readSerializedData(@NotNull BinaryReader reader, @NotNull Object2ShortMap typeToIndexMap) { // Map used to convert an index to the class name (opposite of typeToIndexMap) final Short2ObjectMap indexToTypeMap = new Short2ObjectOpenHashMap<>(typeToIndexMap.size()); { diff --git a/src/main/java/net/minestom/server/data/type/BooleanData.java b/src/main/java/net/minestom/server/data/type/BooleanData.java index 440c7456d..38e0d7491 100644 --- a/src/main/java/net/minestom/server/data/type/BooleanData.java +++ b/src/main/java/net/minestom/server/data/type/BooleanData.java @@ -3,15 +3,17 @@ package net.minestom.server.data.type; import net.minestom.server.data.DataType; import net.minestom.server.utils.binary.BinaryReader; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class BooleanData extends DataType { @Override - public void encode(BinaryWriter writer, Boolean value) { + public void encode(@NotNull BinaryWriter writer, @NotNull Boolean value) { writer.writeBoolean(value); } + @NotNull @Override - public Boolean decode(BinaryReader reader) { + public Boolean decode(@NotNull BinaryReader reader) { return reader.readBoolean(); } } diff --git a/src/main/java/net/minestom/server/data/type/ByteData.java b/src/main/java/net/minestom/server/data/type/ByteData.java index 27a176663..0fd3c7693 100644 --- a/src/main/java/net/minestom/server/data/type/ByteData.java +++ b/src/main/java/net/minestom/server/data/type/ByteData.java @@ -3,15 +3,17 @@ package net.minestom.server.data.type; import net.minestom.server.data.DataType; import net.minestom.server.utils.binary.BinaryReader; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class ByteData extends DataType { @Override - public void encode(BinaryWriter writer, Byte value) { + public void encode(@NotNull BinaryWriter writer, @NotNull Byte value) { writer.writeByte(value); } + @NotNull @Override - public Byte decode(BinaryReader reader) { + public Byte decode(@NotNull BinaryReader reader) { return reader.readByte(); } } diff --git a/src/main/java/net/minestom/server/data/type/CharacterData.java b/src/main/java/net/minestom/server/data/type/CharacterData.java index cbeee8d0f..48d54ac7c 100644 --- a/src/main/java/net/minestom/server/data/type/CharacterData.java +++ b/src/main/java/net/minestom/server/data/type/CharacterData.java @@ -3,16 +3,18 @@ package net.minestom.server.data.type; import net.minestom.server.data.DataType; import net.minestom.server.utils.binary.BinaryReader; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class CharacterData extends DataType { @Override - public void encode(BinaryWriter writer, Character value) { + public void encode(@NotNull BinaryWriter writer, @NotNull Character value) { writer.writeChar(value); } + @NotNull @Override - public Character decode(BinaryReader reader) { + public Character decode(@NotNull BinaryReader reader) { return reader.readChar(); } } diff --git a/src/main/java/net/minestom/server/data/type/DoubleData.java b/src/main/java/net/minestom/server/data/type/DoubleData.java index 7c64b860c..f5b897589 100644 --- a/src/main/java/net/minestom/server/data/type/DoubleData.java +++ b/src/main/java/net/minestom/server/data/type/DoubleData.java @@ -3,16 +3,18 @@ package net.minestom.server.data.type; import net.minestom.server.data.DataType; import net.minestom.server.utils.binary.BinaryReader; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class DoubleData extends DataType { @Override - public void encode(BinaryWriter writer, Double value) { + public void encode(@NotNull BinaryWriter writer, @NotNull Double value) { writer.writeDouble(value); } + @NotNull @Override - public Double decode(BinaryReader reader) { + public Double decode(@NotNull BinaryReader reader) { return reader.readDouble(); } } diff --git a/src/main/java/net/minestom/server/data/type/FloatData.java b/src/main/java/net/minestom/server/data/type/FloatData.java index 97cb85ce4..69d392ddc 100644 --- a/src/main/java/net/minestom/server/data/type/FloatData.java +++ b/src/main/java/net/minestom/server/data/type/FloatData.java @@ -3,16 +3,18 @@ package net.minestom.server.data.type; import net.minestom.server.data.DataType; import net.minestom.server.utils.binary.BinaryReader; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class FloatData extends DataType { @Override - public void encode(BinaryWriter writer, Float value) { + public void encode(@NotNull BinaryWriter writer, @NotNull Float value) { writer.writeFloat(value); } + @NotNull @Override - public Float decode(BinaryReader reader) { + public Float decode(@NotNull BinaryReader reader) { return reader.readFloat(); } } diff --git a/src/main/java/net/minestom/server/data/type/IntegerData.java b/src/main/java/net/minestom/server/data/type/IntegerData.java index 7465f82a0..c0902b59c 100644 --- a/src/main/java/net/minestom/server/data/type/IntegerData.java +++ b/src/main/java/net/minestom/server/data/type/IntegerData.java @@ -3,16 +3,18 @@ package net.minestom.server.data.type; import net.minestom.server.data.DataType; import net.minestom.server.utils.binary.BinaryReader; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class IntegerData extends DataType { @Override - public void encode(BinaryWriter writer, Integer value) { + public void encode(@NotNull BinaryWriter writer, @NotNull Integer value) { writer.writeVarInt(value); } + @NotNull @Override - public Integer decode(BinaryReader reader) { + public Integer decode(@NotNull BinaryReader reader) { return reader.readVarInt(); } } \ No newline at end of file diff --git a/src/main/java/net/minestom/server/data/type/InventoryData.java b/src/main/java/net/minestom/server/data/type/InventoryData.java index 293098b71..78e05ebfb 100644 --- a/src/main/java/net/minestom/server/data/type/InventoryData.java +++ b/src/main/java/net/minestom/server/data/type/InventoryData.java @@ -5,11 +5,12 @@ import net.minestom.server.inventory.Inventory; import net.minestom.server.inventory.InventoryType; import net.minestom.server.utils.binary.BinaryReader; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class InventoryData extends DataType { @Override - public void encode(BinaryWriter writer, Inventory value) { + public void encode(@NotNull BinaryWriter writer, @NotNull Inventory value) { final InventoryType inventoryType = value.getInventoryType(); final int size = inventoryType.getAdditionalSlot(); @@ -23,8 +24,9 @@ public class InventoryData extends DataType { } } + @NotNull @Override - public Inventory decode(BinaryReader reader) { + public Inventory decode(@NotNull BinaryReader reader) { final String title = reader.readSizedString(); final InventoryType inventoryType = InventoryType.valueOf(reader.readSizedString()); final int size = inventoryType.getAdditionalSlot(); diff --git a/src/main/java/net/minestom/server/data/type/ItemStackData.java b/src/main/java/net/minestom/server/data/type/ItemStackData.java index 8c28e5172..810be1e98 100644 --- a/src/main/java/net/minestom/server/data/type/ItemStackData.java +++ b/src/main/java/net/minestom/server/data/type/ItemStackData.java @@ -4,15 +4,17 @@ import net.minestom.server.data.DataType; import net.minestom.server.item.ItemStack; import net.minestom.server.utils.binary.BinaryReader; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class ItemStackData extends DataType { @Override - public void encode(BinaryWriter writer, ItemStack value) { + public void encode(@NotNull BinaryWriter writer, @NotNull ItemStack value) { writer.writeItemStack(value); } + @NotNull @Override - public ItemStack decode(BinaryReader reader) { + public ItemStack decode(@NotNull BinaryReader reader) { return reader.readSlot(); } } diff --git a/src/main/java/net/minestom/server/data/type/LongData.java b/src/main/java/net/minestom/server/data/type/LongData.java index 83dc0a459..ebd97be26 100644 --- a/src/main/java/net/minestom/server/data/type/LongData.java +++ b/src/main/java/net/minestom/server/data/type/LongData.java @@ -3,15 +3,17 @@ package net.minestom.server.data.type; import net.minestom.server.data.DataType; import net.minestom.server.utils.binary.BinaryReader; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class LongData extends DataType { @Override - public void encode(BinaryWriter writer, Long value) { + public void encode(@NotNull BinaryWriter writer, @NotNull Long value) { writer.writeLong(value); } + @NotNull @Override - public Long decode(BinaryReader reader) { + public Long decode(@NotNull BinaryReader reader) { return reader.readLong(); } } diff --git a/src/main/java/net/minestom/server/data/type/SerializableDataData.java b/src/main/java/net/minestom/server/data/type/SerializableDataData.java index 3507e872e..85ceaefd3 100644 --- a/src/main/java/net/minestom/server/data/type/SerializableDataData.java +++ b/src/main/java/net/minestom/server/data/type/SerializableDataData.java @@ -5,17 +5,19 @@ import net.minestom.server.data.SerializableData; import net.minestom.server.data.SerializableDataImpl; import net.minestom.server.utils.binary.BinaryReader; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; // Pretty weird name huh? public class SerializableDataData extends DataType { @Override - public void encode(BinaryWriter writer, SerializableData value) { + public void encode(@NotNull BinaryWriter writer, @NotNull SerializableData value) { writer.writeBytes(value.getIndexedSerializedData()); } + @NotNull @Override - public SerializableData decode(BinaryReader reader) { + public SerializableData decode(@NotNull BinaryReader reader) { SerializableData serializableData = new SerializableDataImpl(); serializableData.readIndexedSerializedData(reader); return serializableData; diff --git a/src/main/java/net/minestom/server/data/type/ShortData.java b/src/main/java/net/minestom/server/data/type/ShortData.java index 5800ede45..01c746370 100644 --- a/src/main/java/net/minestom/server/data/type/ShortData.java +++ b/src/main/java/net/minestom/server/data/type/ShortData.java @@ -3,16 +3,18 @@ package net.minestom.server.data.type; import net.minestom.server.data.DataType; import net.minestom.server.utils.binary.BinaryReader; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class ShortData extends DataType { @Override - public void encode(BinaryWriter writer, Short value) { + public void encode(@NotNull BinaryWriter writer, @NotNull Short value) { writer.writeShort(value); } + @NotNull @Override - public Short decode(BinaryReader reader) { + public Short decode(@NotNull BinaryReader reader) { return reader.readShort(); } } diff --git a/src/main/java/net/minestom/server/data/type/StringData.java b/src/main/java/net/minestom/server/data/type/StringData.java index 6a604ed50..99d0a3a5f 100644 --- a/src/main/java/net/minestom/server/data/type/StringData.java +++ b/src/main/java/net/minestom/server/data/type/StringData.java @@ -3,16 +3,18 @@ package net.minestom.server.data.type; import net.minestom.server.data.DataType; import net.minestom.server.utils.binary.BinaryReader; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class StringData extends DataType { @Override - public void encode(BinaryWriter writer, String value) { + public void encode(@NotNull BinaryWriter writer, @NotNull String value) { writer.writeSizedString(value); } + @NotNull @Override - public String decode(BinaryReader reader) { + public String decode(@NotNull BinaryReader reader) { return reader.readSizedString(); } } diff --git a/src/main/java/net/minestom/server/data/type/UuidType.java b/src/main/java/net/minestom/server/data/type/UuidType.java index 8df3929f7..e4c026ed0 100644 --- a/src/main/java/net/minestom/server/data/type/UuidType.java +++ b/src/main/java/net/minestom/server/data/type/UuidType.java @@ -3,17 +3,19 @@ package net.minestom.server.data.type; import net.minestom.server.data.DataType; import net.minestom.server.utils.binary.BinaryReader; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; import java.util.UUID; public class UuidType extends DataType { @Override - public void encode(BinaryWriter writer, UUID value) { + public void encode(@NotNull BinaryWriter writer, @NotNull UUID value) { writer.writeUuid(value); } + @NotNull @Override - public UUID decode(BinaryReader reader) { + public UUID decode(@NotNull BinaryReader reader) { return reader.readUuid(); } } diff --git a/src/main/java/net/minestom/server/data/type/array/BooleanArrayData.java b/src/main/java/net/minestom/server/data/type/array/BooleanArrayData.java index b74ac2c81..bbcbdd19c 100644 --- a/src/main/java/net/minestom/server/data/type/array/BooleanArrayData.java +++ b/src/main/java/net/minestom/server/data/type/array/BooleanArrayData.java @@ -3,19 +3,21 @@ package net.minestom.server.data.type.array; import net.minestom.server.data.DataType; import net.minestom.server.utils.binary.BinaryReader; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class BooleanArrayData extends DataType { @Override - public void encode(BinaryWriter writer, boolean[] value) { + public void encode(@NotNull BinaryWriter writer, @NotNull boolean[] value) { writer.writeVarInt(value.length); for (boolean val : value) { writer.writeBoolean(val); } } + @NotNull @Override - public boolean[] decode(BinaryReader reader) { + public boolean[] decode(@NotNull BinaryReader reader) { boolean[] array = new boolean[reader.readVarInt()]; for (int i = 0; i < array.length; i++) { array[i] = reader.readBoolean(); diff --git a/src/main/java/net/minestom/server/data/type/array/ByteArrayData.java b/src/main/java/net/minestom/server/data/type/array/ByteArrayData.java index 7ef154681..eb69118de 100644 --- a/src/main/java/net/minestom/server/data/type/array/ByteArrayData.java +++ b/src/main/java/net/minestom/server/data/type/array/ByteArrayData.java @@ -3,15 +3,17 @@ package net.minestom.server.data.type.array; import net.minestom.server.data.DataType; import net.minestom.server.utils.binary.BinaryReader; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class ByteArrayData extends DataType { @Override - public void encode(BinaryWriter writer, byte[] value) { + public void encode(@NotNull BinaryWriter writer, @NotNull byte[] value) { encodeByteArray(writer, value); } + @NotNull @Override - public byte[] decode(BinaryReader reader) { + public byte[] decode(@NotNull BinaryReader reader) { return decodeByteArray(reader); } diff --git a/src/main/java/net/minestom/server/data/type/array/CharacterArrayData.java b/src/main/java/net/minestom/server/data/type/array/CharacterArrayData.java index 8e7e36097..4a69fc99f 100644 --- a/src/main/java/net/minestom/server/data/type/array/CharacterArrayData.java +++ b/src/main/java/net/minestom/server/data/type/array/CharacterArrayData.java @@ -3,18 +3,20 @@ package net.minestom.server.data.type.array; import net.minestom.server.data.DataType; import net.minestom.server.utils.binary.BinaryReader; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class CharacterArrayData extends DataType { @Override - public void encode(BinaryWriter writer, char[] value) { + public void encode(@NotNull BinaryWriter writer, @NotNull char[] value) { writer.writeVarInt(value.length); for (char val : value) { writer.writeChar(val); } } + @NotNull @Override - public char[] decode(BinaryReader reader) { + public char[] decode(@NotNull BinaryReader reader) { char[] array = new char[reader.readVarInt()]; for (int i = 0; i < array.length; i++) { array[i] = reader.readChar(); diff --git a/src/main/java/net/minestom/server/data/type/array/DoubleArrayData.java b/src/main/java/net/minestom/server/data/type/array/DoubleArrayData.java index 0182c2c87..e5131602f 100644 --- a/src/main/java/net/minestom/server/data/type/array/DoubleArrayData.java +++ b/src/main/java/net/minestom/server/data/type/array/DoubleArrayData.java @@ -3,19 +3,21 @@ package net.minestom.server.data.type.array; import net.minestom.server.data.DataType; import net.minestom.server.utils.binary.BinaryReader; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class DoubleArrayData extends DataType { @Override - public void encode(BinaryWriter writer, double[] value) { + public void encode(@NotNull BinaryWriter writer, @NotNull double[] value) { writer.writeVarInt(value.length); for (double val : value) { writer.writeDouble(val); } } + @NotNull @Override - public double[] decode(BinaryReader reader) { + public double[] decode(@NotNull BinaryReader reader) { double[] array = new double[reader.readVarInt()]; for (int i = 0; i < array.length; i++) { array[i] = reader.readDouble(); diff --git a/src/main/java/net/minestom/server/data/type/array/FloatArrayData.java b/src/main/java/net/minestom/server/data/type/array/FloatArrayData.java index 119ab001b..6a11fdd36 100644 --- a/src/main/java/net/minestom/server/data/type/array/FloatArrayData.java +++ b/src/main/java/net/minestom/server/data/type/array/FloatArrayData.java @@ -3,19 +3,21 @@ package net.minestom.server.data.type.array; import net.minestom.server.data.DataType; import net.minestom.server.utils.binary.BinaryReader; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class FloatArrayData extends DataType { @Override - public void encode(BinaryWriter writer, float[] value) { + public void encode(@NotNull BinaryWriter writer, @NotNull float[] value) { writer.writeVarInt(value.length); for (float val : value) { writer.writeFloat(val); } } + @NotNull @Override - public float[] decode(BinaryReader reader) { + public float[] decode(@NotNull BinaryReader reader) { float[] array = new float[reader.readVarInt()]; for (int i = 0; i < array.length; i++) { array[i] = reader.readFloat(); diff --git a/src/main/java/net/minestom/server/data/type/array/IntegerArrayData.java b/src/main/java/net/minestom/server/data/type/array/IntegerArrayData.java index eca283cf7..9f754d7ca 100644 --- a/src/main/java/net/minestom/server/data/type/array/IntegerArrayData.java +++ b/src/main/java/net/minestom/server/data/type/array/IntegerArrayData.java @@ -3,19 +3,21 @@ package net.minestom.server.data.type.array; import net.minestom.server.data.DataType; import net.minestom.server.utils.binary.BinaryReader; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class IntegerArrayData extends DataType { @Override - public void encode(BinaryWriter writer, int[] value) { + public void encode(@NotNull BinaryWriter writer, @NotNull int[] value) { writer.writeVarInt(value.length); for (int val : value) { writer.writeInt(val); } } + @NotNull @Override - public int[] decode(BinaryReader reader) { + public int[] decode(@NotNull BinaryReader reader) { int[] array = new int[reader.readVarInt()]; for (int i = 0; i < array.length; i++) { array[i] = reader.readInteger(); diff --git a/src/main/java/net/minestom/server/data/type/array/ItemStackArrayData.java b/src/main/java/net/minestom/server/data/type/array/ItemStackArrayData.java index e1baa8157..d88dd75a7 100644 --- a/src/main/java/net/minestom/server/data/type/array/ItemStackArrayData.java +++ b/src/main/java/net/minestom/server/data/type/array/ItemStackArrayData.java @@ -4,18 +4,20 @@ import net.minestom.server.data.DataType; import net.minestom.server.item.ItemStack; import net.minestom.server.utils.binary.BinaryReader; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class ItemStackArrayData extends DataType { @Override - public void encode(BinaryWriter writer, ItemStack[] value) { + public void encode(@NotNull BinaryWriter writer, @NotNull ItemStack[] value) { writer.writeVarInt(value.length); for (ItemStack itemStack : value) { writer.writeItemStack(itemStack); } } + @NotNull @Override - public ItemStack[] decode(BinaryReader reader) { + public ItemStack[] decode(@NotNull BinaryReader reader) { ItemStack[] items = new ItemStack[reader.readVarInt()]; for (int i = 0; i < items.length; i++) { items[i] = reader.readSlot(); diff --git a/src/main/java/net/minestom/server/data/type/array/LongArrayData.java b/src/main/java/net/minestom/server/data/type/array/LongArrayData.java index 486847dbd..cb7e9df54 100644 --- a/src/main/java/net/minestom/server/data/type/array/LongArrayData.java +++ b/src/main/java/net/minestom/server/data/type/array/LongArrayData.java @@ -3,19 +3,21 @@ package net.minestom.server.data.type.array; import net.minestom.server.data.DataType; import net.minestom.server.utils.binary.BinaryReader; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class LongArrayData extends DataType { @Override - public void encode(BinaryWriter writer, long[] value) { + public void encode(@NotNull BinaryWriter writer, @NotNull long[] value) { writer.writeVarInt(value.length); for (long val : value) { writer.writeLong(val); } } + @NotNull @Override - public long[] decode(BinaryReader reader) { + public long[] decode(@NotNull BinaryReader reader) { long[] array = new long[reader.readVarInt()]; for (int i = 0; i < array.length; i++) { array[i] = reader.readLong(); diff --git a/src/main/java/net/minestom/server/data/type/array/ShortArrayData.java b/src/main/java/net/minestom/server/data/type/array/ShortArrayData.java index 51835f463..c133a1478 100644 --- a/src/main/java/net/minestom/server/data/type/array/ShortArrayData.java +++ b/src/main/java/net/minestom/server/data/type/array/ShortArrayData.java @@ -3,19 +3,21 @@ package net.minestom.server.data.type.array; import net.minestom.server.data.DataType; import net.minestom.server.utils.binary.BinaryReader; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class ShortArrayData extends DataType { @Override - public void encode(BinaryWriter writer, short[] value) { + public void encode(@NotNull BinaryWriter writer, @NotNull short[] value) { writer.writeVarInt(value.length); for (short val : value) { writer.writeShort(val); } } + @NotNull @Override - public short[] decode(BinaryReader reader) { + public short[] decode(@NotNull BinaryReader reader) { short[] array = new short[reader.readVarInt()]; for (int i = 0; i < array.length; i++) { array[i] = reader.readShort(); diff --git a/src/main/java/net/minestom/server/data/type/array/StringArrayData.java b/src/main/java/net/minestom/server/data/type/array/StringArrayData.java index d37fc4b19..cbdde7ab1 100644 --- a/src/main/java/net/minestom/server/data/type/array/StringArrayData.java +++ b/src/main/java/net/minestom/server/data/type/array/StringArrayData.java @@ -3,19 +3,21 @@ package net.minestom.server.data.type.array; import net.minestom.server.data.DataType; import net.minestom.server.utils.binary.BinaryReader; import net.minestom.server.utils.binary.BinaryWriter; +import org.jetbrains.annotations.NotNull; public class StringArrayData extends DataType { @Override - public void encode(BinaryWriter writer, String[] value) { + public void encode(@NotNull BinaryWriter writer, @NotNull String[] value) { writer.writeVarInt(value.length); for (String val : value) { writer.writeSizedString(val); } } + @NotNull @Override - public String[] decode(BinaryReader reader) { + public String[] decode(@NotNull BinaryReader reader) { String[] array = new String[reader.readVarInt()]; for (int i = 0; i < array.length; i++) { array[i] = reader.readSizedString(); diff --git a/src/main/java/net/minestom/server/entity/ItemEntity.java b/src/main/java/net/minestom/server/entity/ItemEntity.java index bd86edf18..f9ecb43b0 100644 --- a/src/main/java/net/minestom/server/entity/ItemEntity.java +++ b/src/main/java/net/minestom/server/entity/ItemEntity.java @@ -39,7 +39,7 @@ public class ItemEntity extends ObjectEntity { private long spawnTime; private long pickupDelay; - public ItemEntity(ItemStack itemStack, Position spawnPosition) { + public ItemEntity(@NotNull ItemStack itemStack, @NotNull Position spawnPosition) { super(EntityType.ITEM, spawnPosition); this.itemStack = itemStack; setBoundingBox(0.25f, 0.25f, 0.25f); diff --git a/src/main/java/net/minestom/server/entity/LivingEntity.java b/src/main/java/net/minestom/server/entity/LivingEntity.java index 63ba2bbf8..1555f024b 100644 --- a/src/main/java/net/minestom/server/entity/LivingEntity.java +++ b/src/main/java/net/minestom/server/entity/LivingEntity.java @@ -22,6 +22,7 @@ import net.minestom.server.utils.binary.BinaryWriter; import net.minestom.server.utils.time.TimeUnit; import net.minestom.server.utils.validate.Check; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Set; import java.util.function.Consumer; @@ -65,13 +66,13 @@ public abstract class LivingEntity extends Entity implements EquipmentHandler { private Team team; - public LivingEntity(EntityType entityType, Position spawnPosition) { + public LivingEntity(@NotNull EntityType entityType, @NotNull Position spawnPosition) { super(entityType, spawnPosition); setupAttributes(); setGravity(0.02f); } - public LivingEntity(EntityType entityType) { + public LivingEntity(@NotNull EntityType entityType) { this(entityType, new Position()); } @@ -255,8 +256,8 @@ public abstract class LivingEntity extends Entity implements EquipmentHandler { * @param value the amount of damage * @return true if damage has been applied, false if it didn't */ - public boolean damage(DamageType type, float value) { - Check.notNull(type, "The damage type cannot be null!o"); + public boolean damage(@NotNull DamageType type, float value) { + Check.notNull(type, "The damage type cannot be null!"); if (isDead()) return false; if (isInvulnerable() || isImmune(type)) { @@ -318,7 +319,7 @@ public abstract class LivingEntity extends Entity implements EquipmentHandler { * @param type the type of damage * @return true if this entity is immune to the given type of damage */ - public boolean isImmune(DamageType type) { + public boolean isImmune(@NotNull DamageType type) { return false; } @@ -351,6 +352,7 @@ public abstract class LivingEntity extends Entity implements EquipmentHandler { * * @return the last damage source, null if not any */ + @Nullable public DamageType getLastDamageSource() { return lastDamageSource; } @@ -379,7 +381,7 @@ public abstract class LivingEntity extends Entity implements EquipmentHandler { * @param attribute The attribute to change * @param value the new value of the attribute */ - public void setAttribute(Attribute attribute, float value) { + public void setAttribute(@NotNull Attribute attribute, float value) { this.attributeValues[attribute.ordinal()] = value; } @@ -389,7 +391,7 @@ public abstract class LivingEntity extends Entity implements EquipmentHandler { * @param attribute the attribute value to get * @return the attribute value */ - public float getAttributeValue(Attribute attribute) { + public float getAttributeValue(@NotNull Attribute attribute) { return this.attributeValues[attribute.ordinal()]; } @@ -470,6 +472,7 @@ public abstract class LivingEntity extends Entity implements EquipmentHandler { * * @return an {@link EntityPropertiesPacket} linked to this entity */ + @NotNull protected EntityPropertiesPacket getPropertiesPacket() { EntityPropertiesPacket propertiesPacket = new EntityPropertiesPacket(); propertiesPacket.entityId = getEntityId(); @@ -525,7 +528,7 @@ public abstract class LivingEntity extends Entity implements EquipmentHandler { * @param fireDamagePeriod the delay * @param timeUnit the time unit */ - public void setFireDamagePeriod(long fireDamagePeriod, TimeUnit timeUnit) { + public void setFireDamagePeriod(long fireDamagePeriod, @NotNull TimeUnit timeUnit) { fireDamagePeriod = timeUnit.toMilliseconds(fireDamagePeriod); this.fireDamagePeriod = fireDamagePeriod; } diff --git a/src/main/java/net/minestom/server/entity/ObjectEntity.java b/src/main/java/net/minestom/server/entity/ObjectEntity.java index 0e8273ec3..7f0459273 100644 --- a/src/main/java/net/minestom/server/entity/ObjectEntity.java +++ b/src/main/java/net/minestom/server/entity/ObjectEntity.java @@ -7,7 +7,7 @@ import org.jetbrains.annotations.NotNull; public abstract class ObjectEntity extends Entity { - public ObjectEntity(EntityType entityType, Position spawnPosition) { + public ObjectEntity(@NotNull EntityType entityType, @NotNull Position spawnPosition) { super(entityType, spawnPosition); setGravity(0.02f); } diff --git a/src/main/java/net/minestom/server/entity/Player.java b/src/main/java/net/minestom/server/entity/Player.java index b8dc36068..de46e73f7 100644 --- a/src/main/java/net/minestom/server/entity/Player.java +++ b/src/main/java/net/minestom/server/entity/Player.java @@ -280,7 +280,7 @@ public class Player extends LivingEntity implements CommandSender { } @Override - public float getAttributeValue(Attribute attribute) { + public float getAttributeValue(@NotNull Attribute attribute) { if (attribute == Attribute.MOVEMENT_SPEED) { return walkingSpeed; } @@ -679,6 +679,7 @@ public class Player extends LivingEntity implements CommandSender { sendMessage(ColoredText.of(message)); } + @NotNull @Override public Collection getAllPermissions() { return permissions; @@ -775,10 +776,10 @@ public class Player extends LivingEntity implements CommandSender { /** * Sets the header and footer of a player which will be displayed in his tab window. * - * @param header the header text - * @param footer the footer text + * @param header the header text, null to set empty + * @param footer the footer text, null to set empty */ - public void sendHeaderFooter(@NotNull ColoredText header, @NotNull ColoredText footer) { + public void sendHeaderFooter(@Nullable ColoredText header, @Nullable ColoredText footer) { PlayerListHeaderAndFooterPacket playerListHeaderAndFooterPacket = new PlayerListHeaderAndFooterPacket(); playerListHeaderAndFooterPacket.emptyHeader = header == null; playerListHeaderAndFooterPacket.emptyFooter = footer == null; @@ -1624,7 +1625,7 @@ public class Player extends LivingEntity implements CommandSender { Inventory newInventory = inventoryOpenEvent.getInventory(); - if(newInventory == null){ + if (newInventory == null) { // just close the inventory return; } diff --git a/src/main/java/net/minestom/server/entity/damage/DamageType.java b/src/main/java/net/minestom/server/entity/damage/DamageType.java index f46ef2616..563ac9310 100644 --- a/src/main/java/net/minestom/server/entity/damage/DamageType.java +++ b/src/main/java/net/minestom/server/entity/damage/DamageType.java @@ -9,6 +9,8 @@ import net.minestom.server.entity.Entity; import net.minestom.server.entity.LivingEntity; import net.minestom.server.entity.Player; import net.minestom.server.sound.Sound; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * Represents a type of damage, required when calling {@link LivingEntity#damage(DamageType, float)} @@ -24,7 +26,7 @@ public class DamageType implements DataContainer { public static final DamageType GRAVITY = new DamageType("attack.fall"); public static final DamageType ON_FIRE = new DamageType("attack.onFire") { @Override - protected Sound getPlayerSound(Player player) { + protected Sound getPlayerSound(@NotNull Player player) { return Sound.ENTITY_PLAYER_HURT_ON_FIRE; } }; @@ -37,7 +39,7 @@ public class DamageType implements DataContainer { * @param identifier the identifier of this damage type, * does not need to be unique */ - public DamageType(String identifier) { + public DamageType(@NotNull String identifier) { this.identifier = identifier; } @@ -48,6 +50,7 @@ public class DamageType implements DataContainer { * * @return the damage type identifier */ + @NotNull public String getIdentifier() { return identifier; } @@ -61,7 +64,8 @@ public class DamageType implements DataContainer { * @return the death message, null to do not send anything. * Can be for instance, of type {@link ColoredText} or {@link RichMessage}. */ - public JsonMessage buildDeathMessage(Player killed) { + @NotNull + public JsonMessage buildDeathMessage(@NotNull Player killed) { return ColoredText.of("{@death." + identifier + "," + killed.getUsername() + "}"); } @@ -72,7 +76,8 @@ public class DamageType implements DataContainer { * @param projectile the actual projectile * @return a new {@link EntityProjectileDamage} */ - public static DamageType fromProjectile(Entity shooter, Entity projectile) { + @NotNull + public static DamageType fromProjectile(@Nullable Entity shooter, @NotNull Entity projectile) { return new EntityProjectileDamage(shooter, projectile); } @@ -82,7 +87,8 @@ public class DamageType implements DataContainer { * @param player the player damager * @return a new {@link EntityDamage} */ - public static EntityDamage fromPlayer(Player player) { + @NotNull + public static EntityDamage fromPlayer(@NotNull Player player) { return new EntityDamage(player); } @@ -92,7 +98,8 @@ public class DamageType implements DataContainer { * @param entity the entity damager * @return a new {@link EntityDamage} */ - public static EntityDamage fromEntity(Entity entity) { + @NotNull + public static EntityDamage fromEntity(@NotNull Entity entity) { return new EntityDamage(entity); } @@ -102,7 +109,8 @@ public class DamageType implements DataContainer { * @param killed the player who has been killed * @return the death screen text, null to do not send anything */ - public ColoredText buildDeathScreenText(Player killed) { + @NotNull + public ColoredText buildDeathScreenText(@NotNull Player killed) { return ColoredText.of("{@death." + identifier + "}"); } @@ -112,18 +120,19 @@ public class DamageType implements DataContainer { * @param entity the entity hit by this damage * @return the sound to play when the given entity is hurt by this damage type. Can be null if no sound should play */ - public Sound getSound(LivingEntity entity) { + @Nullable + public Sound getSound(@NotNull LivingEntity entity) { if (entity instanceof Player) { return getPlayerSound((Player) entity); } return getGenericSound(entity); } - protected Sound getGenericSound(LivingEntity entity) { + protected Sound getGenericSound(@NotNull LivingEntity entity) { return Sound.ENTITY_GENERIC_HURT; } - protected Sound getPlayerSound(Player player) { + protected Sound getPlayerSound(@NotNull Player player) { return Sound.ENTITY_PLAYER_HURT; } diff --git a/src/main/java/net/minestom/server/entity/damage/EntityDamage.java b/src/main/java/net/minestom/server/entity/damage/EntityDamage.java index 4e00d0521..ff6bd2979 100644 --- a/src/main/java/net/minestom/server/entity/damage/EntityDamage.java +++ b/src/main/java/net/minestom/server/entity/damage/EntityDamage.java @@ -1,6 +1,7 @@ package net.minestom.server.entity.damage; import net.minestom.server.entity.Entity; +import org.jetbrains.annotations.NotNull; /** * Represents damage inflicted by an {@link Entity}. @@ -9,7 +10,7 @@ public class EntityDamage extends DamageType { private final Entity source; - public EntityDamage(Entity source) { + public EntityDamage(@NotNull Entity source) { super("entity_source"); this.source = source; } @@ -19,6 +20,7 @@ public class EntityDamage extends DamageType { * * @return the source */ + @NotNull public Entity getSource() { return source; } diff --git a/src/main/java/net/minestom/server/entity/damage/EntityProjectileDamage.java b/src/main/java/net/minestom/server/entity/damage/EntityProjectileDamage.java index 610f9f829..e7d6f5de9 100644 --- a/src/main/java/net/minestom/server/entity/damage/EntityProjectileDamage.java +++ b/src/main/java/net/minestom/server/entity/damage/EntityProjectileDamage.java @@ -1,6 +1,8 @@ package net.minestom.server.entity.damage; import net.minestom.server.entity.Entity; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * Represents damage inflicted by an entity, via a projectile. @@ -10,7 +12,7 @@ public class EntityProjectileDamage extends DamageType { private final Entity shooter; private final Entity projectile; - public EntityProjectileDamage(Entity shooter, Entity projectile) { + public EntityProjectileDamage(@Nullable Entity shooter, @NotNull Entity projectile) { super("projectile_source"); this.shooter = shooter; this.projectile = projectile; @@ -21,6 +23,7 @@ public class EntityProjectileDamage extends DamageType { * * @return the projectile */ + @NotNull public Entity getProjectile() { return projectile; } @@ -30,6 +33,7 @@ public class EntityProjectileDamage extends DamageType { * * @return the shooter of the projectile, null if not any */ + @Nullable public Entity getShooter() { return shooter; } diff --git a/src/main/java/net/minestom/server/entity/fakeplayer/FakePlayer.java b/src/main/java/net/minestom/server/entity/fakeplayer/FakePlayer.java index d6f530c1d..3fe4e6f57 100644 --- a/src/main/java/net/minestom/server/entity/fakeplayer/FakePlayer.java +++ b/src/main/java/net/minestom/server/entity/fakeplayer/FakePlayer.java @@ -6,6 +6,7 @@ import net.minestom.server.event.player.PlayerLoginEvent; import net.minestom.server.network.player.FakePlayerConnection; import net.minestom.server.network.player.PlayerConnection; import net.minestom.server.utils.time.TimeUnit; +import org.jetbrains.annotations.NotNull; import java.util.UUID; import java.util.function.Consumer; @@ -15,7 +16,7 @@ public class FakePlayer extends Player { private final FakePlayerOption option; private final FakePlayerController fakePlayerController; - private FakePlayer(UUID uuid, String username, FakePlayerOption option) { + private FakePlayer(@NotNull UUID uuid, @NotNull String username, @NotNull FakePlayerOption option) { super(uuid, username, new FakePlayerConnection()); this.option = option; @@ -37,7 +38,8 @@ public class FakePlayer extends Player { * WARNING: it will be called in the * {@link net.minestom.server.timer.SchedulerManager} thread pool */ - public static void initPlayer(UUID uuid, String username, FakePlayerOption option, Consumer scheduledCallback) { + public static void initPlayer(@NotNull UUID uuid, @NotNull String username, + @NotNull FakePlayerOption option, @NotNull Consumer scheduledCallback) { final FakePlayer fakePlayer = new FakePlayer(uuid, username, option); fakePlayer.addEventCallback(PlayerLoginEvent.class, event -> MinecraftServer.getSchedulerManager().buildTask(() -> scheduledCallback.accept(fakePlayer)).delay(1, TimeUnit.TICK).schedule()); @@ -52,7 +54,7 @@ public class FakePlayer extends Player { * WARNING: it will be called in the * {@link net.minestom.server.timer.SchedulerManager} thread pool */ - public static void initPlayer(UUID uuid, String username, Consumer scheduledCallback) { + public static void initPlayer(@NotNull UUID uuid, @NotNull String username, @NotNull Consumer scheduledCallback) { initPlayer(uuid, username, new FakePlayerOption(), scheduledCallback); } @@ -61,16 +63,18 @@ public class FakePlayer extends Player { * * @return the fake player option */ + @NotNull public FakePlayerOption getOption() { return option; } + @NotNull public FakePlayerController getController() { return fakePlayerController; } @Override - protected void showPlayer(PlayerConnection connection) { + protected void showPlayer(@NotNull PlayerConnection connection) { super.showPlayer(connection); if (!option.isInTabList()) { // Remove from tab-list