SPIGOT-2540: Add nullability annotations to entire Bukkit API

By: Darkyenus <darkyenus@gmail.com>
This commit is contained in:
Bukkit/Spigot
2019-03-13 17:42:57 +11:00
parent e069a80fd8
commit 416c865476
565 changed files with 5372 additions and 2008 deletions

View File

@@ -15,12 +15,14 @@ import org.bukkit.Server;
import org.bukkit.command.defaults.*;
import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class SimpleCommandMap implements CommandMap {
protected final Map<String, Command> knownCommands = new HashMap<String, Command>();
private final Server server;
public SimpleCommandMap(final Server server) {
public SimpleCommandMap(@NotNull final Server server) {
this.server = server;
setDefaultCommands();
}
@@ -39,7 +41,7 @@ public class SimpleCommandMap implements CommandMap {
/**
* {@inheritDoc}
*/
public void registerAll(String fallbackPrefix, List<Command> commands) {
public void registerAll(@NotNull String fallbackPrefix, @NotNull List<Command> commands) {
if (commands != null) {
for (Command c : commands) {
register(fallbackPrefix, c);
@@ -50,14 +52,14 @@ public class SimpleCommandMap implements CommandMap {
/**
* {@inheritDoc}
*/
public boolean register(String fallbackPrefix, Command command) {
public boolean register(@NotNull String fallbackPrefix, @NotNull Command command) {
return register(command.getName(), fallbackPrefix, command);
}
/**
* {@inheritDoc}
*/
public boolean register(String label, String fallbackPrefix, Command command) {
public boolean register(@NotNull String label, @NotNull String fallbackPrefix, @NotNull Command command) {
label = label.toLowerCase(java.util.Locale.ENGLISH).trim();
fallbackPrefix = fallbackPrefix.toLowerCase(java.util.Locale.ENGLISH).trim();
boolean registered = register(label, command, false, fallbackPrefix);
@@ -91,7 +93,7 @@ public class SimpleCommandMap implements CommandMap {
* unique address
* @return true if command was registered, false otherwise.
*/
private synchronized boolean register(String label, Command command, boolean isAlias, String fallbackPrefix) {
private synchronized boolean register(@NotNull String label, @NotNull Command command, boolean isAlias, @NotNull String fallbackPrefix) {
knownCommands.put(fallbackPrefix + ":" + label, command);
if ((command instanceof BukkitCommand || isAlias) && knownCommands.containsKey(label)) {
// Request is for an alias/fallback command and it conflicts with
@@ -119,7 +121,7 @@ public class SimpleCommandMap implements CommandMap {
/**
* {@inheritDoc}
*/
public boolean dispatch(CommandSender sender, String commandLine) throws CommandException {
public boolean dispatch(@NotNull CommandSender sender, @NotNull String commandLine) throws CommandException {
String[] args = commandLine.split(" ");
if (args.length == 0) {
@@ -154,16 +156,19 @@ public class SimpleCommandMap implements CommandMap {
setDefaultCommands();
}
public Command getCommand(String name) {
@Nullable
public Command getCommand(@NotNull String name) {
Command target = knownCommands.get(name.toLowerCase(java.util.Locale.ENGLISH));
return target;
}
public List<String> tabComplete(CommandSender sender, String cmdLine) {
@Nullable
public List<String> tabComplete(@NotNull CommandSender sender, @NotNull String cmdLine) {
return tabComplete(sender, cmdLine, null);
}
public List<String> tabComplete(CommandSender sender, String cmdLine, Location location) {
@Nullable
public List<String> tabComplete(@NotNull CommandSender sender, @NotNull String cmdLine, @Nullable Location location) {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(cmdLine, "Command line cannot null");
@@ -215,6 +220,7 @@ public class SimpleCommandMap implements CommandMap {
}
}
@NotNull
public Collection<Command> getCommands() {
return Collections.unmodifiableCollection(knownCommands.values());
}