mirror of
https://github.com/PaperMC/Paper.git
synced 2025-09-01 12:53:52 -07:00
SPIGOT-2540: Add nullability annotations to entire Bukkit API
By: Darkyenus <darkyenus@gmail.com>
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
package org.bukkit.attribute;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Represents an object which may contain attributes.
|
||||
*/
|
||||
@@ -12,5 +15,6 @@ public interface Attributable {
|
||||
* @param attribute the attribute to get
|
||||
* @return the attribute instance or null if not applicable to this object
|
||||
*/
|
||||
AttributeInstance getAttribute(Attribute attribute);
|
||||
@Nullable
|
||||
AttributeInstance getAttribute(@NotNull Attribute attribute);
|
||||
}
|
||||
|
@@ -1,5 +1,7 @@
|
||||
package org.bukkit.attribute;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
@@ -13,6 +15,7 @@ public interface AttributeInstance {
|
||||
*
|
||||
* @return the attribute
|
||||
*/
|
||||
@NotNull
|
||||
Attribute getAttribute();
|
||||
|
||||
/**
|
||||
@@ -34,6 +37,7 @@ public interface AttributeInstance {
|
||||
*
|
||||
* @return a copied collection of all modifiers
|
||||
*/
|
||||
@NotNull
|
||||
Collection<AttributeModifier> getModifiers();
|
||||
|
||||
/**
|
||||
@@ -41,14 +45,14 @@ public interface AttributeInstance {
|
||||
*
|
||||
* @param modifier to add
|
||||
*/
|
||||
void addModifier(AttributeModifier modifier);
|
||||
void addModifier(@NotNull AttributeModifier modifier);
|
||||
|
||||
/**
|
||||
* Remove a modifier from this instance.
|
||||
*
|
||||
* @param modifier to remove
|
||||
*/
|
||||
void removeModifier(AttributeModifier modifier);
|
||||
void removeModifier(@NotNull AttributeModifier modifier);
|
||||
|
||||
/**
|
||||
* Get the value of this instance after all associated modifiers have been
|
||||
|
@@ -8,6 +8,8 @@ import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.util.NumberConversions;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Concrete implementation of an attribute modifier.
|
||||
@@ -20,15 +22,15 @@ public class AttributeModifier implements ConfigurationSerializable {
|
||||
private final Operation operation;
|
||||
private final EquipmentSlot slot;
|
||||
|
||||
public AttributeModifier(String name, double amount, Operation operation) {
|
||||
public AttributeModifier(@NotNull String name, double amount, @NotNull Operation operation) {
|
||||
this(UUID.randomUUID(), name, amount, operation);
|
||||
}
|
||||
|
||||
public AttributeModifier(UUID uuid, String name, double amount, Operation operation) {
|
||||
public AttributeModifier(@NotNull UUID uuid, @NotNull String name, double amount, @NotNull Operation operation) {
|
||||
this(uuid, name, amount, operation, null);
|
||||
}
|
||||
|
||||
public AttributeModifier(UUID uuid, String name, double amount, Operation operation, EquipmentSlot slot) {
|
||||
public AttributeModifier(@NotNull UUID uuid, @NotNull String name, double amount, @NotNull Operation operation, @Nullable EquipmentSlot slot) {
|
||||
Validate.notNull(uuid, "UUID cannot be null");
|
||||
Validate.notEmpty(name, "Name cannot be empty");
|
||||
Validate.notNull(operation, "Operation cannot be null");
|
||||
@@ -44,6 +46,7 @@ public class AttributeModifier implements ConfigurationSerializable {
|
||||
*
|
||||
* @return unique id
|
||||
*/
|
||||
@NotNull
|
||||
public UUID getUniqueId() {
|
||||
return uuid;
|
||||
}
|
||||
@@ -53,6 +56,7 @@ public class AttributeModifier implements ConfigurationSerializable {
|
||||
*
|
||||
* @return name
|
||||
*/
|
||||
@NotNull
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
@@ -71,6 +75,7 @@ public class AttributeModifier implements ConfigurationSerializable {
|
||||
*
|
||||
* @return operation
|
||||
*/
|
||||
@NotNull
|
||||
public Operation getOperation() {
|
||||
return operation;
|
||||
}
|
||||
@@ -81,10 +86,12 @@ public class AttributeModifier implements ConfigurationSerializable {
|
||||
*
|
||||
* @return the slot
|
||||
*/
|
||||
@Nullable
|
||||
public EquipmentSlot getSlot() {
|
||||
return slot;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Map<String, Object> serialize() {
|
||||
Map<String, Object> data = new HashMap<String, Object>();
|
||||
@@ -130,7 +137,8 @@ public class AttributeModifier implements ConfigurationSerializable {
|
||||
+ "}";
|
||||
}
|
||||
|
||||
public static AttributeModifier deserialize(Map<String, Object> args) {
|
||||
@NotNull
|
||||
public static AttributeModifier deserialize(@NotNull Map<String, Object> args) {
|
||||
if (args.containsKey("slot")) {
|
||||
return new AttributeModifier(UUID.fromString((String) args.get("uuid")), (String) args.get("name"), NumberConversions.toDouble(args.get("amount")), Operation.values()[NumberConversions.toInt(args.get("operation"))], EquipmentSlot.valueOf((args.get("slot").toString().toUpperCase())));
|
||||
}
|
||||
|
Reference in New Issue
Block a user