SPIGOT-2540: Add nullability annotations to entire Bukkit API
By: Darkyenus <darkyenus@gmail.com>
This commit is contained in:
@@ -4,6 +4,8 @@ import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Represents additional information a {@link LootTable} can use to modify it's
|
||||
@@ -19,7 +21,7 @@ public final class LootContext {
|
||||
private final Entity lootedEntity;
|
||||
private final HumanEntity killer;
|
||||
|
||||
private LootContext(Location location, float luck, int lootingModifier, Entity lootedEntity, HumanEntity killer) {
|
||||
private LootContext(@NotNull Location location, float luck, int lootingModifier, @Nullable Entity lootedEntity, @Nullable HumanEntity killer) {
|
||||
Validate.notNull(location, "LootContext location cannot be null");
|
||||
Validate.notNull(location.getWorld(), "LootContext World cannot be null");
|
||||
this.location = location;
|
||||
@@ -34,6 +36,7 @@ public final class LootContext {
|
||||
*
|
||||
* @return the Location of where the loot will be generated
|
||||
*/
|
||||
@NotNull
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
@@ -69,6 +72,7 @@ public final class LootContext {
|
||||
*
|
||||
* @return the looted entity or null
|
||||
*/
|
||||
@Nullable
|
||||
public Entity getLootedEntity() {
|
||||
return lootedEntity;
|
||||
}
|
||||
@@ -79,6 +83,7 @@ public final class LootContext {
|
||||
*
|
||||
* @return the killer entity, or null.
|
||||
*/
|
||||
@Nullable
|
||||
public HumanEntity getKiller() {
|
||||
return killer;
|
||||
}
|
||||
@@ -102,7 +107,7 @@ public final class LootContext {
|
||||
*
|
||||
* @param location the location the LootContext should use
|
||||
*/
|
||||
public Builder(Location location) {
|
||||
public Builder(@NotNull Location location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
@@ -112,6 +117,7 @@ public final class LootContext {
|
||||
* @param luck the luck level
|
||||
* @return the Builder
|
||||
*/
|
||||
@NotNull
|
||||
public Builder luck(float luck) {
|
||||
this.luck = luck;
|
||||
return this;
|
||||
@@ -126,6 +132,7 @@ public final class LootContext {
|
||||
* @param modifier the looting level modifier
|
||||
* @return the Builder
|
||||
*/
|
||||
@NotNull
|
||||
public Builder lootingModifier(int modifier) {
|
||||
this.lootingModifier = modifier;
|
||||
return this;
|
||||
@@ -137,7 +144,8 @@ public final class LootContext {
|
||||
* @param lootedEntity the looted entity
|
||||
* @return the Builder
|
||||
*/
|
||||
public Builder lootedEntity(Entity lootedEntity) {
|
||||
@NotNull
|
||||
public Builder lootedEntity(@Nullable Entity lootedEntity) {
|
||||
this.lootedEntity = lootedEntity;
|
||||
return this;
|
||||
}
|
||||
@@ -150,7 +158,8 @@ public final class LootContext {
|
||||
* @param killer the killer entity
|
||||
* @return the Builder
|
||||
*/
|
||||
public Builder killer(HumanEntity killer) {
|
||||
@NotNull
|
||||
public Builder killer(@Nullable HumanEntity killer) {
|
||||
this.killer = killer;
|
||||
return this;
|
||||
}
|
||||
@@ -161,6 +170,7 @@ public final class LootContext {
|
||||
*
|
||||
* @return a new {@link LootContext} instance
|
||||
*/
|
||||
@NotNull
|
||||
public LootContext build() {
|
||||
return new LootContext(location, luck, lootingModifier, lootedEntity, killer);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.bukkit.loot;
|
||||
import org.bukkit.Keyed;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Random;
|
||||
@@ -24,7 +25,8 @@ public interface LootTable extends Keyed {
|
||||
* @param context context within to populate loot
|
||||
* @return a list of ItemStacks
|
||||
*/
|
||||
Collection<ItemStack> populateLoot(Random random, LootContext context);
|
||||
@NotNull
|
||||
Collection<ItemStack> populateLoot(@NotNull Random random, @NotNull LootContext context);
|
||||
|
||||
/**
|
||||
* Attempt to fill an inventory with this LootTable's loot.
|
||||
@@ -33,5 +35,5 @@ public interface LootTable extends Keyed {
|
||||
* @param random the random instance to use to generate loot
|
||||
* @param context context within to populate loot
|
||||
*/
|
||||
void fillInventory(Inventory inventory, Random random, LootContext context);
|
||||
void fillInventory(@NotNull Inventory inventory, @NotNull Random random, @NotNull LootContext context);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.bukkit.loot;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Keyed;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* This enum holds a list of all known {@link LootTable}s offered by Mojang.
|
||||
@@ -118,10 +119,11 @@ public enum LootTables implements Keyed {
|
||||
|
||||
private final String location;
|
||||
|
||||
private LootTables(String location) {
|
||||
private LootTables(@NotNull String location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public NamespacedKey getKey() {
|
||||
return NamespacedKey.minecraft(location);
|
||||
@@ -133,6 +135,7 @@ public enum LootTables implements Keyed {
|
||||
*
|
||||
* @return the associated LootTable
|
||||
*/
|
||||
@NotNull
|
||||
public LootTable getLootTable() {
|
||||
return Bukkit.getLootTable(getKey());
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.bukkit.loot;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Represents a {@link org.bukkit.block.Container} or a
|
||||
* {@link org.bukkit.entity.Mob} that can have a loot table.
|
||||
@@ -20,7 +22,7 @@ public interface Lootable {
|
||||
* @param table the Loot Table this {@link org.bukkit.block.Container} or
|
||||
* {@link org.bukkit.entity.Mob} will have.
|
||||
*/
|
||||
void setLootTable(LootTable table);
|
||||
void setLootTable(@Nullable LootTable table);
|
||||
|
||||
/**
|
||||
* Gets the Loot Table attached to this block or entity.
|
||||
@@ -31,6 +33,7 @@ public interface Lootable {
|
||||
*
|
||||
* @return the Loot Table attached to this block or entity.
|
||||
*/
|
||||
@Nullable
|
||||
LootTable getLootTable();
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user