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
@@ -3,13 +3,14 @@ package org.bukkit.command.defaults;
import java.util.List;
import org.bukkit.command.Command;
import org.jetbrains.annotations.NotNull;
public abstract class BukkitCommand extends Command {
protected BukkitCommand(String name) {
protected BukkitCommand(@NotNull String name) {
super(name);
}
protected BukkitCommand(String name, String description, String usageMessage, List<String> aliases) {
protected BukkitCommand(@NotNull String name, @NotNull String description, @NotNull String usageMessage, @NotNull List<String> aliases) {
super(name, description, usageMessage, aliases);
}
}
@@ -23,6 +23,8 @@ import org.bukkit.help.IndexHelpTopic;
import org.bukkit.util.ChatPaginator;
import com.google.common.collect.ImmutableList;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class HelpCommand extends BukkitCommand {
public HelpCommand() {
@@ -34,7 +36,7 @@ public class HelpCommand extends BukkitCommand {
}
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
public boolean execute(@NotNull CommandSender sender, @NotNull String currentAlias, @NotNull String[] args) {
if (!testPermission(sender)) return true;
String command;
@@ -111,8 +113,9 @@ public class HelpCommand extends BukkitCommand {
return true;
}
@NotNull
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) {
public List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
@@ -132,7 +135,8 @@ public class HelpCommand extends BukkitCommand {
return ImmutableList.of();
}
protected HelpTopic findPossibleMatches(String searchString) {
@Nullable
protected HelpTopic findPossibleMatches(@NotNull String searchString) {
int maxDistance = (searchString.length() / 5) + 3;
Set<HelpTopic> possibleMatches = new TreeSet<HelpTopic>(HelpTopicComparator.helpTopicComparatorInstance());
@@ -172,7 +176,7 @@ public class HelpCommand extends BukkitCommand {
* @return The number of substitutions, deletions, insertions, and
* transpositions required to get from s1 to s2.
*/
protected static int damerauLevenshteinDistance(String s1, String s2) {
protected static int damerauLevenshteinDistance(@Nullable String s1, @Nullable String s2) {
if (s1 == null && s2 == null) {
return 0;
}
@@ -8,9 +8,10 @@ import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
public class PluginsCommand extends BukkitCommand {
public PluginsCommand(String name) {
public PluginsCommand(@NotNull String name) {
super(name);
this.description = "Gets a list of plugins running on the server";
this.usageMessage = "/plugins";
@@ -19,18 +20,20 @@ public class PluginsCommand extends BukkitCommand {
}
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
public boolean execute(@NotNull CommandSender sender, @NotNull String currentAlias, @NotNull String[] args) {
if (!testPermission(sender)) return true;
sender.sendMessage("Plugins " + getPluginList());
return true;
}
@NotNull
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
public List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException {
return Collections.emptyList();
}
@NotNull
private String getPluginList() {
StringBuilder pluginList = new StringBuilder();
Plugin[] plugins = Bukkit.getPluginManager().getPlugins();
@@ -8,9 +8,10 @@ import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
public class ReloadCommand extends BukkitCommand {
public ReloadCommand(String name) {
public ReloadCommand(@NotNull String name) {
super(name);
this.description = "Reloads the server configuration and plugins";
this.usageMessage = "/reload";
@@ -19,7 +20,7 @@ public class ReloadCommand extends BukkitCommand {
}
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
public boolean execute(@NotNull CommandSender sender, @NotNull String currentAlias, @NotNull String[] args) {
if (!testPermission(sender)) return true;
Command.broadcastCommandMessage(sender, ChatColor.RED + "Please note that this command is not supported and may cause issues when using some plugins.");
@@ -30,8 +31,9 @@ public class ReloadCommand extends BukkitCommand {
return true;
}
@NotNull
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
public List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException {
return Collections.emptyList();
}
}
@@ -18,11 +18,12 @@ import org.bukkit.plugin.TimedRegisteredListener;
import org.bukkit.util.StringUtil;
import com.google.common.collect.ImmutableList;
import org.jetbrains.annotations.NotNull;
public class TimingsCommand extends BukkitCommand {
private static final List<String> TIMINGS_SUBCOMMANDS = ImmutableList.of("merged", "reset", "separate");
public TimingsCommand(String name) {
public TimingsCommand(@NotNull String name) {
super(name);
this.description = "Records timings for all plugin events";
this.usageMessage = "/timings <reset|merged|separate>";
@@ -30,7 +31,7 @@ public class TimingsCommand extends BukkitCommand {
}
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
public boolean execute(@NotNull CommandSender sender, @NotNull String currentAlias, @NotNull String[] args) {
if (!testPermission(sender)) return true;
if (args.length != 1) {
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
@@ -110,8 +111,9 @@ public class TimingsCommand extends BukkitCommand {
return true;
}
@NotNull
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) {
public List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
@@ -22,12 +22,14 @@ import java.net.URLEncoder;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.locks.ReentrantLock;
import org.jetbrains.annotations.NotNull;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
public class VersionCommand extends BukkitCommand {
public VersionCommand(String name) {
public VersionCommand(@NotNull String name) {
super(name);
this.description = "Gets the version of this server including any plugins in use";
@@ -37,7 +39,7 @@ public class VersionCommand extends BukkitCommand {
}
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
public boolean execute(@NotNull CommandSender sender, @NotNull String currentAlias, @NotNull String[] args) {
if (!testPermission(sender)) return true;
if (args.length == 0) {
@@ -78,7 +80,7 @@ public class VersionCommand extends BukkitCommand {
return true;
}
private void describeToSender(Plugin plugin, CommandSender sender) {
private void describeToSender(@NotNull Plugin plugin, @NotNull CommandSender sender) {
PluginDescriptionFile desc = plugin.getDescription();
sender.sendMessage(ChatColor.GREEN + desc.getName() + ChatColor.WHITE + " version " + ChatColor.GREEN + desc.getVersion());
@@ -99,7 +101,8 @@ public class VersionCommand extends BukkitCommand {
}
}
private String getAuthors(final PluginDescriptionFile desc) {
@NotNull
private String getAuthors(@NotNull final PluginDescriptionFile desc) {
StringBuilder result = new StringBuilder();
List<String> authors = desc.getAuthors();
@@ -121,8 +124,9 @@ public class VersionCommand extends BukkitCommand {
return result.toString();
}
@NotNull
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) {
public List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
@@ -147,7 +151,7 @@ public class VersionCommand extends BukkitCommand {
private boolean versionTaskStarted = false;
private long lastCheck = 0;
private void sendVersion(CommandSender sender) {
private void sendVersion(@NotNull CommandSender sender) {
if (hasVersion) {
if (System.currentTimeMillis() - lastCheck > 21600000) {
lastCheck = System.currentTimeMillis();
@@ -214,7 +218,7 @@ public class VersionCommand extends BukkitCommand {
}
}
private void setVersionMessage(String msg) {
private void setVersionMessage(@NotNull String msg) {
lastCheck = System.currentTimeMillis();
versionMessage = msg;
versionLock.lock();
@@ -230,7 +234,7 @@ public class VersionCommand extends BukkitCommand {
}
}
private static int getDistance(String repo, String hash) {
private static int getDistance(@NotNull String repo, @NotNull String hash) {
try {
BufferedReader reader = Resources.asCharSource(
new URL("https://hub.spigotmc.org/stash/rest/api/1.0/projects/SPIGOT/repos/" + repo + "/commits?since=" + URLEncoder.encode(hash, "UTF-8") + "&withCounts=true"),