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

@@ -2,6 +2,8 @@ package org.bukkit.permissions;
import java.util.Set;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Represents an object that may be assigned permissions
@@ -15,7 +17,7 @@ public interface Permissible extends ServerOperator {
* @param name Name of the permission
* @return true if the permission is set, otherwise false
*/
public boolean isPermissionSet(String name);
public boolean isPermissionSet(@NotNull String name);
/**
* Checks if this object contains an override for the specified {@link
@@ -24,7 +26,7 @@ public interface Permissible extends ServerOperator {
* @param perm Permission to check
* @return true if the permission is set, otherwise false
*/
public boolean isPermissionSet(Permission perm);
public boolean isPermissionSet(@NotNull Permission perm);
/**
* Gets the value of the specified permission, if set.
@@ -35,7 +37,7 @@ public interface Permissible extends ServerOperator {
* @param name Name of the permission
* @return Value of the permission
*/
public boolean hasPermission(String name);
public boolean hasPermission(@NotNull String name);
/**
* Gets the value of the specified permission, if set.
@@ -46,7 +48,7 @@ public interface Permissible extends ServerOperator {
* @param perm Permission to get
* @return Value of the permission
*/
public boolean hasPermission(Permission perm);
public boolean hasPermission(@NotNull Permission perm);
/**
* Adds a new {@link PermissionAttachment} with a single permission by
@@ -58,7 +60,8 @@ public interface Permissible extends ServerOperator {
* @param value Value of the permission
* @return The PermissionAttachment that was just created
*/
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value);
@NotNull
public PermissionAttachment addAttachment(@NotNull Plugin plugin, @NotNull String name, boolean value);
/**
* Adds a new empty {@link PermissionAttachment} to this object
@@ -67,7 +70,8 @@ public interface Permissible extends ServerOperator {
* or disabled
* @return The PermissionAttachment that was just created
*/
public PermissionAttachment addAttachment(Plugin plugin);
@NotNull
public PermissionAttachment addAttachment(@NotNull Plugin plugin);
/**
* Temporarily adds a new {@link PermissionAttachment} with a single
@@ -81,7 +85,8 @@ public interface Permissible extends ServerOperator {
* after
* @return The PermissionAttachment that was just created
*/
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value, int ticks);
@Nullable
public PermissionAttachment addAttachment(@NotNull Plugin plugin, @NotNull String name, boolean value, int ticks);
/**
* Temporarily adds a new empty {@link PermissionAttachment} to this
@@ -93,7 +98,8 @@ public interface Permissible extends ServerOperator {
* after
* @return The PermissionAttachment that was just created
*/
public PermissionAttachment addAttachment(Plugin plugin, int ticks);
@Nullable
public PermissionAttachment addAttachment(@NotNull Plugin plugin, int ticks);
/**
* Removes the given {@link PermissionAttachment} from this object
@@ -102,7 +108,7 @@ public interface Permissible extends ServerOperator {
* @throws IllegalArgumentException Thrown when the specified attachment
* isn't part of this object
*/
public void removeAttachment(PermissionAttachment attachment);
public void removeAttachment(@NotNull PermissionAttachment attachment);
/**
* Recalculates the permissions for this object, if the attachments have
@@ -118,5 +124,6 @@ public interface Permissible extends ServerOperator {
*
* @return Set of currently effective permissions
*/
@NotNull
public Set<PermissionAttachmentInfo> getEffectivePermissions();
}

View File

