mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-31 04:13:51 -07:00
SPIGOT-2540: Add nullability annotations to entire Bukkit API
By: Darkyenus <darkyenus@gmail.com>
This commit is contained in:
@@ -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;
|
||||
|
@@ -1,5 +1,7 @@
|
||||
package org.bukkit.potion;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
@@ -16,7 +18,8 @@ public interface PotionBrewer {
|
||||
* @param amplifier The amplifier of the effect
|
||||
* @return The resulting potion effect
|
||||
*/
|
||||
public PotionEffect createEffect(PotionEffectType potion, int duration, int amplifier);
|
||||
@NotNull
|
||||
public PotionEffect createEffect(@NotNull PotionEffectType potion, int duration, int amplifier);
|
||||
|
||||
/**
|
||||
* Returns a collection of {@link PotionEffect} that would be applied from
|
||||
@@ -27,6 +30,7 @@ public interface PotionBrewer {
|
||||
* @deprecated Non-Functional
|
||||
*/
|
||||
@Deprecated
|
||||
@NotNull
|
||||
public Collection<PotionEffect> getEffectsFromDamage(int damage);
|
||||
|
||||
/**
|
||||
@@ -36,5 +40,6 @@ public interface PotionBrewer {
|
||||
* @param type The type of the potion
|
||||
* @return The list of effects
|
||||
*/
|
||||
public Collection<PotionEffect> getEffects(PotionType type, boolean upgraded, boolean extended);
|
||||
@NotNull
|
||||
public Collection<PotionEffect> getEffects(@NotNull PotionType type, boolean upgraded, boolean extended);
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package org.bukkit.potion;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class PotionData {
|
||||
|
||||
@@ -18,7 +19,7 @@ public final class PotionData {
|
||||
* @param upgraded whether the potion is upgraded PotionType#isUpgradable()
|
||||
* must be true
|
||||
*/
|
||||
public PotionData(PotionType type, boolean extended, boolean upgraded) {
|
||||
public PotionData(@NotNull PotionType type, boolean extended, boolean upgraded) {
|
||||
Validate.notNull(type, "Potion Type must not be null");
|
||||
Validate.isTrue(!upgraded || type.isUpgradeable(), "Potion Type is not upgradable");
|
||||
Validate.isTrue(!extended || type.isExtendable(), "Potion Type is not extendable");
|
||||
@@ -28,7 +29,7 @@ public final class PotionData {
|
||||
this.upgraded = upgraded;
|
||||
}
|
||||
|
||||
public PotionData(PotionType type) {
|
||||
public PotionData(@NotNull PotionType type) {
|
||||
this(type, false, false);
|
||||
}
|
||||
|
||||
@@ -38,6 +39,7 @@ public final class PotionData {
|
||||
*
|
||||
* @return the potion type
|
||||
*/
|
||||
@NotNull
|
||||
public PotionType getType() {
|
||||
return type;
|
||||
}
|
||||
|
@@ -10,6 +10,9 @@ import org.bukkit.configuration.serialization.SerializableAs;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Represents a potion effect, that can be added to a {@link LivingEntity}. A
|
||||
@@ -42,7 +45,7 @@ public class PotionEffect implements ConfigurationSerializable {
|
||||
* @param particles the particle status, see {@link PotionEffect#hasParticles()}
|
||||
* @param icon the icon status, see {@link PotionEffect#hasIcon()}
|
||||
*/
|
||||
public PotionEffect(PotionEffectType type, int duration, int amplifier, boolean ambient, boolean particles, boolean icon) {
|
||||
public PotionEffect(@NotNull PotionEffectType type, int duration, int amplifier, boolean ambient, boolean particles, boolean icon) {
|
||||
Validate.notNull(type, "effect type cannot be null");
|
||||
this.type = type;
|
||||
this.duration = duration;
|
||||
@@ -62,7 +65,7 @@ public class PotionEffect implements ConfigurationSerializable {
|
||||
* @param ambient the ambient status, see {@link PotionEffect#isAmbient()}
|
||||
* @param particles the particle status, see {@link PotionEffect#hasParticles()}
|
||||
*/
|
||||
public PotionEffect(PotionEffectType type, int duration, int amplifier, boolean ambient, boolean particles) {
|
||||
public PotionEffect(@NotNull PotionEffectType type, int duration, int amplifier, boolean ambient, boolean particles) {
|
||||
this(type, duration, amplifier, ambient, particles, particles);
|
||||
}
|
||||
|
||||
@@ -75,7 +78,7 @@ public class PotionEffect implements ConfigurationSerializable {
|
||||
* @param amplifier the amplifier, see {@link PotionEffect#getAmplifier()}
|
||||
* @param ambient the ambient status, see {@link PotionEffect#isAmbient()}
|
||||
*/
|
||||
public PotionEffect(PotionEffectType type, int duration, int amplifier, boolean ambient) {
|
||||
public PotionEffect(@NotNull PotionEffectType type, int duration, int amplifier, boolean ambient) {
|
||||
this(type, duration, amplifier, ambient, true);
|
||||
}
|
||||
|
||||
@@ -87,7 +90,7 @@ public class PotionEffect implements ConfigurationSerializable {
|
||||
* @param amplifier the amplifier for the effect
|
||||
* @see PotionEffect#PotionEffect(PotionEffectType, int, int, boolean)
|
||||
*/
|
||||
public PotionEffect(PotionEffectType type, int duration, int amplifier) {
|
||||
public PotionEffect(@NotNull PotionEffectType type, int duration, int amplifier) {
|
||||
this(type, duration, amplifier, true);
|
||||
}
|
||||
|
||||
@@ -96,11 +99,12 @@ public class PotionEffect implements ConfigurationSerializable {
|
||||
*
|
||||
* @param map the map to deserialize from
|
||||
*/
|
||||
public PotionEffect(Map<String, Object> map) {
|
||||
public PotionEffect(@NotNull Map<String, Object> map) {
|
||||
this(getEffectType(map), getInt(map, DURATION), getInt(map, AMPLIFIER), getBool(map, AMBIENT, false), getBool(map, PARTICLES, true), getBool(map, ICON, getBool(map, PARTICLES, true)));
|
||||
}
|
||||
|
||||
private static PotionEffectType getEffectType(Map<?, ?> map) {
|
||||
@NotNull
|
||||
private static PotionEffectType getEffectType(@NotNull Map<?, ?> map) {
|
||||
int type = getInt(map, TYPE);
|
||||
PotionEffectType effect = PotionEffectType.getById(type);
|
||||
if (effect != null) {
|
||||
@@ -109,7 +113,7 @@ public class PotionEffect implements ConfigurationSerializable {
|
||||
throw new NoSuchElementException(map + " does not contain " + TYPE);
|
||||
}
|
||||
|
||||
private static int getInt(Map<?, ?> map, Object key) {
|
||||
private static int getInt(@NotNull Map<?, ?> map, @NotNull Object key) {
|
||||
Object num = map.get(key);
|
||||
if (num instanceof Integer) {
|
||||
return (Integer) num;
|
||||
@@ -117,7 +121,7 @@ public class PotionEffect implements ConfigurationSerializable {
|
||||
throw new NoSuchElementException(map + " does not contain " + key);
|
||||
}
|
||||
|
||||
private static boolean getBool(Map<?, ?> map, Object key, boolean def) {
|
||||
private static boolean getBool(@NotNull Map<?, ?> map, @NotNull Object key, boolean def) {
|
||||
Object bool = map.get(key);
|
||||
if (bool instanceof Boolean) {
|
||||
return (Boolean) bool;
|
||||
@@ -125,6 +129,7 @@ public class PotionEffect implements ConfigurationSerializable {
|
||||
return def;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Map<String, Object> serialize() {
|
||||
return ImmutableMap.<String, Object>builder()
|
||||
.put(TYPE, type.getId())
|
||||
@@ -144,7 +149,7 @@ public class PotionEffect implements ConfigurationSerializable {
|
||||
* @param entity The entity to add this effect to
|
||||
* @return Whether the effect could be added
|
||||
*/
|
||||
public boolean apply(LivingEntity entity) {
|
||||
public boolean apply(@NotNull LivingEntity entity) {
|
||||
return entity.addPotionEffect(this);
|
||||
}
|
||||
|
||||
@@ -186,6 +191,7 @@ public class PotionEffect implements ConfigurationSerializable {
|
||||
*
|
||||
* @return The potion type of this effect
|
||||
*/
|
||||
@NotNull
|
||||
public PotionEffectType getType() {
|
||||
return type;
|
||||
}
|
||||
@@ -211,6 +217,8 @@ public class PotionEffect implements ConfigurationSerializable {
|
||||
* @deprecated color is not part of potion effects
|
||||
*/
|
||||
@Deprecated
|
||||
@Nullable
|
||||
@Contract("-> null")
|
||||
public Color getColor() {
|
||||
return null;
|
||||
}
|
||||
|
@@ -6,6 +6,8 @@ import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Color;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Represents a type of potion and its effect on an entity.
|
||||
@@ -178,6 +180,7 @@ public abstract class PotionEffectType {
|
||||
* @param amplifier the effect's amplifier
|
||||
* @return a resulting potion effect
|
||||
*/
|
||||
@NotNull
|
||||
public PotionEffect createEffect(int duration, int amplifier) {
|
||||
return new PotionEffect(this, isInstant() ? 1 : (int) (duration * getDurationModifier()), amplifier);
|
||||
}
|
||||
@@ -205,6 +208,7 @@ public abstract class PotionEffectType {
|
||||
*
|
||||
* @return The name of this effect type
|
||||
*/
|
||||
@NotNull
|
||||
public abstract String getName();
|
||||
|
||||
/**
|
||||
@@ -219,6 +223,7 @@ public abstract class PotionEffectType {
|
||||
*
|
||||
* @return the color
|
||||
*/
|
||||
@NotNull
|
||||
public abstract Color getColor();
|
||||
|
||||
@Override
|
||||
@@ -259,6 +264,7 @@ public abstract class PotionEffectType {
|
||||
* @deprecated Magic value
|
||||
*/
|
||||
@Deprecated
|
||||
@Nullable
|
||||
public static PotionEffectType getById(int id) {
|
||||
if (id >= byId.length || id < 0)
|
||||
return null;
|
||||
@@ -271,7 +277,8 @@ public abstract class PotionEffectType {
|
||||
* @param name Name of PotionEffectType to fetch
|
||||
* @return Resulting PotionEffectType, or null if not found.
|
||||
*/
|
||||
public static PotionEffectType getByName(String name) {
|
||||
@Nullable
|
||||
public static PotionEffectType getByName(@NotNull String name) {
|
||||
Validate.notNull(name, "name cannot be null");
|
||||
return byName.get(name.toLowerCase(java.util.Locale.ENGLISH));
|
||||
}
|
||||
@@ -283,7 +290,7 @@ public abstract class PotionEffectType {
|
||||
*
|
||||
* @param type PotionType to register
|
||||
*/
|
||||
public static void registerPotionEffectType(PotionEffectType type) {
|
||||
public static void registerPotionEffectType(@NotNull PotionEffectType type) {
|
||||
if (byId[type.id] != null || byName.containsKey(type.getName().toLowerCase(java.util.Locale.ENGLISH))) {
|
||||
throw new IllegalArgumentException("Cannot set already-set type");
|
||||
} else if (!acceptingNew) {
|
||||
@@ -308,6 +315,7 @@ public abstract class PotionEffectType {
|
||||
*
|
||||
* @return Array of types.
|
||||
*/
|
||||
@NotNull
|
||||
public static PotionEffectType[] values() {
|
||||
return Arrays.copyOfRange(byId, 1, byId.length);
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package org.bukkit.potion;
|
||||
|
||||
import org.bukkit.Color;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class PotionEffectTypeWrapper extends PotionEffectType {
|
||||
protected PotionEffectTypeWrapper(int id) {
|
||||
@@ -12,6 +13,7 @@ public class PotionEffectTypeWrapper extends PotionEffectType {
|
||||
return getType().getDurationModifier();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getName() {
|
||||
return getType().getName();
|
||||
@@ -22,6 +24,7 @@ public class PotionEffectTypeWrapper extends PotionEffectType {
|
||||
*
|
||||
* @return The potion effect type
|
||||
*/
|
||||
@NotNull
|
||||
public PotionEffectType getType() {
|
||||
return PotionEffectType.getById(getId());
|
||||
}
|
||||
@@ -31,6 +34,7 @@ public class PotionEffectTypeWrapper extends PotionEffectType {
|
||||
return getType().isInstant();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Color getColor() {
|
||||
return getType().getColor();
|
||||
|
@@ -1,5 +1,8 @@
|
||||
package org.bukkit.potion;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* This enum reflects and matches each potion state that can be obtained from
|
||||
* the Creative mode inventory
|
||||
@@ -32,12 +35,13 @@ public enum PotionType {
|
||||
private final boolean upgradeable;
|
||||
private final boolean extendable;
|
||||
|
||||
PotionType(PotionEffectType effect, boolean upgradeable, boolean extendable) {
|
||||
PotionType(@Nullable PotionEffectType effect, boolean upgradeable, boolean extendable) {
|
||||
this.effect = effect;
|
||||
this.upgradeable = upgradeable;
|
||||
this.extendable = extendable;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public PotionEffectType getEffectType() {
|
||||
return effect;
|
||||
}
|
||||
@@ -83,6 +87,8 @@ public enum PotionType {
|
||||
* @deprecated Non-functional
|
||||
*/
|
||||
@Deprecated
|
||||
@Nullable
|
||||
@Contract("_ -> null")
|
||||
public static PotionType getByDamageValue(int damage) {
|
||||
return null;
|
||||
}
|
||||
@@ -91,7 +97,8 @@ public enum PotionType {
|
||||
* @deprecated Misleading
|
||||
*/
|
||||
@Deprecated
|
||||
public static PotionType getByEffect(PotionEffectType effectType) {
|
||||
@Nullable
|
||||
public static PotionType getByEffect(@Nullable PotionEffectType effectType) {
|
||||
if (effectType == null)
|
||||
return WATER;
|
||||
for (PotionType type : PotionType.values()) {
|
||||
|
Reference in New Issue
Block a user