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

@@ -1,6 +1,7 @@
package org.bukkit.command;
import org.bukkit.block.Block;
import org.jetbrains.annotations.NotNull;
public interface BlockCommandSender extends CommandSender {
@@ -9,5 +10,6 @@ public interface BlockCommandSender extends CommandSender {
*
* @return Block for the command sender
*/
@NotNull
public Block getBlock();
}

View File

@@ -18,6 +18,8 @@ import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.util.StringUtil;
import com.google.common.collect.ImmutableList;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Represents a Command, which executes various tasks upon user input
@@ -28,22 +30,22 @@ public abstract class Command {
private String label;
private List<String> aliases;
private List<String> activeAliases;
private CommandMap commandMap = null;
protected String description = "";
private CommandMap commandMap;
protected String description;
protected String usageMessage;
private String permission;
private String permissionMessage;
protected Command(String name) {
protected Command(@NotNull String name) {
this(name, "", "/" + name, new ArrayList<String>());
}
protected Command(String name, String description, String usageMessage, List<String> aliases) {
protected Command(@NotNull String name, @NotNull String description, @NotNull String usageMessage, @NotNull List<String> aliases) {
this.name = name;
this.nextLabel = name;
this.label = name;
this.description = description;
this.usageMessage = usageMessage;
this.description = (description == null) ? "" : description;
this.usageMessage = (usageMessage == null) ? "/" + name : usageMessage;
this.aliases = aliases;
this.activeAliases = new ArrayList<String>(aliases);
}
@@ -56,7 +58,7 @@ public abstract class Command {
* @param args All arguments passed to the command, split via ' '
* @return true if the command was successful, otherwise false
*/
public abstract boolean execute(CommandSender sender, String commandLabel, String[] args);
public abstract boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args);
/**
* Executed on tab completion for this command, returning a list of
@@ -69,7 +71,8 @@ public abstract class Command {
* will never be null. List may be immutable.
* @throws IllegalArgumentException if sender, alias, or args is null
*/
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
@NotNull
public List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException {
return tabComplete0(sender, alias, args, null);
}
@@ -85,11 +88,13 @@ public abstract class Command {
* will never be null. List may be immutable.
* @throws IllegalArgumentException if sender, alias, or args is null
*/
public List<String> tabComplete(CommandSender sender, String alias, String[] args, Location location) throws IllegalArgumentException {
@NotNull
public List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args, @Nullable Location location) throws IllegalArgumentException {
return tabComplete(sender, alias, args);
}
private List<String> tabComplete0(CommandSender sender, String alias, String[] args, Location location) throws IllegalArgumentException {
@NotNull
private List<String> tabComplete0(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args, @Nullable Location location) throws IllegalArgumentException {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
@@ -119,6 +124,7 @@ public abstract class Command {
*
* @return Name of this command
*/
@NotNull
public String getName() {
return name;
}
@@ -134,9 +140,9 @@ public abstract class Command {
* @return returns true if the name change happened instantly or false if
* the command was already registered
*/
public boolean setName(String name) {
public boolean setName(@NotNull String name) {
if (!isRegistered()) {
this.name = name;
this.name = (name == null) ? "" : name;
return true;
}
return false;
@@ -148,6 +154,7 @@ public abstract class Command {
*
* @return Permission name, or null if none
*/
@Nullable
public String getPermission() {
return permission;
}
@@ -158,7 +165,7 @@ public abstract class Command {
*
* @param permission Permission name or null
*/
public void setPermission(String permission) {
public void setPermission(@Nullable String permission) {
this.permission = permission;
}
@@ -172,7 +179,7 @@ public abstract class Command {
* @param target User to test
* @return true if they can use it, otherwise false
*/
public boolean testPermission(CommandSender target) {
public boolean testPermission(@NotNull CommandSender target) {
if (testPermissionSilent(target)) {
return true;
}
@@ -197,7 +204,7 @@ public abstract class Command {
* @param target User to test
* @return true if they can use it, otherwise false
*/
public boolean testPermissionSilent(CommandSender target) {
public boolean testPermissionSilent(@NotNull CommandSender target) {
if ((permission == null) || (permission.length() == 0)) {
return true;
}
@@ -216,6 +223,7 @@ public abstract class Command {
*
* @return Label of this command
*/
@NotNull
public String getLabel() {
return label;
}
@@ -231,7 +239,10 @@ public abstract class Command {
* @return returns true if the name change happened instantly or false if
* the command was already registered
*/
public boolean setLabel(String name) {
public boolean setLabel(@NotNull String name) {
if (name == null) {
name = "";
}
this.nextLabel = name;
if (!isRegistered()) {
this.label = name;
@@ -248,7 +259,7 @@ public abstract class Command {
* @return true if the registration was successful (the current registered
* CommandMap was the passed CommandMap or null) false otherwise
*/
public boolean register(CommandMap commandMap) {
public boolean register(@NotNull CommandMap commandMap) {
if (allowChangesFrom(commandMap)) {
this.commandMap = commandMap;
return true;
@@ -266,7 +277,7 @@ public abstract class Command {
* registered CommandMap was the passed CommandMap or null) false
* otherwise
*/
public boolean unregister(CommandMap commandMap) {
public boolean unregister(@NotNull CommandMap commandMap) {
if (allowChangesFrom(commandMap)) {
this.commandMap = null;
this.activeAliases = new ArrayList<String>(this.aliases);
@@ -277,7 +288,7 @@ public abstract class Command {
return false;
}
private boolean allowChangesFrom(CommandMap commandMap) {
private boolean allowChangesFrom(@NotNull CommandMap commandMap) {
return (null == this.commandMap || this.commandMap == commandMap);
}
@@ -295,6 +306,7 @@ public abstract class Command {
*
* @return List of aliases
*/
@NotNull
public List<String> getAliases() {
return activeAliases;
}
@@ -305,6 +317,7 @@ public abstract class Command {
*
* @return Permission check failed message
*/
@Nullable
public String getPermissionMessage() {
return permissionMessage;
}
@@ -314,6 +327,7 @@ public abstract class Command {
*
* @return Description of this command
*/
@NotNull
public String getDescription() {
return description;
}
@@ -323,6 +337,7 @@ public abstract class Command {
*
* @return One or more example usages
*/
@NotNull
public String getUsage() {
return usageMessage;
}
@@ -336,7 +351,8 @@ public abstract class Command {
* @param aliases aliases to register to this command
* @return this command object, for chaining
*/
public Command setAliases(List<String> aliases) {
@NotNull
public Command setAliases(@NotNull List<String> aliases) {
this.aliases = aliases;
if (!isRegistered()) {
this.activeAliases = new ArrayList<String>(aliases);
@@ -352,8 +368,9 @@ public abstract class Command {
* @param description new command description
* @return this command object, for chaining
*/
public Command setDescription(String description) {
this.description = description;
@NotNull
public Command setDescription(@NotNull String description) {
this.description = description == null ? "" : "";
return this;
}
@@ -364,7 +381,8 @@ public abstract class Command {
* default message, or an empty string to indicate no message
* @return this command object, for chaining
*/
public Command setPermissionMessage(String permissionMessage) {
@NotNull
public Command setPermissionMessage(@Nullable String permissionMessage) {
this.permissionMessage = permissionMessage;
return this;
}
@@ -375,16 +393,17 @@ public abstract class Command {
* @param usage new example usage
* @return this command object, for chaining
*/
public Command setUsage(String usage) {
this.usageMessage = usage;
@NotNull
public Command setUsage(@NotNull String usage) {
this.usageMessage = (usage == null) ? "" : usage;
return this;
}
public static void broadcastCommandMessage(CommandSender source, String message) {
public static void broadcastCommandMessage(@NotNull CommandSender source, @NotNull String message) {
broadcastCommandMessage(source, message, true);
}
public static void broadcastCommandMessage(CommandSender source, String message, boolean sendToSource) {
public static void broadcastCommandMessage(@NotNull CommandSender source, @NotNull String message, boolean sendToSource) {
String result = source.getName() + ": " + message;
if (source instanceof BlockCommandSender) {

View File

@@ -1,5 +1,7 @@
package org.bukkit.command;
import org.jetbrains.annotations.NotNull;
/**
* Represents a class which contains a single method for executing commands
*/
@@ -17,5 +19,5 @@ public interface CommandExecutor {
* @param args Passed command arguments
* @return true if a valid command, otherwise false
*/
public boolean onCommand(CommandSender sender, Command command, String label, String[] args);
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args);
}

View File

@@ -2,6 +2,8 @@ package org.bukkit.command;
import java.util.List;
import org.bukkit.Location;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public interface CommandMap {
@@ -20,7 +22,7 @@ public interface CommandMap {
* a ':' one or more times to make the command unique
* @param commands a list of commands to register
*/
public void registerAll(String fallbackPrefix, List<Command> commands);
public void registerAll(@NotNull String fallbackPrefix, @NotNull List<Command> commands);
/**
* Registers a command. Returns true on success; false if name is already
@@ -42,7 +44,7 @@ public interface CommandMap {
* otherwise, which indicates the fallbackPrefix was used one or more
* times
*/
public boolean register(String label, String fallbackPrefix, Command command);
public boolean register(@NotNull String label, @NotNull String fallbackPrefix, @NotNull Command command);
/**
* Registers a command. Returns true on success; false if name is already
@@ -64,7 +66,7 @@ public interface CommandMap {
* otherwise, which indicates the fallbackPrefix was used one or more
* times
*/
public boolean register(String fallbackPrefix, Command command);
public boolean register(@NotNull String fallbackPrefix, @NotNull Command command);
/**
* Looks for the requested command and executes it if found.
@@ -75,7 +77,7 @@ public interface CommandMap {
* @throws CommandException Thrown when the executor for the given command
* fails with an unhandled exception
*/
public boolean dispatch(CommandSender sender, String cmdLine) throws CommandException;
public boolean dispatch(@NotNull CommandSender sender, @NotNull String cmdLine) throws CommandException;
/**
* Clears all registered commands.
@@ -89,7 +91,8 @@ public interface CommandMap {
* @return Command with the specified name or null if a command with that
* label doesn't exist
*/
public Command getCommand(String name);
@Nullable
public Command getCommand(@NotNull String name);
/**
* Looks for the requested command and executes an appropriate
@@ -105,7 +108,8 @@ public interface CommandMap {
* command fails with an unhandled exception
* @throws IllegalArgumentException if either sender or cmdLine are null
*/
public List<String> tabComplete(CommandSender sender, String cmdLine) throws IllegalArgumentException;
@Nullable
public List<String> tabComplete(@NotNull CommandSender sender, @NotNull String cmdLine) throws IllegalArgumentException;
/**
* Looks for the requested command and executes an appropriate
@@ -122,5 +126,6 @@ public interface CommandMap {
* command fails with an unhandled exception
* @throws IllegalArgumentException if either sender or cmdLine are null
*/
public List<String> tabComplete(CommandSender sender, String cmdLine, Location location) throws IllegalArgumentException;
@Nullable
public List<String> tabComplete(@NotNull CommandSender sender, @NotNull String cmdLine, @Nullable Location location) throws IllegalArgumentException;
}

View File

@@ -2,6 +2,7 @@ package org.bukkit.command;
import org.bukkit.Server;
import org.bukkit.permissions.Permissible;
import org.jetbrains.annotations.NotNull;
public interface CommandSender extends Permissible {
@@ -10,20 +11,21 @@ public interface CommandSender extends Permissible {
*
* @param message Message to be displayed
*/
public void sendMessage(String message);
public void sendMessage(@NotNull String message);
/**
* Sends this sender multiple messages
*
* @param messages An array of messages to be displayed
*/
public void sendMessage(String[] messages);
public void sendMessage(@NotNull String[] messages);
/**
* Returns the server instance that this command is running on
*
* @return Server instance
*/
@NotNull
public Server getServer();
/**
@@ -31,5 +33,6 @@ public interface CommandSender extends Permissible {
*
* @return Name of the sender
*/
@NotNull
public String getName();
}

View File

@@ -3,17 +3,18 @@ package org.bukkit.command;
import java.util.ArrayList;
import org.bukkit.Bukkit;
import org.jetbrains.annotations.NotNull;
public class FormattedCommandAlias extends Command {
private final String[] formatStrings;
public FormattedCommandAlias(String alias, String[] formatStrings) {
public FormattedCommandAlias(@NotNull String alias, @NotNull String[] formatStrings) {
super(alias);
this.formatStrings = formatStrings;
}
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args) {
boolean result = false;
ArrayList<String> commands = new ArrayList<String>();
for (String formatString : formatStrings) {
@@ -36,7 +37,7 @@ public class FormattedCommandAlias extends Command {
return result;
}
private String buildCommand(String formatString, String[] args) {
private String buildCommand(@NotNull String formatString, @NotNull String[] args) {
int index = formatString.indexOf('$');
while (index != -1) {
int start = index;

View File

@@ -1,12 +1,14 @@
package org.bukkit.command;
import org.jetbrains.annotations.NotNull;
/**
* Represents a command that delegates to one or more other commands
*/
public class MultipleCommandAlias extends Command {
private Command[] commands;
public MultipleCommandAlias(String name, Command[] commands) {
public MultipleCommandAlias(@NotNull String name, @NotNull Command[] commands) {
super(name);
this.commands = commands;
}
@@ -16,12 +18,13 @@ public class MultipleCommandAlias extends Command {
*
* @return commands associated with alias
*/
@NotNull
public Command[] getCommands() {
return commands;
}
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args) {
boolean result = false;
for (Command command : commands) {

View File

@@ -4,6 +4,8 @@ import java.util.List;
import org.apache.commons.lang.Validate;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Represents a {@link Command} belonging to a plugin
@@ -13,7 +15,7 @@ public final class PluginCommand extends Command implements PluginIdentifiableCo
private CommandExecutor executor;
private TabCompleter completer;
protected PluginCommand(String name, Plugin owner) {
protected PluginCommand(@NotNull String name, @NotNull Plugin owner) {
super(name);
this.executor = owner;
this.owningPlugin = owner;
@@ -29,7 +31,7 @@ public final class PluginCommand extends Command implements PluginIdentifiableCo
* @return true if the command was successful, otherwise false
*/
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args) {
boolean success = false;
if (!owningPlugin.isEnabled()) {
@@ -60,7 +62,7 @@ public final class PluginCommand extends Command implements PluginIdentifiableCo
*
* @param executor New executor to run
*/
public void setExecutor(CommandExecutor executor) {
public void setExecutor(@Nullable CommandExecutor executor) {
this.executor = executor == null ? owningPlugin : executor;
}
@@ -69,6 +71,7 @@ public final class PluginCommand extends Command implements PluginIdentifiableCo
*
* @return CommandExecutor object linked to this command
*/
@NotNull
public CommandExecutor getExecutor() {
return executor;
}
@@ -81,7 +84,7 @@ public final class PluginCommand extends Command implements PluginIdentifiableCo
*
* @param completer New tab completer
*/
public void setTabCompleter(TabCompleter completer) {
public void setTabCompleter(@Nullable TabCompleter completer) {
this.completer = completer;
}
@@ -90,6 +93,7 @@ public final class PluginCommand extends Command implements PluginIdentifiableCo
*
* @return TabCompleter object linked to this command
*/
@Nullable
public TabCompleter getTabCompleter() {
return completer;
}
@@ -99,6 +103,7 @@ public final class PluginCommand extends Command implements PluginIdentifiableCo
*
* @return Plugin that owns this command
*/
@NotNull
public Plugin getPlugin() {
return owningPlugin;
}
@@ -120,8 +125,9 @@ public final class PluginCommand extends Command implements PluginIdentifiableCo
* exception during the process of tab-completing.
* @throws IllegalArgumentException if sender, alias, or args is null
*/
@NotNull
@Override
public java.util.List<String> tabComplete(CommandSender sender, String alias, String[] args) throws CommandException, IllegalArgumentException {
public java.util.List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws CommandException, IllegalArgumentException {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");

View File

@@ -7,10 +7,12 @@ import java.util.Map.Entry;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
public class PluginCommandYamlParser {
public static List<Command> parse(Plugin plugin) {
@NotNull
public static List<Command> parse(@NotNull Plugin plugin) {
List<Command> pluginCmds = new ArrayList<Command>();
Map<String, Map<String, Object>> map = plugin.getDescription().getCommands();

View File

@@ -1,6 +1,7 @@
package org.bukkit.command;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
/**
* This interface is used by the help system to group commands into
@@ -15,5 +16,6 @@ public interface PluginIdentifiableCommand {
*
* @return Plugin that owns this PluginIdentifiableCommand.
*/
@NotNull
public Plugin getPlugin();
}

View File

@@ -1,6 +1,8 @@
package org.bukkit.command;
import org.jetbrains.annotations.NotNull;
public interface ProxiedCommandSender extends CommandSender {
/**
@@ -8,6 +10,7 @@ public interface ProxiedCommandSender extends CommandSender {
*
* @return the caller which triggered the command
*/
@NotNull
CommandSender getCaller();
/**
@@ -15,6 +18,7 @@ public interface ProxiedCommandSender extends CommandSender {
*
* @return the caller which the command is being run as
*/
@NotNull
CommandSender getCallee();
}

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

View File

@@ -1,5 +1,8 @@
package org.bukkit.command;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
/**
@@ -20,5 +23,6 @@ public interface TabCompleter {
* @return A List of possible completions for the final argument, or null
* to default to the command executor
*/
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args);
@Nullable
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args);
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -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"),