Annotations for data & command

This commit is contained in:
themode 2020-10-24 16:58:27 +02:00
parent 27e0b86cb5
commit cb28fdc208
72 changed files with 454 additions and 266 deletions

View File

@ -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<AdvancementTab> getTabs(Player player) {
@NotNull
public static Set<AdvancementTab> 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<AdvancementTab> 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;
}

View File

@ -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;

View File

@ -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<DeclareCommandsPacket.Node> 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<DeclareCommandsPacket.Node> nodes, IntList cmdChildren, String name, Collection<CommandSyntax> syntaxes, IntList rootChildren) {
private void createCommand(@NotNull List<DeclareCommandsPacket.Node> nodes,
@NotNull IntList cmdChildren,
@NotNull String name,
@NotNull Collection<CommandSyntax> 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<DeclareCommandsPacket.Node> toNodes(Argument<?> argument, boolean executable) {
@NotNull
private List<DeclareCommandsPacket.Node> toNodes(@NotNull Argument<?> argument, boolean executable) {
List<DeclareCommandsPacket.Node> 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<? extends Number> argumentNumber) {
private byte getNumberProperties(@NotNull ArgumentNumber<? extends Number> 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<DeclareCommandsPacket.Node> nodes,
Argument<?> argument, boolean executable, boolean suggestion) {
@NotNull
private DeclareCommandsPacket.Node simpleArgumentNode(@NotNull List<DeclareCommandsPacket.Node> 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) {

View File

@ -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;
}
}

View File

@ -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<Permission> 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<? extends Permission> permissionClass) {
default boolean hasPermission(@NotNull Class<? extends Permission> permissionClass) {
boolean result = true;
boolean foundPerm = false;
for (Permission p : getAllPermissions()) {

View File

@ -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<Permission> permissions = new LinkedList<>();
@Override
public void sendMessage(String message) {
public void sendMessage(@NotNull String message) {
System.out.println(message);
}
@NotNull
@Override
public Collection<Permission> getAllPermissions() {
return permissions;

View File

@ -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);
}

View File

@ -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<String, Object> 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<Entity> getEntities(String id) {
public List<Entity> getEntities(@NotNull String id) {
return (List<Entity>) 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);
}

View File

@ -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<CommandSyntax> 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) {
}
}

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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<T> {
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<T> {
* @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<T> {
* @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<T> {
* @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<T> {
*
* @return the argument id
*/
@NotNull
public String getId() {
return id;
}
@ -101,6 +105,7 @@ public abstract class Argument<T> {
*
* @return the argument callback
*/
@Nullable
public ArgumentCallback getCallback() {
return callback;
}
@ -110,7 +115,7 @@ public abstract class Argument<T> {
*
* @param callback the argument callback
*/
public void setCallback(ArgumentCallback callback) {
public void setCallback(@Nullable ArgumentCallback callback) {
this.callback = callback;
}

View File

@ -1,5 +1,7 @@
package net.minestom.server.command.builder.arguments;
import org.jetbrains.annotations.NotNull;
/**
* Represents a boolean value.
* <p>
@ -14,18 +16,19 @@ public class ArgumentBoolean extends Argument<Boolean> {
}
@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;
}

View File

@ -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<String[]> {
}
@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;
}
}

View File

@ -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<String> {
}
@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;
}
}

View File

@ -1,5 +1,7 @@
package net.minestom.server.command.builder.arguments;
import org.jetbrains.annotations.NotNull;
/**
* Argument which will take a quoted string.
* <p>
@ -14,7 +16,7 @@ public class ArgumentString extends Argument<String> {
}
@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<String> {
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<String> {
}
@Override
public int getConditionResult(String value) {
public int getConditionResult(@NotNull String value) {
return SUCCESS;
}
}

View File

@ -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<String[]> {
}
@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;
}
}

View File

@ -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);
}

View File

@ -1,5 +1,7 @@
package net.minestom.server.command.builder.arguments;
import org.jetbrains.annotations.NotNull;
/**
* Represents a single word in the command.
* <p>
@ -24,20 +26,21 @@ public class ArgumentWord extends Argument<String> {
}
@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) {

View File

@ -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<ChatColor> {
}
@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;
}
}

View File

@ -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<ArrayList<Entity>> {
}
@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<ArrayList<Entity>> {
return finalIndex;
}
@NotNull
@Override
public ArrayList<Entity> parse(String value) {
public ArrayList<Entity> parse(@NotNull String value) {
return null;
}
@Override
public int getConditionResult(ArrayList<Entity> value) {
public int getConditionResult(@NotNull ArrayList<Entity> value) {
return SUCCESS;
}

View File

@ -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<FloatRange> {
}
@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<FloatRange> {
}
}
@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(".."));

View File

@ -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<IntRange> {
}
@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<IntRange> {
}
}
@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(".."));

View File

@ -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<ItemStack> {
}
@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<ItemStack> {
}
}
@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<ItemStack> {
}
@Override
public int getConditionResult(ItemStack value) {
public int getConditionResult(@NotNull ItemStack value) {
return SUCCESS;
}
}

View File

@ -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<NBTCompound> {
}
@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<NBTCompound> {
}
}
@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<NBTCompound> {
}
@Override
public int getConditionResult(NBTCompound value) {
public int getConditionResult(@NotNull NBTCompound value) {
return SUCCESS;
}
}

View File

@ -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<NBT> {
}
@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<NBT> {
}
}
@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<NBT> {
}
@Override
public int getConditionResult(NBT value) {
public int getConditionResult(@NotNull NBT value) {
return SUCCESS;
}
}

View File

@ -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<T> extends Argument<T> {
}
@Override
public int getConditionResult(T value) {
public int getConditionResult(@NotNull T value) {
return SUCCESS;
}
}

View File

@ -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<UpdateOption> {
}
@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<UpdateOption> {
}
}
@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<UpdateOption> {
}
@Override
public int getConditionResult(UpdateOption value) {
public int getConditionResult(@NotNull UpdateOption value) {
return SUCCESS;
}
}

View File

@ -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<T> extends Argument<T> {
@ -13,17 +14,18 @@ public abstract class ArgumentRegistry<T> extends Argument<T> {
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;
}
}

View File

@ -1,5 +1,7 @@
package net.minestom.server.command.builder.arguments.number;
import org.jetbrains.annotations.NotNull;
public class ArgumentDouble extends ArgumentNumber<Double> {
public ArgumentDouble(String id) {
@ -9,7 +11,7 @@ public class ArgumentDouble extends ArgumentNumber<Double> {
}
@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<Double> {
}
}
@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<Double> {
}
@Override
public int getConditionResult(Double value) {
public int getConditionResult(@NotNull Double value) {
// Check range
if (hasMin && value < min) {
return RANGE_ERROR;

View File

@ -1,5 +1,7 @@
package net.minestom.server.command.builder.arguments.number;
import org.jetbrains.annotations.NotNull;
public class ArgumentFloat extends ArgumentNumber<Float> {
public ArgumentFloat(String id) {
@ -9,7 +11,7 @@ public class ArgumentFloat extends ArgumentNumber<Float> {
}
@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<Float> {
}
}
@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<Float> {
}
@Override
public int getConditionResult(Float value) {
public int getConditionResult(@NotNull Float value) {
// Check range
if (hasMin && value < min) {
return RANGE_ERROR;

View File

@ -1,5 +1,7 @@
package net.minestom.server.command.builder.arguments.number;
import org.jetbrains.annotations.NotNull;
public class ArgumentInteger extends ArgumentNumber<Integer> {
public ArgumentInteger(String id) {
@ -9,7 +11,7 @@ public class ArgumentInteger extends ArgumentNumber<Integer> {
}
@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<Integer> {
}
}
@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;

View File

@ -1,5 +1,7 @@
package net.minestom.server.command.builder.arguments.number;
import org.jetbrains.annotations.NotNull;
public class ArgumentLong extends ArgumentNumber<Long> {
public ArgumentLong(String id) {
@ -9,7 +11,7 @@ public class ArgumentLong extends ArgumentNumber<Long> {
}
@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<Long> {
}
}
@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;

View File

@ -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<T extends Number> extends Argument<T> {
super(id, false);
}
public ArgumentNumber<T> min(T value) {
@NotNull
public ArgumentNumber<T> min(@NotNull T value) {
this.min = value;
this.hasMin = true;
return this;
}
public ArgumentNumber<T> max(T value) {
@NotNull
public ArgumentNumber<T> max(@NotNull T value) {
this.max = value;
this.hasMax = true;
return this;
}
public ArgumentNumber<T> between(T min, T max) {
@NotNull
public ArgumentNumber<T> between(@NotNull T min, @NotNull T max) {
this.min = min;
this.max = max;
this.hasMin = true;
@ -52,6 +57,7 @@ public abstract class ArgumentNumber<T extends Number> extends Argument<T> {
*
* @return the minimum of this argument
*/
@NotNull
public T getMin() {
return min;
}
@ -70,11 +76,12 @@ public abstract class ArgumentNumber<T extends Number> extends Argument<T> {
*
* @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<T extends Number> extends Argument<T> {
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<T extends Number> extends Argument<T> {
return 10;
}
protected String removeScientificNotation(String value) {
@Nullable
protected String removeScientificNotation(@NotNull String value) {
try {
return new BigDecimal(value).toPlainString();
} catch (NumberFormatException e) {

View File

@ -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);
}

View File

@ -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> T getOrDefault(@NotNull String key, T defaultValue);
<T> 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();
}

View File

@ -44,6 +44,7 @@ public class DataImpl implements Data {
return data.isEmpty();
}
@NotNull
@Override
public Data clone() {
DataImpl data = new DataImpl();

View File

@ -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 <T> the data type
* @throws IllegalStateException if the type {@code clazz} is already registered
*/
public <T> void registerType(Class<T> clazz, DataType<T> dataType) {
public <T> void registerType(@NotNull Class<T> clazz, @NotNull DataType<T> 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 <T> DataType<T> getDataType(Class<T> clazz) {
@Nullable
public <T> DataType<T> getDataType(@NotNull Class<T> clazz) {
clazz = PrimitiveConversion.getObjectClass(clazz);
return dataTypeMap.get(clazz);
}

View File

@ -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<T> {
/**
* 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);
}

View File

@ -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.
* <p>
* 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<String> typeToIndexMap, boolean indexed);
@NotNull
byte[] getSerializedData(@NotNull Object2ShortMap<String> 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.
* <p>
* 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<String> typeToIndexMap);
void readSerializedData(@NotNull BinaryReader reader, @NotNull Object2ShortMap<String> typeToIndexMap);
/**
* Serialize the data into an array of bytes
* Serializes the data into an array of bytes.
* <p>
* Use {@link #readIndexedSerializedData(BinaryReader)}
* to convert it back to a {@link SerializableData}
* to convert it back to a {@link SerializableData}.
* <p>
* 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<String> typeToIndexMap = SerializableData.readDataIndexes(reader);
readSerializedData(reader, typeToIndexMap);
}
/**
* Write the index info (class name -&gt; class index), used to write the header for indexed serialized data
* Writes the index info (class name -&gt; class index), used to write the header for indexed serialized data.
* <p>
* Sized by a var-int
* Sized by a var-int.
*
* @param typeToIndexMap the data index map
*/
static void writeDataIndexHeader(BinaryWriter indexWriter, Object2ShortMap<String> typeToIndexMap) {
static void writeDataIndexHeader(@NotNull BinaryWriter indexWriter, @NotNull Object2ShortMap<String> 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 -&gt; type index)
* Reads a data index map (type name -&gt; type index).
* <p>
* 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<String> readDataIndexes(BinaryReader binaryReader) {
@NotNull
static Object2ShortMap<String> readDataIndexes(@NotNull BinaryReader binaryReader) {
Object2ShortMap<String> typeToIndexMap = new Object2ShortOpenHashMap<>();
{
final int dataIndexSize = binaryReader.readVarInt();

View File

@ -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<String> typeToIndexMap, boolean indexed) {
public byte[] getSerializedData(@NotNull Object2ShortMap<String> 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<String> typeToIndexMap) {
public void readSerializedData(@NotNull BinaryReader reader, @NotNull Object2ShortMap<String> typeToIndexMap) {
// Map used to convert an index to the class name (opposite of typeToIndexMap)
final Short2ObjectMap<String> indexToTypeMap = new Short2ObjectOpenHashMap<>(typeToIndexMap.size());
{

View File

@ -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<Boolean> {
@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();
}
}

View File

@ -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<Byte> {
@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();
}
}

View File

@ -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<Character> {
@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();
}
}

View File

@ -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<Double> {
@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();
}
}

View File

@ -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<Float> {
@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();
}
}

View File

@ -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<Integer> {
@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();
}
}

View File

@ -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<Inventory> {
@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<Inventory> {
}
}
@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();

View File

@ -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<ItemStack> {
@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();
}
}

View File

@ -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<Long> {
@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();
}
}

View File

@ -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<SerializableData> {
@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;

View File

@ -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<Short> {
@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();
}
}

View File

@ -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<String> {
@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();
}
}

View File

@ -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<UUID> {
@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();
}
}

View File

@ -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<boolean[]> {
@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();

View File

@ -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<byte[]> {
@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);
}

View File

@ -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<char[]> {
@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();

View File

@ -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<double[]> {
@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();

View File

@ -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<float[]> {
@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();

View File

@ -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<int[]> {
@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();

View File

@ -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<ItemStack[]> {
@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();

View File

@ -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<long[]> {
@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();

View File

@ -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<short[]> {
@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();

View File

@ -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<String[]> {
@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();

View File

@ -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);

View File

@ -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;
}

View File

@ -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);
}

View File

@ -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<Permission> 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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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<FakePlayer> scheduledCallback) {
public static void initPlayer(@NotNull UUID uuid, @NotNull String username,
@NotNull FakePlayerOption option, @NotNull Consumer<FakePlayer> 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<FakePlayer> scheduledCallback) {
public static void initPlayer(@NotNull UUID uuid, @NotNull String username, @NotNull Consumer<FakePlayer> 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