@@ -9,17 +9,19 @@ import java.util.Set;
import java.util.logging.Level;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Base Permissible for use in any Permissible object via proxy or extension
*/
public class PermissibleBase implements Permissible {
private ServerOperator opable = null;
private ServerOperator opable;
private Permissible parent = this;
private final List<PermissionAttachment> attachments = new LinkedList<PermissionAttachment>();
private final Map<String, PermissionAttachmentInfo> permissions = new HashMap<String, PermissionAttachmentInfo>();
public PermissibleBase(ServerOperator opable) {
public PermissibleBase(@Nullable ServerOperator opable) {
this.opable = opable;
if (opable instanceof Permissible) {
@@ -45,7 +47,7 @@ public class PermissibleBase implements Permissible {
}
}
public boolean isPermissionSet(String name) {
public boolean isPermissionSet(@NotNull String name) {
if (name == null) {
throw new IllegalArgumentException("Permission name cannot be null");
}
@@ -53,7 +55,7 @@ public class PermissibleBase implements Permissible {
return permissions.containsKey(name.toLowerCase(java.util.Locale.ENGLISH));
}
public boolean isPermissionSet(Permission perm) {
public boolean isPermissionSet(@NotNull Permission perm) {
if (perm == null) {
throw new IllegalArgumentException("Permission cannot be null");
}
@@ -61,7 +63,7 @@ public class PermissibleBase implements Permissible {
return isPermissionSet(perm.getName());
}
public boolean hasPermission(String inName) {
public boolean hasPermission(@NotNull String inName) {
if (inName == null) {
throw new IllegalArgumentException("Permission name cannot be null");
}
@@ -81,7 +83,7 @@ public class PermissibleBase implements Permissible {
}
}
public boolean hasPermission(Permission perm) {
public boolean hasPermission(@NotNull Permission perm) {
if (perm == null) {
throw new IllegalArgumentException("Permission cannot be null");
}
@@ -94,7 +96,8 @@ public class PermissibleBase implements Permissible {
return perm.getDefault().getValue(isOp());
}
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value) {
@NotNull
public PermissionAttachment addAttachment(@NotNull Plugin plugin, @NotNull String name, boolean value) {
if (name == null) {
throw new IllegalArgumentException("Permission name cannot be null");
} else if (plugin == null) {
@@ -111,7 +114,8 @@ public class PermissibleBase implements Permissible {
return result;
}
public PermissionAttachment addAttachment(Plugin plugin) {
@NotNull
public PermissionAttachment addAttachment(@NotNull Plugin plugin) {
if (plugin == null) {
throw new IllegalArgumentException("Plugin cannot be null");
} else if (!plugin.isEnabled()) {
@@ -126,7 +130,7 @@ public class PermissibleBase implements Permissible {
return result;
}
public void removeAttachment(PermissionAttachment attachment) {
public void removeAttachment(@NotNull PermissionAttachment attachment) {
if (attachment == null) {
throw new IllegalArgumentException("Attachment cannot be null");
}
@@ -175,7 +179,7 @@ public class PermissibleBase implements Permissible {
permissions.clear();
}
private void calculateChildPermissions(Map<String, Boolean> children, boolean invert, PermissionAttachment attachment) {
private void calculateChildPermissions(@NotNull Map<String, Boolean> children, boolean invert, @Nullable PermissionAttachment attachment) {
for (Map.Entry<String, Boolean> entry : children.entrySet()) {
String name = entry.getKey();
@@ -192,7 +196,8 @@ public class PermissibleBase implements Permissible {
}
}
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value, int ticks) {
@Nullable
public PermissionAttachment addAttachment(@NotNull Plugin plugin, @NotNull String name, boolean value, int ticks) {
if (name == null) {
throw new IllegalArgumentException("Permission name cannot be null");
} else if (plugin == null) {
@@ -210,7 +215,8 @@ public class PermissibleBase implements Permissible {
return result;
}
public PermissionAttachment addAttachment(Plugin plugin, int ticks) {
@Nullable
public PermissionAttachment addAttachment(@NotNull Plugin plugin, int ticks) {
if (plugin == null) {
throw new IllegalArgumentException("Plugin cannot be null");
} else if (!plugin.isEnabled()) {
@@ -228,6 +234,7 @@ public class PermissibleBase implements Permissible {
}
}
@NotNull
public Set<PermissionAttachmentInfo> getEffectivePermissions() {
return new HashSet<PermissionAttachmentInfo>(permissions.values());
}
@@ -235,7 +242,7 @@ public class PermissibleBase implements Permissible {
private static class RemoveAttachmentRunnable implements Runnable {
private PermissionAttachment attachment;
public RemoveAttachmentRunnable(PermissionAttachment attachment) {
public RemoveAttachmentRunnable(@NotNull PermissionAttachment attachment) {
this.attachment = attachment;
}

View File

@@ -10,6 +10,8 @@ import java.util.logging.Level;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.plugin.PluginManager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Represents a unique permission that may be attached to a {@link
@@ -23,35 +25,35 @@ public class Permission {
private PermissionDefault defaultValue = DEFAULT_PERMISSION;
private String description;
public Permission(String name) {
public Permission(@NotNull String name) {
this(name, null, null, null);
}
public Permission(String name, String description) {
public Permission(@NotNull String name, @Nullable String description) {
this(name, description, null, null);
}
public Permission(String name, PermissionDefault defaultValue) {
public Permission(@NotNull String name, @Nullable PermissionDefault defaultValue) {
this(name, null, defaultValue, null);
}
public Permission(String name, String description, PermissionDefault defaultValue) {
public Permission(@NotNull String name, @Nullable String description, @Nullable PermissionDefault defaultValue) {
this(name, description, defaultValue, null);
}
public Permission(String name, Map<String, Boolean> children) {
public Permission(@NotNull String name, @Nullable Map<String, Boolean> children) {
this(name, null, null, children);
}
public Permission(String name, String description, Map<String, Boolean> children) {
public Permission(@NotNull String name, @Nullable String description, @Nullable Map<String, Boolean> children) {
this(name, description, null, children);
}
public Permission(String name, PermissionDefault defaultValue, Map<String, Boolean> children) {
public Permission(@NotNull String name, @Nullable PermissionDefault defaultValue, @Nullable Map<String, Boolean> children) {
this(name, null, defaultValue, children);
}
public Permission(String name, String description, PermissionDefault defaultValue, Map<String, Boolean> children) {
public Permission(@NotNull String name, @Nullable String description, @Nullable PermissionDefault defaultValue, @Nullable Map<String, Boolean> children) {
Validate.notNull(name, "Name cannot be null");
this.name = name;
this.description = (description == null) ? "" : description;
@@ -72,6 +74,7 @@ public class Permission {
*
* @return Fully qualified name
*/
@NotNull
public String getName() {
return name;
}
@@ -84,6 +87,7 @@ public class Permission {
*
* @return Permission children
*/
@NotNull
public Map<String, Boolean> getChildren() {
return children;
}
@@ -93,6 +97,7 @@ public class Permission {
*
* @return Default value of this permission.
*/
@NotNull
public PermissionDefault getDefault() {
return defaultValue;
}
@@ -107,7 +112,7 @@ public class Permission {
*
* @param value The new default to set
*/
public void setDefault(PermissionDefault value) {
public void setDefault(@NotNull PermissionDefault value) {
if (defaultValue == null) {
throw new IllegalArgumentException("Default value cannot be null");
}
@@ -117,10 +122,11 @@ public class Permission {
}
/**
* Gets a brief description of this permission, if set
* Gets a brief description of this permission, may be empty
*
* @return Brief description of this permission
*/
@NotNull
public String getDescription() {
return description;
}
@@ -133,7 +139,7 @@ public class Permission {
*
* @param value The new description to set
*/
public void setDescription(String value) {
public void setDescription(@Nullable String value) {
if (value == null) {
description = "";
} else {
@@ -149,6 +155,7 @@ public class Permission {
*
* @return Set containing permissibles with this permission
*/
@NotNull
public Set<Permissible> getPermissibles() {
return Bukkit.getServer().getPluginManager().getPermissionSubscriptions(name);
}
@@ -179,7 +186,8 @@ public class Permission {
* @param value The value to set this permission to
* @return Parent permission it created or loaded
*/
public Permission addParent(String name, boolean value) {
@NotNull
public Permission addParent(@NotNull String name, boolean value) {
PluginManager pm = Bukkit.getServer().getPluginManager();
String lname = name.toLowerCase(java.util.Locale.ENGLISH);
@@ -201,7 +209,7 @@ public class Permission {
* @param perm Parent permission to register with
* @param value The value to set this permission to
*/
public void addParent(Permission perm, boolean value) {
public void addParent(@NotNull Permission perm, boolean value) {
perm.getChildren().put(getName(), value);
perm.recalculatePermissibles();
}
@@ -221,11 +229,12 @@ public class Permission {
* </ul>
*
* @param data Map of permissions
* @param error An error message to show if a permission is invalid.
* @param error An error message to show if a permission is invalid. May contain "%s" format tag, which will be replaced with the name of invalid permission.
* @param def Default permission value to use if missing
* @return Permission object
*/
public static List<Permission> loadPermissions(Map<?, ?> data, String error, PermissionDefault def) {
@NotNull
public static List<Permission> loadPermissions(@NotNull Map<?, ?> data, @NotNull String error, @Nullable PermissionDefault def) {
List<Permission> result = new ArrayList<Permission>();
for (Map.Entry<?, ?> entry : data.entrySet()) {
@@ -256,7 +265,8 @@ public class Permission {
* @param data Map of keys
* @return Permission object
*/
public static Permission loadPermission(String name, Map<String, Object> data) {
@NotNull
public static Permission loadPermission(@NotNull String name, @NotNull Map<String, Object> data) {
return loadPermission(name, data, DEFAULT_PERMISSION, null);
}
@@ -279,7 +289,8 @@ public class Permission {
* @param output A list to append any created child-Permissions to, may be null
* @return Permission object
*/
public static Permission loadPermission(String name, Map<?, ?> data, PermissionDefault def, List<Permission> output) {
@NotNull
public static Permission loadPermission(@NotNull String name, @NotNull Map<?, ?> data, @Nullable PermissionDefault def, @Nullable List<Permission> output) {
Validate.notNull(name, "Name cannot be null");
Validate.notNull(data, "Data cannot be null");
@@ -318,7 +329,8 @@ public class Permission {
return new Permission(name, desc, def, children);
}
private static Map<String, Boolean> extractChildren(Map<?, ?> input, String name, PermissionDefault def, List<Permission> output) {
@NotNull
private static Map<String, Boolean> extractChildren(@NotNull Map<?, ?> input, @NotNull String name, @Nullable PermissionDefault def, @Nullable List<Permission> output) {
Map<String, Boolean> children = new LinkedHashMap<String, Boolean>();
for (Map.Entry<?, ?> entry : input.entrySet()) {

View File

@@ -3,6 +3,8 @@ package org.bukkit.permissions;
import java.util.LinkedHashMap;
import java.util.Map;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Holds information about a permission attachment on a {@link Permissible}
@@ -14,14 +16,14 @@ public class PermissionAttachment {
private final Permissible permissible;
private final Plugin plugin;
public PermissionAttachment(Plugin plugin, Permissible Permissible) {
public PermissionAttachment(@NotNull Plugin plugin, @NotNull Permissible permissible) {
if (plugin == null) {
throw new IllegalArgumentException("Plugin cannot be null");
} else if (!plugin.isEnabled()) {
throw new IllegalArgumentException("Plugin " + plugin.getDescription().getFullName() + " is disabled");
}
this.permissible = Permissible;
this.permissible = permissible;
this.plugin = plugin;
}
@@ -30,6 +32,7 @@ public class PermissionAttachment {
*
* @return Plugin responsible for this permission attachment
*/
@NotNull
public Plugin getPlugin() {
return plugin;
}
@@ -40,7 +43,7 @@ public class PermissionAttachment {
*
* @param ex Object to be called when this is removed
*/
public void setRemovalCallback(PermissionRemovedExecutor ex) {
public void setRemovalCallback(@Nullable PermissionRemovedExecutor ex) {
removed = ex;
}
@@ -50,6 +53,7 @@ public class PermissionAttachment {
*
* @return Object to be called when this is removed
*/
@Nullable
public PermissionRemovedExecutor getRemovalCallback() {
return removed;
}
@@ -59,6 +63,7 @@ public class PermissionAttachment {
*
* @return Permissible containing this attachment
*/
@NotNull
public Permissible getPermissible() {
return permissible;
}
@@ -72,6 +77,7 @@ public class PermissionAttachment {
*
* @return Copy of all permissions and values expressed by this attachment
*/
@NotNull
public Map<String, Boolean> getPermissions() {
return new LinkedHashMap<String, Boolean>(permissions);
}
@@ -82,7 +88,7 @@ public class PermissionAttachment {
* @param name Name of the permission
* @param value New value of the permission
*/
public void setPermission(String name, boolean value) {
public void setPermission(@NotNull String name, boolean value) {
permissions.put(name.toLowerCase(java.util.Locale.ENGLISH), value);
permissible.recalculatePermissions();
}
@@ -93,7 +99,7 @@ public class PermissionAttachment {
* @param perm Permission to set
* @param value New value of the permission
*/
public void setPermission(Permission perm, boolean value) {
public void setPermission(@NotNull Permission perm, boolean value) {
setPermission(perm.getName(), value);
}
@@ -105,7 +111,7 @@ public class PermissionAttachment {
*
* @param name Name of the permission to remove
*/
public void unsetPermission(String name) {
public void unsetPermission(@NotNull String name) {
permissions.remove(name.toLowerCase(java.util.Locale.ENGLISH));
permissible.recalculatePermissions();
}
@@ -118,7 +124,7 @@ public class PermissionAttachment {
*
* @param perm Permission to remove
*/
public void unsetPermission(Permission perm) {
public void unsetPermission(@NotNull Permission perm) {
unsetPermission(perm.getName());
}

View File

@@ -1,5 +1,8 @@
package org.bukkit.permissions;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Holds information on a permission and which {@link PermissionAttachment}
* provides it
@@ -10,11 +13,11 @@ public class PermissionAttachmentInfo {
private final PermissionAttachment attachment;
private final boolean value;
public PermissionAttachmentInfo(Permissible permissible, String permission, PermissionAttachment attachment, boolean value) {
public PermissionAttachmentInfo(@NotNull Permissible permissible, @NotNull String permission, @Nullable PermissionAttachment attachment, boolean value) {
if (permissible == null) {
throw new IllegalArgumentException("Permissible may not be null");
} else if (permission == null) {
throw new IllegalArgumentException("Permissions may not be null");
throw new IllegalArgumentException("Permission may not be null");
}
this.permissible = permissible;
@@ -28,6 +31,7 @@ public class PermissionAttachmentInfo {
*
* @return Permissible this permission is for
*/
@NotNull
public Permissible getPermissible() {
return permissible;
}
@@ -37,6 +41,7 @@ public class PermissionAttachmentInfo {
*
* @return Name of the permission
*/
@NotNull
public String getPermission() {
return permission;
}
@@ -47,6 +52,7 @@ public class PermissionAttachmentInfo {
*
* @return Attachment
*/
@Nullable
public PermissionAttachment getAttachment() {
return attachment;
}

View File

@@ -1,5 +1,8 @@
package org.bukkit.permissions;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.Map;
@@ -15,7 +18,7 @@ public enum PermissionDefault {
private final String[] names;
private final static Map<String, PermissionDefault> lookup = new HashMap<String, PermissionDefault>();
private PermissionDefault(String... names) {
private PermissionDefault(@NotNull String... names) {
this.names = names;
}
@@ -47,7 +50,8 @@ public enum PermissionDefault {
* @param name Name of the default
* @return Specified value, or null if not found
*/
public static PermissionDefault getByName(String name) {
@Nullable
public static PermissionDefault getByName(@NotNull String name) {
return lookup.get(name.toLowerCase(java.util.Locale.ENGLISH).replaceAll("[^a-z!]", ""));
}

View File

@@ -1,5 +1,7 @@
package org.bukkit.permissions;
import org.jetbrains.annotations.NotNull;
/**
* Represents a class which is to be notified when a {@link
* PermissionAttachment} is removed from a {@link Permissible}
@@ -12,5 +14,5 @@ public interface PermissionRemovedExecutor {
*
* @param attachment Attachment which was removed
*/
public void attachmentRemoved(PermissionAttachment attachment);
public void attachmentRemoved(@NotNull PermissionAttachment attachment);
}