SPIGOT-2540: Add nullability annotations to entire Bukkit API
By: Darkyenus <darkyenus@gmail.com>
This commit is contained in:
@@ -6,6 +6,9 @@ import java.util.Map;
|
||||
import org.bukkit.Keyed;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* The various type of enchantments that may be added to armour or weapons
|
||||
@@ -188,10 +191,11 @@ public abstract class Enchantment implements Keyed {
|
||||
private static boolean acceptingNew = true;
|
||||
private final NamespacedKey key;
|
||||
|
||||
public Enchantment(NamespacedKey key) {
|
||||
public Enchantment(@NotNull NamespacedKey key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public NamespacedKey getKey() {
|
||||
return key;
|
||||
@@ -203,6 +207,7 @@ public abstract class Enchantment implements Keyed {
|
||||
* @return Unique name
|
||||
* @deprecated enchantments are badly named, use {@link #getKey()}.
|
||||
*/
|
||||
@NotNull
|
||||
@Deprecated
|
||||
public abstract String getName();
|
||||
|
||||
@@ -225,6 +230,7 @@ public abstract class Enchantment implements Keyed {
|
||||
*
|
||||
* @return Target type of the Enchantment
|
||||
*/
|
||||
@NotNull
|
||||
public abstract EnchantmentTarget getItemTarget();
|
||||
|
||||
/**
|
||||
@@ -256,7 +262,7 @@ public abstract class Enchantment implements Keyed {
|
||||
* @param other The enchantment to check against
|
||||
* @return True if there is a conflict.
|
||||
*/
|
||||
public abstract boolean conflictsWith(Enchantment other);
|
||||
public abstract boolean conflictsWith(@NotNull Enchantment other);
|
||||
|
||||
/**
|
||||
* Checks if this Enchantment may be applied to the given {@link
|
||||
@@ -268,7 +274,7 @@ public abstract class Enchantment implements Keyed {
|
||||
* @param item Item to test
|
||||
* @return True if the enchantment may be applied, otherwise False
|
||||
*/
|
||||
public abstract boolean canEnchantItem(ItemStack item);
|
||||
public abstract boolean canEnchantItem(@NotNull ItemStack item);
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
@@ -302,7 +308,7 @@ public abstract class Enchantment implements Keyed {
|
||||
*
|
||||
* @param enchantment Enchantment to register
|
||||
*/
|
||||
public static void registerEnchantment(Enchantment enchantment) {
|
||||
public static void registerEnchantment(@NotNull Enchantment enchantment) {
|
||||
if (byKey.containsKey(enchantment.key) || byName.containsKey(enchantment.getName())) {
|
||||
throw new IllegalArgumentException("Cannot set already-set enchantment");
|
||||
} else if (!isAcceptingRegistrations()) {
|
||||
@@ -335,7 +341,9 @@ public abstract class Enchantment implements Keyed {
|
||||
* @param key key to fetch
|
||||
* @return Resulting Enchantment, or null if not found
|
||||
*/
|
||||
public static Enchantment getByKey(NamespacedKey key) {
|
||||
@Contract("null -> null")
|
||||
@Nullable
|
||||
public static Enchantment getByKey(@Nullable NamespacedKey key) {
|
||||
return byKey.get(key);
|
||||
}
|
||||
|
||||
@@ -347,7 +355,9 @@ public abstract class Enchantment implements Keyed {
|
||||
* @deprecated enchantments are badly named, use {@link #getByKey(org.bukkit.NamespacedKey)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public static Enchantment getByName(String name) {
|
||||
@Contract("null -> null")
|
||||
@Nullable
|
||||
public static Enchantment getByName(@Nullable String name) {
|
||||
return byName.get(name);
|
||||
}
|
||||
|
||||
@@ -356,6 +366,7 @@ public abstract class Enchantment implements Keyed {
|
||||
*
|
||||
* @return Array of enchantments
|
||||
*/
|
||||
@NotNull
|
||||
public static Enchantment[] values() {
|
||||
return byName.values().toArray(new Enchantment[byName.size()]);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.bukkit.enchantments;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A class for the available enchantment offers in the enchantment table.
|
||||
@@ -11,7 +12,7 @@ public class EnchantmentOffer {
|
||||
private int enchantmentLevel;
|
||||
private int cost;
|
||||
|
||||
public EnchantmentOffer(Enchantment enchantment, int enchantmentLevel, int cost) {
|
||||
public EnchantmentOffer(@NotNull Enchantment enchantment, int enchantmentLevel, int cost) {
|
||||
this.enchantment = enchantment;
|
||||
this.enchantmentLevel = enchantmentLevel;
|
||||
this.cost = cost;
|
||||
@@ -22,6 +23,7 @@ public class EnchantmentOffer {
|
||||
*
|
||||
* @return type of enchantment
|
||||
*/
|
||||
@NotNull
|
||||
public Enchantment getEnchantment() {
|
||||
return enchantment;
|
||||
}
|
||||
@@ -31,7 +33,7 @@ public class EnchantmentOffer {
|
||||
*
|
||||
* @param enchantment type of the enchantment
|
||||
*/
|
||||
public void setEnchantment(Enchantment enchantment) {
|
||||
public void setEnchantment(@NotNull Enchantment enchantment) {
|
||||
Validate.notNull(enchantment, "The enchantment may not be null!");
|
||||
|
||||
this.enchantment = enchantment;
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.bukkit.enchantments;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Represents the applicable target for a {@link Enchantment}
|
||||
@@ -12,7 +13,7 @@ public enum EnchantmentTarget {
|
||||
*/
|
||||
ALL {
|
||||
@Override
|
||||
public boolean includes(Material item) {
|
||||
public boolean includes(@NotNull Material item) {
|
||||
return true;
|
||||
}
|
||||
},
|
||||
@@ -22,7 +23,7 @@ public enum EnchantmentTarget {
|
||||
*/
|
||||
ARMOR {
|
||||
@Override
|
||||
public boolean includes(Material item) {
|
||||
public boolean includes(@NotNull Material item) {
|
||||
return ARMOR_FEET.includes(item)
|
||||
|| ARMOR_LEGS.includes(item)
|
||||
|| ARMOR_HEAD.includes(item)
|
||||
@@ -35,7 +36,7 @@ public enum EnchantmentTarget {
|
||||
*/
|
||||
ARMOR_FEET {
|
||||
@Override
|
||||
public boolean includes(Material item) {
|
||||
public boolean includes(@NotNull Material item) {
|
||||
return item.equals(Material.LEATHER_BOOTS)
|
||||
|| item.equals(Material.CHAINMAIL_BOOTS)
|
||||
|| item.equals(Material.IRON_BOOTS)
|
||||
@@ -49,7 +50,7 @@ public enum EnchantmentTarget {
|
||||
*/
|
||||
ARMOR_LEGS {
|
||||
@Override
|
||||
public boolean includes(Material item) {
|
||||
public boolean includes(@NotNull Material item) {
|
||||
return item.equals(Material.LEATHER_LEGGINGS)
|
||||
|| item.equals(Material.CHAINMAIL_LEGGINGS)
|
||||
|| item.equals(Material.IRON_LEGGINGS)
|
||||
@@ -63,7 +64,7 @@ public enum EnchantmentTarget {
|
||||
*/
|
||||
ARMOR_TORSO {
|
||||
@Override
|
||||
public boolean includes(Material item) {
|
||||
public boolean includes(@NotNull Material item) {
|
||||
return item.equals(Material.LEATHER_CHESTPLATE)
|
||||
|| item.equals(Material.CHAINMAIL_CHESTPLATE)
|
||||
|| item.equals(Material.IRON_CHESTPLATE)
|
||||
@@ -77,7 +78,7 @@ public enum EnchantmentTarget {
|
||||
*/
|
||||
ARMOR_HEAD {
|
||||
@Override
|
||||
public boolean includes(Material item) {
|
||||
public boolean includes(@NotNull Material item) {
|
||||
return item.equals(Material.LEATHER_HELMET)
|
||||
|| item.equals(Material.CHAINMAIL_HELMET)
|
||||
|| item.equals(Material.DIAMOND_HELMET)
|
||||
@@ -91,7 +92,7 @@ public enum EnchantmentTarget {
|
||||
*/
|
||||
WEAPON {
|
||||
@Override
|
||||
public boolean includes(Material item) {
|
||||
public boolean includes(@NotNull Material item) {
|
||||
return item.equals(Material.WOODEN_SWORD)
|
||||
|| item.equals(Material.STONE_SWORD)
|
||||
|| item.equals(Material.IRON_SWORD)
|
||||
@@ -106,7 +107,7 @@ public enum EnchantmentTarget {
|
||||
*/
|
||||
TOOL {
|
||||
@Override
|
||||
public boolean includes(Material item) {
|
||||
public boolean includes(@NotNull Material item) {
|
||||
return item.equals(Material.WOODEN_SHOVEL)
|
||||
|| item.equals(Material.STONE_SHOVEL)
|
||||
|| item.equals(Material.IRON_SHOVEL)
|
||||
@@ -137,7 +138,7 @@ public enum EnchantmentTarget {
|
||||
*/
|
||||
BOW {
|
||||
@Override
|
||||
public boolean includes(Material item) {
|
||||
public boolean includes(@NotNull Material item) {
|
||||
return item.equals(Material.BOW);
|
||||
}
|
||||
},
|
||||
@@ -147,7 +148,7 @@ public enum EnchantmentTarget {
|
||||
*/
|
||||
FISHING_ROD {
|
||||
@Override
|
||||
public boolean includes(Material item) {
|
||||
public boolean includes(@NotNull Material item) {
|
||||
return item.equals(Material.FISHING_ROD);
|
||||
}
|
||||
},
|
||||
@@ -157,7 +158,7 @@ public enum EnchantmentTarget {
|
||||
*/
|
||||
BREAKABLE {
|
||||
@Override
|
||||
public boolean includes(Material item) {
|
||||
public boolean includes(@NotNull Material item) {
|
||||
return item.getMaxDurability() > 0 && item.getMaxStackSize() == 1;
|
||||
}
|
||||
},
|
||||
@@ -167,7 +168,7 @@ public enum EnchantmentTarget {
|
||||
*/
|
||||
WEARABLE {
|
||||
@Override
|
||||
public boolean includes(Material item) {
|
||||
public boolean includes(@NotNull Material item) {
|
||||
return ARMOR.includes(item)
|
||||
|| item.equals(Material.ELYTRA)
|
||||
|| item.equals(Material.PUMPKIN)
|
||||
@@ -187,7 +188,7 @@ public enum EnchantmentTarget {
|
||||
*/
|
||||
TRIDENT {
|
||||
@Override
|
||||
public boolean includes(Material item) {
|
||||
public boolean includes(@NotNull Material item) {
|
||||
return item.equals(Material.TRIDENT);
|
||||
}
|
||||
};
|
||||
@@ -198,7 +199,7 @@ public enum EnchantmentTarget {
|
||||
* @param item The item to check
|
||||
* @return True if the target includes the item
|
||||
*/
|
||||
public abstract boolean includes(Material item);
|
||||
public abstract boolean includes(@NotNull Material item);
|
||||
|
||||
/**
|
||||
* Check whether this target includes the specified item.
|
||||
@@ -206,7 +207,7 @@ public enum EnchantmentTarget {
|
||||
* @param item The item to check
|
||||
* @return True if the target includes the item
|
||||
*/
|
||||
public boolean includes(ItemStack item) {
|
||||
public boolean includes(@NotNull ItemStack item) {
|
||||
return includes(item.getType());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,13 @@ package org.bukkit.enchantments;
|
||||
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A simple wrapper for ease of selecting {@link Enchantment}s
|
||||
*/
|
||||
public class EnchantmentWrapper extends Enchantment {
|
||||
public EnchantmentWrapper(String name) {
|
||||
public EnchantmentWrapper(@NotNull String name) {
|
||||
super(NamespacedKey.minecraft(name));
|
||||
}
|
||||
|
||||
@@ -16,6 +17,7 @@ public class EnchantmentWrapper extends Enchantment {
|
||||
*
|
||||
* @return Enchantment
|
||||
*/
|
||||
@NotNull
|
||||
public Enchantment getEnchantment() {
|
||||
return Enchantment.getByKey(getKey());
|
||||
}
|
||||
@@ -30,16 +32,18 @@ public class EnchantmentWrapper extends Enchantment {
|
||||
return getEnchantment().getStartLevel();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public EnchantmentTarget getItemTarget() {
|
||||
return getEnchantment().getItemTarget();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canEnchantItem(ItemStack item) {
|
||||
public boolean canEnchantItem(@NotNull ItemStack item) {
|
||||
return getEnchantment().canEnchantItem(item);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getName() {
|
||||
return getEnchantment().getName();
|
||||
@@ -56,7 +60,7 @@ public class EnchantmentWrapper extends Enchantment {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean conflictsWith(Enchantment other) {
|
||||
public boolean conflictsWith(@NotNull Enchantment other) {
|
||||
return getEnchantment().conflictsWith(other);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user