SPIGOT-2540: Add nullability annotations to entire Bukkit API
By: Darkyenus <darkyenus@gmail.com>
This commit is contained in:
@@ -5,6 +5,7 @@ import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Lacking an alternative, the help system will create instances of
|
||||
@@ -16,7 +17,7 @@ public class GenericCommandHelpTopic extends HelpTopic {
|
||||
|
||||
protected Command command;
|
||||
|
||||
public GenericCommandHelpTopic(Command command) {
|
||||
public GenericCommandHelpTopic(@NotNull Command command) {
|
||||
this.command = command;
|
||||
|
||||
if (command.getLabel().startsWith("/")) {
|
||||
@@ -58,7 +59,7 @@ public class GenericCommandHelpTopic extends HelpTopic {
|
||||
fullText = sb.toString();
|
||||
}
|
||||
|
||||
public boolean canSee(CommandSender sender) {
|
||||
public boolean canSee(@NotNull CommandSender sender) {
|
||||
if (!command.isRegistered()) {
|
||||
// Unregistered commands should not show up in the help
|
||||
return false;
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package org.bukkit.help;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@@ -24,13 +27,15 @@ public interface HelpMap {
|
||||
* @return A {@link HelpTopic} object matching the topic name or null if
|
||||
* none can be found.
|
||||
*/
|
||||
public HelpTopic getHelpTopic(String topicName);
|
||||
@Nullable
|
||||
public HelpTopic getHelpTopic(@NotNull String topicName);
|
||||
|
||||
/**
|
||||
* Returns a collection of all the registered help topics.
|
||||
*
|
||||
* @return All the registered help topics.
|
||||
*/
|
||||
@NotNull
|
||||
public Collection<HelpTopic> getHelpTopics();
|
||||
|
||||
/**
|
||||
@@ -38,7 +43,7 @@ public interface HelpMap {
|
||||
*
|
||||
* @param topic The new help topic to add.
|
||||
*/
|
||||
public void addTopic(HelpTopic topic);
|
||||
public void addTopic(@NotNull HelpTopic topic);
|
||||
|
||||
/**
|
||||
* Clears out the contents of the help index. Normally called during
|
||||
@@ -63,7 +68,7 @@ public interface HelpMap {
|
||||
* @throws IllegalArgumentException Thrown if {@code commandClass} does
|
||||
* not derive from a legal base class.
|
||||
*/
|
||||
public void registerHelpTopicFactory(Class<?> commandClass, HelpTopicFactory<?> factory);
|
||||
public void registerHelpTopicFactory(@NotNull Class<?> commandClass, @NotNull HelpTopicFactory<?> factory);
|
||||
|
||||
/**
|
||||
* Gets the list of plugins the server administrator has chosen to exclude
|
||||
@@ -75,5 +80,6 @@ public interface HelpMap {
|
||||
*
|
||||
* @return A list of plugins that should be excluded from the help index.
|
||||
*/
|
||||
@NotNull
|
||||
public List<String> getIgnoredPlugins();
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package org.bukkit.help;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* HelpTopic implementations are displayed to the user when the user uses the
|
||||
@@ -16,11 +18,11 @@ import org.bukkit.entity.Player;
|
||||
* the methods in this class.
|
||||
*/
|
||||
public abstract class HelpTopic {
|
||||
protected String name;
|
||||
protected String shortText;
|
||||
protected String fullText;
|
||||
protected String amendedPermission;
|
||||
|
||||
protected String name = "";
|
||||
protected String shortText = "";
|
||||
protected String fullText = "";
|
||||
protected String amendedPermission = null;
|
||||
|
||||
/**
|
||||
* Determines if a {@link Player} is allowed to see this help topic.
|
||||
* <p>
|
||||
@@ -30,7 +32,7 @@ public abstract class HelpTopic {
|
||||
* @param player The Player in question.
|
||||
* @return True of the Player can see this help topic, false otherwise.
|
||||
*/
|
||||
public abstract boolean canSee(CommandSender player);
|
||||
public abstract boolean canSee(@NotNull CommandSender player);
|
||||
|
||||
/**
|
||||
* Allows the server administrator to override the permission required to
|
||||
@@ -43,7 +45,7 @@ public abstract class HelpTopic {
|
||||
* @param amendedPermission The permission node the server administrator
|
||||
* wishes to apply to this topic.
|
||||
*/
|
||||
public void amendCanSee(String amendedPermission) {
|
||||
public void amendCanSee(@Nullable String amendedPermission) {
|
||||
this.amendedPermission = amendedPermission;
|
||||
}
|
||||
|
||||
@@ -52,6 +54,7 @@ public abstract class HelpTopic {
|
||||
*
|
||||
* @return The topic name.
|
||||
*/
|
||||
@NotNull
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
@@ -61,6 +64,7 @@ public abstract class HelpTopic {
|
||||
*
|
||||
* @return A brief topic description.
|
||||
*/
|
||||
@NotNull
|
||||
public String getShortText() {
|
||||
return shortText;
|
||||
}
|
||||
@@ -77,7 +81,8 @@ public abstract class HelpTopic {
|
||||
*
|
||||
* @return A full topic description.
|
||||
*/
|
||||
public String getFullText(CommandSender forWho) {
|
||||
@NotNull
|
||||
public String getFullText(@NotNull CommandSender forWho) {
|
||||
return fullText;
|
||||
}
|
||||
|
||||
@@ -95,7 +100,7 @@ public abstract class HelpTopic {
|
||||
* @param amendedFullText The new topic full text to use, or null to leave
|
||||
* alone.
|
||||
*/
|
||||
public void amendTopic(String amendedShortText, String amendedFullText) {
|
||||
public void amendTopic(@Nullable String amendedShortText, @Nullable String amendedFullText) {
|
||||
shortText = applyAmendment(shortText, amendedShortText);
|
||||
fullText = applyAmendment(fullText, amendedFullText);
|
||||
}
|
||||
@@ -111,7 +116,8 @@ public abstract class HelpTopic {
|
||||
* @return The application of the amending text to the existing text,
|
||||
* according to the expected rules of amendTopic().
|
||||
*/
|
||||
protected String applyAmendment(String baseText, String amendment) {
|
||||
@NotNull
|
||||
protected String applyAmendment(@NotNull String baseText, @Nullable String amendment) {
|
||||
if (amendment == null) {
|
||||
return baseText;
|
||||
} else {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.bukkit.help;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
/**
|
||||
@@ -12,25 +14,27 @@ public class HelpTopicComparator implements Comparator<HelpTopic> {
|
||||
|
||||
// Singleton implementations
|
||||
private static final TopicNameComparator tnc = new TopicNameComparator();
|
||||
@NotNull
|
||||
public static TopicNameComparator topicNameComparatorInstance() {
|
||||
return tnc;
|
||||
}
|
||||
|
||||
private static final HelpTopicComparator htc = new HelpTopicComparator();
|
||||
@NotNull
|
||||
public static HelpTopicComparator helpTopicComparatorInstance() {
|
||||
return htc;
|
||||
}
|
||||
|
||||
private HelpTopicComparator() {}
|
||||
|
||||
public int compare(HelpTopic lhs, HelpTopic rhs) {
|
||||
public int compare(@NotNull HelpTopic lhs, @NotNull HelpTopic rhs) {
|
||||
return tnc.compare(lhs.getName(), rhs.getName());
|
||||
}
|
||||
|
||||
public static class TopicNameComparator implements Comparator<String> {
|
||||
private TopicNameComparator(){}
|
||||
|
||||
public int compare(String lhs, String rhs) {
|
||||
public int compare(@NotNull String lhs, @NotNull String rhs) {
|
||||
boolean lhsStartSlash = lhs.startsWith("/");
|
||||
boolean rhsStartSlash = rhs.startsWith("/");
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package org.bukkit.help;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* A HelpTopicFactory is used to create custom {@link HelpTopic} objects from
|
||||
@@ -38,5 +40,6 @@ public interface HelpTopicFactory<TCommand extends Command> {
|
||||
* @return A new custom help topic or {@code null} to intentionally NOT
|
||||
* create a topic.
|
||||
*/
|
||||
public HelpTopic createTopic(TCommand command);
|
||||
@Nullable
|
||||
public HelpTopic createTopic(@NotNull TCommand command);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.ChatPaginator;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -22,15 +24,15 @@ public class IndexHelpTopic extends HelpTopic {
|
||||
protected String preamble;
|
||||
protected Collection<HelpTopic> allTopics;
|
||||
|
||||
public IndexHelpTopic(String name, String shortText, String permission, Collection<HelpTopic> topics) {
|
||||
public IndexHelpTopic(@NotNull String name, @Nullable String shortText, @Nullable String permission, @NotNull Collection<HelpTopic> topics) {
|
||||
this(name, shortText, permission, topics, null);
|
||||
}
|
||||
|
||||
public IndexHelpTopic(String name, String shortText, String permission, Collection<HelpTopic> topics, String preamble) {
|
||||
public IndexHelpTopic(@NotNull String name, @Nullable String shortText, @Nullable String permission, @NotNull Collection<HelpTopic> topics, @Nullable String preamble) {
|
||||
this.name = name;
|
||||
this.shortText = shortText;
|
||||
this.shortText = (shortText == null) ? "" : shortText;
|
||||
this.permission = permission;
|
||||
this.preamble = preamble;
|
||||
this.preamble = (preamble == null) ? "" : preamble;
|
||||
setTopicsCollection(topics);
|
||||
}
|
||||
|
||||
@@ -39,11 +41,11 @@ public class IndexHelpTopic extends HelpTopic {
|
||||
*
|
||||
* @param topics The topics to set.
|
||||
*/
|
||||
protected void setTopicsCollection(Collection<HelpTopic> topics) {
|
||||
protected void setTopicsCollection(@NotNull Collection<HelpTopic> topics) {
|
||||
this.allTopics = topics;
|
||||
}
|
||||
|
||||
public boolean canSee(CommandSender sender) {
|
||||
public boolean canSee(@NotNull CommandSender sender) {
|
||||
if (sender instanceof ConsoleCommandSender) {
|
||||
return true;
|
||||
}
|
||||
@@ -54,11 +56,12 @@ public class IndexHelpTopic extends HelpTopic {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void amendCanSee(String amendedPermission) {
|
||||
public void amendCanSee(@Nullable String amendedPermission) {
|
||||
permission = amendedPermission;
|
||||
}
|
||||
|
||||
public String getFullText(CommandSender sender) {
|
||||
@NotNull
|
||||
public String getFullText(@NotNull CommandSender sender) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
if (preamble != null) {
|
||||
@@ -70,7 +73,7 @@ public class IndexHelpTopic extends HelpTopic {
|
||||
if (topic.canSee(sender)) {
|
||||
String lineStr = buildIndexLine(sender, topic).replace("\n", ". ");
|
||||
if (sender instanceof Player && lineStr.length() > ChatPaginator.GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH) {
|
||||
sb.append(lineStr.substring(0, ChatPaginator.GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH - 3));
|
||||
sb.append(lineStr, 0, ChatPaginator.GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH - 3);
|
||||
sb.append("...");
|
||||
} else {
|
||||
sb.append(lineStr);
|
||||
@@ -88,7 +91,8 @@ public class IndexHelpTopic extends HelpTopic {
|
||||
* @param sender The command sender requesting the preamble.
|
||||
* @return The topic preamble.
|
||||
*/
|
||||
protected String buildPreamble(CommandSender sender) {
|
||||
@NotNull
|
||||
protected String buildPreamble(@NotNull CommandSender sender) {
|
||||
return ChatColor.GRAY + preamble;
|
||||
}
|
||||
|
||||
@@ -100,7 +104,8 @@ public class IndexHelpTopic extends HelpTopic {
|
||||
* @param topic The topic to render into an index line.
|
||||
* @return The rendered index line.
|
||||
*/
|
||||
protected String buildIndexLine(CommandSender sender, HelpTopic topic) {
|
||||
@NotNull
|
||||
protected String buildIndexLine(@NotNull CommandSender sender, @NotNull HelpTopic topic) {
|
||||
StringBuilder line = new StringBuilder();
|
||||
line.append(ChatColor.GOLD);
|
||||
line.append(topic.getName());
|
||||
|
||||
Reference in New Issue
Block a user