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

@@ -7,6 +7,7 @@ import org.bukkit.Material;
import org.bukkit.entity.LivingEntity;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.PotionMeta;
import org.jetbrains.annotations.NotNull;
/**
* Potion Adapter for pre-1.9 data values
@@ -28,7 +29,7 @@ public class Potion {
* @param type The potion type
* @see #Potion(int)
*/
public Potion(PotionType type) {
public Potion(@NotNull PotionType type) {
Validate.notNull(type, "Null PotionType");
this.type = type;
}
@@ -39,7 +40,7 @@ public class Potion {
* @param type The type of potion.
* @param level The potion's level.
*/
public Potion(PotionType type, int level) {
public Potion(@NotNull PotionType type, int level) {
this(type);
Validate.notNull(type, "Type cannot be null");
Validate.isTrue(level > 0 && level < 3, "Level must be 1 or 2");
@@ -56,7 +57,7 @@ public class Potion {
* #splash()}.
*/
@Deprecated
public Potion(PotionType type, int level, boolean splash) {
public Potion(@NotNull PotionType type, int level, boolean splash) {
this(type, level);
this.splash = splash;
}
@@ -72,7 +73,7 @@ public class Potion {
* #extend()} and possibly {@link #splash()}.
*/
@Deprecated
public Potion(PotionType type, int level, boolean splash, boolean extended) {
public Potion(@NotNull PotionType type, int level, boolean splash, boolean extended) {
this(type, level, splash);
this.extended = extended;
}
@@ -90,6 +91,7 @@ public class Potion {
*
* @return The potion.
*/
@NotNull
public Potion splash() {
setSplash(true);
return this;
@@ -100,6 +102,7 @@ public class Potion {
*
* @return The potion.
*/
@NotNull
public Potion extend() {
setHasExtendedDuration(true);
return this;
@@ -111,7 +114,7 @@ public class Potion {
*
* @param to The itemstack to apply to
*/
public void apply(ItemStack to) {
public void apply(@NotNull ItemStack to) {
Validate.notNull(to, "itemstack cannot be null");
Validate.isTrue(to.hasItemMeta(), "given itemstack is not a potion");
Validate.isTrue(to.getItemMeta() instanceof PotionMeta, "given itemstack is not a potion");
@@ -127,7 +130,7 @@ public class Potion {
* @see LivingEntity#addPotionEffects(Collection)
* @param to The entity to apply the effects to
*/
public void apply(LivingEntity to) {
public void apply(@NotNull LivingEntity to) {
Validate.notNull(to, "entity cannot be null");
to.addPotionEffects(getEffects());
}
@@ -152,6 +155,7 @@ public class Potion {
* @see Potion#toDamageValue()
* @return The effects that this potion applies
*/
@NotNull
public Collection<PotionEffect> getEffects() {
return getBrewer().getEffects(type, level == 2, extended);
}
@@ -170,6 +174,7 @@ public class Potion {
*
* @return The type of this potion
*/
@NotNull
public PotionType getType() {
return type;
}
@@ -228,7 +233,7 @@ public class Potion {
*
* @param type The new type of this potion
*/
public void setType(PotionType type) {
public void setType(@NotNull PotionType type) {
this.type = type;
}
@@ -262,6 +267,7 @@ public class Potion {
* @param amount The amount of the ItemStack
* @return The created ItemStack
*/
@NotNull
public ItemStack toItemStack(int amount) {
Material material;
if (isSplash()) {
@@ -289,6 +295,7 @@ public class Potion {
* @param damage the damage value
* @return the produced potion
*/
@NotNull
public static Potion fromDamage(int damage) {
PotionType type;
switch (damage & POTION_BIT) {
@@ -354,7 +361,8 @@ public class Potion {
return potion;
}
public static Potion fromItemStack(ItemStack item) {
@NotNull
public static Potion fromItemStack(@NotNull ItemStack item) {
Validate.notNull(item, "item cannot be null");
if (item.getType() != Material.POTION)
throw new IllegalArgumentException("item is not a potion");
@@ -366,6 +374,7 @@ public class Potion {
*
* @return An instance of PotionBrewer
*/
@NotNull
public static PotionBrewer getBrewer() {
return brewer;
}
@@ -376,7 +385,7 @@ public class Potion {
*
* @param other The new PotionBrewer
*/
public static void setPotionBrewer(PotionBrewer other) {
public static void setPotionBrewer(@NotNull PotionBrewer other) {
if (brewer != null)
throw new IllegalArgumentException("brewer can only be set internally");
brewer = other;