Add some @NotNulls

This commit is contained in:
NichtStudioCode 2023-02-26 15:59:42 +01:00
parent 4f6dee6861
commit e8a6176d75
15 changed files with 183 additions and 156 deletions

@ -694,91 +694,91 @@ public abstract class AbstractGui implements Gui, GuiParent {
protected List<Consumer<Gui>> modifiers; protected List<Consumer<Gui>> modifiers;
@Override @Override
public S setStructure(int width, int height, @NotNull String structureData) { public @NotNull S setStructure(int width, int height, @NotNull String structureData) {
structure = new Structure(width, height, structureData); structure = new Structure(width, height, structureData);
return (S) this; return (S) this;
} }
@Override @Override
public S setStructure(@NotNull String... structureData) { public @NotNull S setStructure(@NotNull String... structureData) {
structure = new Structure(structureData); structure = new Structure(structureData);
return (S) this; return (S) this;
} }
@Override @Override
public S setStructure(@NotNull Structure structure) { public @NotNull S setStructure(@NotNull Structure structure) {
this.structure = structure; this.structure = structure;
return (S) this; return (S) this;
} }
@Override @Override
public S addIngredient(char key, @NotNull ItemStack itemStack) { public @NotNull S addIngredient(char key, @NotNull ItemStack itemStack) {
structure.addIngredient(key, itemStack); structure.addIngredient(key, itemStack);
return (S) this; return (S) this;
} }
@Override @Override
public S addIngredient(char key, @NotNull ItemProvider itemProvider) { public @NotNull S addIngredient(char key, @NotNull ItemProvider itemProvider) {
structure.addIngredient(key, itemProvider); structure.addIngredient(key, itemProvider);
return (S) this; return (S) this;
} }
@Override @Override
public S addIngredient(char key, @NotNull Item item) { public @NotNull S addIngredient(char key, @NotNull Item item) {
structure.addIngredient(key, item); structure.addIngredient(key, item);
return (S) this; return (S) this;
} }
@Override @Override
public S addIngredient(char key, @NotNull VirtualInventory inventory) { public @NotNull S addIngredient(char key, @NotNull VirtualInventory inventory) {
structure.addIngredient(key, inventory); structure.addIngredient(key, inventory);
return (S) this; return (S) this;
} }
@Override @Override
public S addIngredient(char key, @NotNull VirtualInventory inventory, @Nullable ItemProvider background) { public @NotNull S addIngredient(char key, @NotNull VirtualInventory inventory, @Nullable ItemProvider background) {
structure.addIngredient(key, inventory, background); structure.addIngredient(key, inventory, background);
return (S) this; return (S) this;
} }
@Override @Override
public S addIngredient(char key, @NotNull SlotElement element) { public @NotNull S addIngredient(char key, @NotNull SlotElement element) {
structure.addIngredient(key, element); structure.addIngredient(key, element);
return (S) this; return (S) this;
} }
@Override @Override
public S addIngredient(char key, @NotNull Marker marker) { public @NotNull S addIngredient(char key, @NotNull Marker marker) {
structure.addIngredient(key, marker); structure.addIngredient(key, marker);
return (S) this; return (S) this;
} }
@Override @Override
public S addIngredient(char key, @NotNull Supplier<? extends Item> itemSupplier) { public @NotNull S addIngredient(char key, @NotNull Supplier<? extends Item> itemSupplier) {
structure.addIngredient(key, itemSupplier); structure.addIngredient(key, itemSupplier);
return (S) this; return (S) this;
} }
@Override @Override
public S addIngredientElementSupplier(char key, @NotNull Supplier<? extends SlotElement> elementSupplier) { public @NotNull S addIngredientElementSupplier(char key, @NotNull Supplier<? extends SlotElement> elementSupplier) {
structure.addIngredientElementSupplier(key, elementSupplier); structure.addIngredientElementSupplier(key, elementSupplier);
return (S) this; return (S) this;
} }
@Override @Override
public S setBackground(@NotNull ItemProvider itemProvider) { public @NotNull S setBackground(@NotNull ItemProvider itemProvider) {
background = itemProvider; background = itemProvider;
return (S) this; return (S) this;
} }
@Override @Override
public S setBackground(@NotNull ItemStack itemStack) { public @NotNull S setBackground(@NotNull ItemStack itemStack) {
background = new ItemWrapper(itemStack); background = new ItemWrapper(itemStack);
return (S) this; return (S) this;
} }
@Override @Override
public S addModifier(@NotNull Consumer<@NotNull Gui> modifier) { public @NotNull S addModifier(@NotNull Consumer<@NotNull Gui> modifier) {
if (modifiers == null) if (modifiers == null)
modifiers = new ArrayList<>(); modifiers = new ArrayList<>();
@ -787,7 +787,7 @@ public abstract class AbstractGui implements Gui, GuiParent {
} }
@Override @Override
public S setModifiers(@NotNull List<@NotNull Consumer<@NotNull Gui>> modifiers) { public @NotNull S setModifiers(@NotNull List<@NotNull Consumer<@NotNull Gui>> modifiers) {
this.modifiers = modifiers; this.modifiers = modifiers;
return (S) this; return (S) this;
} }

@ -140,13 +140,13 @@ public abstract class AbstractPagedGui<C> extends AbstractGui implements PagedGu
protected List<BiConsumer<Integer, Integer>> pageChangeHandlers; protected List<BiConsumer<Integer, Integer>> pageChangeHandlers;
@Override @Override
public PagedGui.Builder<C> setContent(@NotNull List<@NotNull C> content) { public PagedGui.@NotNull Builder<C> setContent(@NotNull List<@NotNull C> content) {
this.content = content; this.content = content;
return this; return this;
} }
@Override @Override
public PagedGui.Builder<C> addContent(@NotNull C content) { public PagedGui.@NotNull Builder<C> addContent(@NotNull C content) {
if (this.content == null) if (this.content == null)
this.content = new ArrayList<>(); this.content = new ArrayList<>();
@ -155,13 +155,13 @@ public abstract class AbstractPagedGui<C> extends AbstractGui implements PagedGu
} }
@Override @Override
public PagedGui.Builder<C> setPageChangeHandlers(@NotNull List<@NotNull BiConsumer<Integer, Integer>> handlers) { public PagedGui.@NotNull Builder<C> setPageChangeHandlers(@NotNull List<@NotNull BiConsumer<Integer, Integer>> handlers) {
pageChangeHandlers = handlers; pageChangeHandlers = handlers;
return this; return this;
} }
@Override @Override
public PagedGui.Builder<C> addPageChangeHandler(@NotNull BiConsumer<Integer, Integer> handler) { public PagedGui.@NotNull Builder<C> addPageChangeHandler(@NotNull BiConsumer<Integer, Integer> handler) {
if (pageChangeHandlers == null) if (pageChangeHandlers == null)
pageChangeHandlers = new ArrayList<>(1); pageChangeHandlers = new ArrayList<>(1);

@ -141,13 +141,13 @@ public abstract class AbstractScrollGui<C> extends AbstractGui implements Scroll
protected List<BiConsumer<Integer, Integer>> scrollHandlers; protected List<BiConsumer<Integer, Integer>> scrollHandlers;
@Override @Override
public ScrollGui.Builder<C> setContent(@NotNull List<@NotNull C> content) { public ScrollGui.@NotNull Builder<C> setContent(@NotNull List<@NotNull C> content) {
this.content = content; this.content = content;
return this; return this;
} }
@Override @Override
public ScrollGui.Builder<C> addContent(@NotNull C content) { public ScrollGui.@NotNull Builder<C> addContent(@NotNull C content) {
if (this.content == null) if (this.content == null)
this.content = new ArrayList<>(); this.content = new ArrayList<>();
@ -156,13 +156,13 @@ public abstract class AbstractScrollGui<C> extends AbstractGui implements Scroll
} }
@Override @Override
public ScrollGui.Builder<C> setScrollHandlers(@NotNull List<@NotNull BiConsumer<Integer, Integer>> handlers) { public ScrollGui.@NotNull Builder<C> setScrollHandlers(@NotNull List<@NotNull BiConsumer<Integer, Integer>> handlers) {
scrollHandlers = handlers; scrollHandlers = handlers;
return this; return this;
} }
@Override @Override
public ScrollGui.Builder<C> addScrollHandler(@NotNull BiConsumer<Integer, Integer> handler) { public ScrollGui.@NotNull Builder<C> addScrollHandler(@NotNull BiConsumer<Integer, Integer> handler) {
if (scrollHandlers == null) if (scrollHandlers == null)
scrollHandlers = new ArrayList<>(1); scrollHandlers = new ArrayList<>(1);

@ -105,13 +105,13 @@ public abstract class AbstractTabGui extends AbstractGui implements TabGui {
protected List<BiConsumer<Integer, Integer>> tabChangeHandlers; protected List<BiConsumer<Integer, Integer>> tabChangeHandlers;
@Override @Override
public TabGui.Builder setTabs(@NotNull List<@Nullable Gui> tabs) { public TabGui.@NotNull Builder setTabs(@NotNull List<@Nullable Gui> tabs) {
this.tabs = tabs; this.tabs = tabs;
return this; return this;
} }
@Override @Override
public TabGui.Builder addTab(@Nullable Gui tab) { public TabGui.@NotNull Builder addTab(@Nullable Gui tab) {
if (this.tabs == null) if (this.tabs == null)
this.tabs = new ArrayList<>(); this.tabs = new ArrayList<>();
@ -120,7 +120,7 @@ public abstract class AbstractTabGui extends AbstractGui implements TabGui {
} }
@Override @Override
public TabGui.Builder addTabChangeHandler(@NotNull BiConsumer<Integer, Integer> handler) { public TabGui.@NotNull Builder addTabChangeHandler(@NotNull BiConsumer<Integer, Integer> handler) {
if (tabChangeHandlers == null) if (tabChangeHandlers == null)
tabChangeHandlers = new ArrayList<>(1); tabChangeHandlers = new ArrayList<>(1);
@ -129,7 +129,7 @@ public abstract class AbstractTabGui extends AbstractGui implements TabGui {
} }
@Override @Override
public TabGui.Builder setTabChangeHandlers(@NotNull List<@NotNull BiConsumer<Integer, Integer>> handlers) { public TabGui.@NotNull Builder setTabChangeHandlers(@NotNull List<@NotNull BiConsumer<Integer, Integer>> handlers) {
tabChangeHandlers = handlers; tabChangeHandlers = handlers;
return this; return this;
} }

@ -392,7 +392,7 @@ public interface Gui {
* @return This {@link Builder} * @return This {@link Builder}
*/ */
@Contract("_ -> this") @Contract("_ -> this")
S setStructure(@NotNull Structure structure); @NotNull S setStructure(@NotNull Structure structure);
/** /**
* Sets the {@link Structure} of the {@link Gui} using the given structure data Strings. * Sets the {@link Structure} of the {@link Gui} using the given structure data Strings.
@ -402,7 +402,7 @@ public interface Gui {
* @return This {@link Builder Gui Builder} * @return This {@link Builder Gui Builder}
*/ */
@Contract("_ -> this") @Contract("_ -> this")
S setStructure(@NotNull String... structureData); @NotNull S setStructure(@NotNull String... structureData);
/** /**
* Sets the {@link Structure} of the {@link Gui} using the given structure data, width and height. * Sets the {@link Structure} of the {@link Gui} using the given structure data, width and height.
@ -413,7 +413,7 @@ public interface Gui {
* @return This {@link Builder Gui Builder} * @return This {@link Builder Gui Builder}
*/ */
@Contract("_, _, _, -> this") @Contract("_, _, _, -> this")
S setStructure(int width, int height, @NotNull String structureData); @NotNull S setStructure(int width, int height, @NotNull String structureData);
/** /**
* Adds an {@link ItemStack} ingredient under the given key. * Adds an {@link ItemStack} ingredient under the given key.
@ -423,7 +423,7 @@ public interface Gui {
* @return This {@link Builder Gui Builder} * @return This {@link Builder Gui Builder}
*/ */
@Contract("_, _ -> this") @Contract("_, _ -> this")
S addIngredient(char key, @NotNull ItemStack itemStack); @NotNull S addIngredient(char key, @NotNull ItemStack itemStack);
/** /**
* Adds an {@link ItemProvider} ingredient under the given key. * Adds an {@link ItemProvider} ingredient under the given key.
@ -433,7 +433,7 @@ public interface Gui {
* @return This {@link Builder Gui Builder} * @return This {@link Builder Gui Builder}
*/ */
@Contract("_, _ -> this") @Contract("_, _ -> this")
S addIngredient(char key, @NotNull ItemProvider itemProvider); @NotNull S addIngredient(char key, @NotNull ItemProvider itemProvider);
/** /**
* Adds an {@link Item} ingredient under the given key. * Adds an {@link Item} ingredient under the given key.
@ -443,7 +443,7 @@ public interface Gui {
* @return This {@link Builder Gui Builder} * @return This {@link Builder Gui Builder}
*/ */
@Contract("_, _ -> this") @Contract("_, _ -> this")
S addIngredient(char key, @NotNull Item item); @NotNull S addIngredient(char key, @NotNull Item item);
/** /**
* Adds an {@link VirtualInventory} ingredient under the given key. * Adds an {@link VirtualInventory} ingredient under the given key.
@ -453,7 +453,7 @@ public interface Gui {
* @return This {@link Builder Gui Builder} * @return This {@link Builder Gui Builder}
*/ */
@Contract("_, _ -> this") @Contract("_, _ -> this")
S addIngredient(char key, @NotNull VirtualInventory inventory); @NotNull S addIngredient(char key, @NotNull VirtualInventory inventory);
/** /**
* Adds an {@link VirtualInventory} ingredient under the given key. * Adds an {@link VirtualInventory} ingredient under the given key.
@ -464,7 +464,7 @@ public interface Gui {
* @return This {@link Builder Gui Builder} * @return This {@link Builder Gui Builder}
*/ */
@Contract("_, _, _ -> this") @Contract("_, _, _ -> this")
S addIngredient(char key, @NotNull VirtualInventory inventory, @Nullable ItemProvider background); @NotNull S addIngredient(char key, @NotNull VirtualInventory inventory, @Nullable ItemProvider background);
/** /**
* Adds a {@link SlotElement} ingredient under the given key. * Adds a {@link SlotElement} ingredient under the given key.
@ -474,7 +474,7 @@ public interface Gui {
* @return This {@link Builder Gui Builder} * @return This {@link Builder Gui Builder}
*/ */
@Contract("_, _ -> this") @Contract("_, _ -> this")
S addIngredient(char key, @NotNull SlotElement element); @NotNull S addIngredient(char key, @NotNull SlotElement element);
/** /**
* Adds a {@link Marker} ingredient under the given key. * Adds a {@link Marker} ingredient under the given key.
@ -484,7 +484,7 @@ public interface Gui {
* @return This {@link Builder Gui Builder} * @return This {@link Builder Gui Builder}
*/ */
@Contract("_, _ -> this") @Contract("_, _ -> this")
S addIngredient(char key, @NotNull Marker marker); @NotNull S addIngredient(char key, @NotNull Marker marker);
/** /**
* Adds a {@link Supplier} of {@link Item Items} ingredient under the given key. * Adds a {@link Supplier} of {@link Item Items} ingredient under the given key.
@ -494,7 +494,7 @@ public interface Gui {
* @return This {@link Builder Gui Builder} * @return This {@link Builder Gui Builder}
*/ */
@Contract("_, _ -> this") @Contract("_, _ -> this")
S addIngredient(char key, @NotNull Supplier<? extends Item> itemSupplier); @NotNull S addIngredient(char key, @NotNull Supplier<? extends Item> itemSupplier);
/** /**
* Adds a {@link Supplier} of {@link SlotElement SlotElements} ingredient under the given key. * Adds a {@link Supplier} of {@link SlotElement SlotElements} ingredient under the given key.
@ -504,7 +504,7 @@ public interface Gui {
* @return This {@link Builder Gui Builder} * @return This {@link Builder Gui Builder}
*/ */
@Contract("_, _ -> this") @Contract("_, _ -> this")
S addIngredientElementSupplier(char key, @NotNull Supplier<? extends SlotElement> elementSupplier); @NotNull S addIngredientElementSupplier(char key, @NotNull Supplier<? extends SlotElement> elementSupplier);
/** /**
* Sets the background of the {@link Gui}. * Sets the background of the {@link Gui}.
@ -513,7 +513,7 @@ public interface Gui {
* @return This {@link Builder Gui Builder} * @return This {@link Builder Gui Builder}
*/ */
@Contract("_ -> this") @Contract("_ -> this")
S setBackground(@NotNull ItemProvider itemProvider); @NotNull S setBackground(@NotNull ItemProvider itemProvider);
/** /**
* Sets the background of the {@link Gui}. * Sets the background of the {@link Gui}.
@ -522,7 +522,7 @@ public interface Gui {
* @return This {@link Builder Gui Builder} * @return This {@link Builder Gui Builder}
*/ */
@Contract("_ -> this") @Contract("_ -> this")
S setBackground(@NotNull ItemStack itemStack); @NotNull S setBackground(@NotNull ItemStack itemStack);
/** /**
* Sets the background of the {@link Gui}. * Sets the background of the {@link Gui}.
@ -531,7 +531,7 @@ public interface Gui {
* @return This {@link Builder Gui Builder} * @return This {@link Builder Gui Builder}
*/ */
@Contract("_ -> this") @Contract("_ -> this")
S addModifier(@NotNull Consumer<@NotNull Gui> modifier); @NotNull S addModifier(@NotNull Consumer<@NotNull Gui> modifier);
/** /**
* Sets the background of the {@link Gui}. * Sets the background of the {@link Gui}.
@ -540,7 +540,7 @@ public interface Gui {
* @return This {@link Builder Gui Builder} * @return This {@link Builder Gui Builder}
*/ */
@Contract("_ -> this") @Contract("_ -> this")
S setModifiers(@NotNull List<@NotNull Consumer<@NotNull Gui>> modifiers); @NotNull S setModifiers(@NotNull List<@NotNull Consumer<@NotNull Gui>> modifiers);
/** /**
* Builds the {@link Gui}. * Builds the {@link Gui}.
@ -557,10 +557,10 @@ public interface Gui {
*/ */
@Contract("-> new") @Contract("-> new")
@NotNull S clone(); @NotNull S clone();
/** /**
* A normal {@link Gui} builder. * A normal {@link Gui} builder.
* *
* @see PagedGui.Builder * @see PagedGui.Builder
* @see ScrollGui.Builder * @see ScrollGui.Builder
* @see TabGui.Builder * @see TabGui.Builder

@ -215,7 +215,7 @@ public interface PagedGui<C> extends Gui {
* @return This {@link Builder Gui Builder}. * @return This {@link Builder Gui Builder}.
*/ */
@Contract("_ -> this") @Contract("_ -> this")
Builder<C> setContent(@NotNull List<@NotNull C> content); @NotNull Builder<C> setContent(@NotNull List<@NotNull C> content);
/** /**
* Adds content to the {@link PagedGui}. * Adds content to the {@link PagedGui}.
@ -224,7 +224,7 @@ public interface PagedGui<C> extends Gui {
* @return This {@link Builder Gui Builder}. * @return This {@link Builder Gui Builder}.
*/ */
@Contract("_ -> this") @Contract("_ -> this")
Builder<C> addContent(@NotNull C content); @NotNull Builder<C> addContent(@NotNull C content);
/** /**
* Sets the page change handlers of the {@link PagedGui}. * Sets the page change handlers of the {@link PagedGui}.
@ -233,7 +233,7 @@ public interface PagedGui<C> extends Gui {
* @return This {@link Builder Gui Builder}. * @return This {@link Builder Gui Builder}.
*/ */
@Contract("_ -> this") @Contract("_ -> this")
Builder<C> setPageChangeHandlers(@NotNull List<@NotNull BiConsumer<Integer, Integer>> handlers); @NotNull Builder<C> setPageChangeHandlers(@NotNull List<@NotNull BiConsumer<Integer, Integer>> handlers);
/** /**
* Adds a page change handler to the {@link PagedGui}. * Adds a page change handler to the {@link PagedGui}.
@ -242,7 +242,7 @@ public interface PagedGui<C> extends Gui {
* @return This {@link Builder Gui Builder}. * @return This {@link Builder Gui Builder}.
*/ */
@Contract("_ -> this") @Contract("_ -> this")
Builder<C> addPageChangeHandler(@NotNull BiConsumer<Integer, Integer> handler); @NotNull Builder<C> addPageChangeHandler(@NotNull BiConsumer<Integer, Integer> handler);
} }

@ -228,7 +228,7 @@ public interface ScrollGui<C> extends Gui {
* @return This {@link Builder Gui Builder}. * @return This {@link Builder Gui Builder}.
*/ */
@Contract("_ -> this") @Contract("_ -> this")
Builder<C> setContent(@NotNull List<@NotNull C> content); @NotNull Builder<C> setContent(@NotNull List<@NotNull C> content);
/** /**
* Adds content to the {@link ScrollGui}. * Adds content to the {@link ScrollGui}.
@ -237,7 +237,7 @@ public interface ScrollGui<C> extends Gui {
* @return This {@link Builder Gui Builder}. * @return This {@link Builder Gui Builder}.
*/ */
@Contract("_ -> this") @Contract("_ -> this")
Builder<C> addContent(@NotNull C content); @NotNull Builder<C> addContent(@NotNull C content);
/** /**
* Adds content to the {@link ScrollGui}. * Adds content to the {@link ScrollGui}.
@ -246,7 +246,7 @@ public interface ScrollGui<C> extends Gui {
* @return This {@link Builder Gui Builder}. * @return This {@link Builder Gui Builder}.
*/ */
@Contract("_ -> this") @Contract("_ -> this")
Builder<C> setScrollHandlers(@NotNull List<@NotNull BiConsumer<Integer, Integer>> handlers); @NotNull Builder<C> setScrollHandlers(@NotNull List<@NotNull BiConsumer<Integer, Integer>> handlers);
/** /**
* Adds a scroll handler to the {@link ScrollGui}. * Adds a scroll handler to the {@link ScrollGui}.
@ -255,7 +255,7 @@ public interface ScrollGui<C> extends Gui {
* @return This {@link Builder Gui Builder}. * @return This {@link Builder Gui Builder}.
*/ */
@Contract("_ -> this") @Contract("_ -> this")
Builder<C> addScrollHandler(@NotNull BiConsumer<Integer, Integer> handler); @NotNull Builder<C> addScrollHandler(@NotNull BiConsumer<Integer, Integer> handler);
} }

@ -126,7 +126,7 @@ public interface TabGui extends Gui {
* @return This {@link Builder Gui Builder}. * @return This {@link Builder Gui Builder}.
*/ */
@Contract("_ -> this") @Contract("_ -> this")
Builder setTabs(@NotNull List<@Nullable Gui> tabs); @NotNull Builder setTabs(@NotNull List<@Nullable Gui> tabs);
/** /**
* Adds a tab to the {@link TabGui}. * Adds a tab to the {@link TabGui}.
@ -136,7 +136,7 @@ public interface TabGui extends Gui {
* @return This {@link Builder Gui Builder}. * @return This {@link Builder Gui Builder}.
*/ */
@Contract("_ -> this") @Contract("_ -> this")
Builder addTab(@Nullable Gui tab); @NotNull Builder addTab(@Nullable Gui tab);
/** /**
* Sets the tab change handlers of the {@link TabGui}. * Sets the tab change handlers of the {@link TabGui}.
@ -145,7 +145,7 @@ public interface TabGui extends Gui {
* @return This {@link Builder Gui Builder}. * @return This {@link Builder Gui Builder}.
*/ */
@Contract("_ -> this") @Contract("_ -> this")
Builder setTabChangeHandlers(@NotNull List<@NotNull BiConsumer<Integer, Integer>> handlers); @NotNull Builder setTabChangeHandlers(@NotNull List<@NotNull BiConsumer<Integer, Integer>> handlers);
/** /**
* Adds a tab change handler to the {@link TabGui}. * Adds a tab change handler to the {@link TabGui}.
@ -154,7 +154,7 @@ public interface TabGui extends Gui {
* @return This {@link Builder Gui Builder}. * @return This {@link Builder Gui Builder}.
*/ */
@Contract("_ -> this") @Contract("_ -> this")
Builder addTabChangeHandler(@NotNull BiConsumer<Integer, Integer> handler); @NotNull Builder addTabChangeHandler(@NotNull BiConsumer<Integer, Integer> handler);
} }

@ -7,6 +7,7 @@ import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable; import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import xyz.xenondevs.inventoryaccess.InventoryAccess; import xyz.xenondevs.inventoryaccess.InventoryAccess;
@ -23,7 +24,8 @@ import java.util.List;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public abstract class AbstractItemBuilder<T> implements ItemProvider { @SuppressWarnings("unchecked")
public abstract class AbstractItemBuilder<S> implements ItemProvider {
protected ItemStack base; protected ItemStack base;
protected Material material; protected Material material;
@ -72,8 +74,9 @@ public abstract class AbstractItemBuilder<T> implements ItemProvider {
* *
* @return The {@link ItemStack} * @return The {@link ItemStack}
*/ */
@Contract(value = "_ -> new", pure = true)
@Override @Override
public ItemStack get(@Nullable String lang) { public @NotNull ItemStack get(@Nullable String lang) {
ItemStack itemStack; ItemStack itemStack;
if (base != null) { if (base != null) {
itemStack = base; itemStack = base;
@ -142,101 +145,114 @@ public abstract class AbstractItemBuilder<T> implements ItemProvider {
return itemStack; return itemStack;
} }
public T removeLoreLine(int index) { @Contract("_ -> this")
public @NotNull S removeLoreLine(int index) {
if (lore != null) lore.remove(index); if (lore != null) lore.remove(index);
return getThis(); return (S) this;
} }
public T clearLore() { @Contract("-> this")
public @NotNull S clearLore() {
if (lore != null) lore.clear(); if (lore != null) lore.clear();
return getThis(); return (S) this;
} }
public ItemStack getBase() { public @Nullable ItemStack getBase() {
return base; return base;
} }
public Material getMaterial() { public @Nullable Material getMaterial() {
return material; return material;
} }
public T setMaterial(@NotNull Material material) { @Contract("_ -> this")
public @NotNull S setMaterial(@NotNull Material material) {
this.material = material; this.material = material;
return getThis(); return (S) this;
} }
public int getAmount() { public int getAmount() {
return amount; return amount;
} }
public T setAmount(int amount) { @Contract("_ -> this")
public @NotNull S setAmount(int amount) {
this.amount = amount; this.amount = amount;
return getThis(); return (S) this;
} }
public int getDamage() { public int getDamage() {
return damage; return damage;
} }
public T setDamage(int damage) { @Contract("_ -> this")
public @NotNull S setDamage(int damage) {
this.damage = damage; this.damage = damage;
return getThis(); return (S) this;
} }
public int getCustomModelData() { public int getCustomModelData() {
return customModelData; return customModelData;
} }
public T setCustomModelData(int customModelData) { @Contract("_ -> this")
public @NotNull S setCustomModelData(int customModelData) {
this.customModelData = customModelData; this.customModelData = customModelData;
return getThis(); return (S) this;
} }
public ComponentWrapper getDisplayName() { public @Nullable ComponentWrapper getDisplayName() {
return displayName; return displayName;
} }
public T setDisplayName(String displayName) { @Contract("_ -> this")
public @NotNull S setDisplayName(String displayName) {
this.displayName = new BaseComponentWrapper(ComponentUtils.withoutPreFormatting(displayName)); this.displayName = new BaseComponentWrapper(ComponentUtils.withoutPreFormatting(displayName));
return getThis(); return (S) this;
} }
public T setDisplayName(BaseComponent... displayName) { @Contract("_ -> this")
public @NotNull S setDisplayName(BaseComponent... displayName) {
this.displayName = new BaseComponentWrapper(ComponentUtils.withoutPreFormatting(displayName)); this.displayName = new BaseComponentWrapper(ComponentUtils.withoutPreFormatting(displayName));
return getThis(); return (S) this;
} }
public T setDisplayName(ComponentWrapper component) { @Contract("_ -> this")
public @NotNull S setDisplayName(ComponentWrapper component) {
this.displayName = component; this.displayName = component;
return getThis(); return (S) this;
} }
//<editor-fold desc="lore"> //<editor-fold desc="lore">
public List<ComponentWrapper> getLore() { public @Nullable List<ComponentWrapper> getLore() {
return lore; return lore;
} }
public T setLore(List<ComponentWrapper> lore) { @Contract("_ -> this")
public @NotNull S setLore(List<ComponentWrapper> lore) {
this.lore = lore; this.lore = lore;
return getThis(); return (S) this;
} }
public T setLegacyLore(@NotNull List<String> lore) { @Contract("_ -> this")
public @NotNull S setLegacyLore(@NotNull List<String> lore) {
this.lore = lore.stream() this.lore = lore.stream()
.map(line -> new BaseComponentWrapper(ComponentUtils.withoutPreFormatting(line))) .map(line -> new BaseComponentWrapper(ComponentUtils.withoutPreFormatting(line)))
.collect(Collectors.toList()); .collect(Collectors.toList());
return getThis(); return (S) this;
} }
public T addLoreLines(@NotNull String... lines) { @Contract("_ -> this")
public @NotNull S addLoreLines(@NotNull String... lines) {
if (lore == null) lore = new ArrayList<>(); if (lore == null) lore = new ArrayList<>();
for (String line : lines) for (String line : lines)
lore.add(new BaseComponentWrapper(ComponentUtils.withoutPreFormatting(line))); lore.add(new BaseComponentWrapper(ComponentUtils.withoutPreFormatting(line)));
return getThis(); return (S) this;
} }
public T addLoreLines(@NotNull BaseComponent[]... lines) { @Contract("_ -> this")
public @NotNull S addLoreLines(@NotNull BaseComponent[]... lines) {
if (lore == null) lore = new ArrayList<>(); if (lore == null) lore = new ArrayList<>();
lore.addAll( lore.addAll(
@ -245,108 +261,118 @@ public abstract class AbstractItemBuilder<T> implements ItemProvider {
.collect(Collectors.toList()) .collect(Collectors.toList())
); );
return getThis(); return (S) this;
} }
public T addLoreLines(@NotNull ComponentWrapper... lines) { @Contract("_ -> this")
public @NotNull S addLoreLines(@NotNull ComponentWrapper... lines) {
if (lore == null) lore = new ArrayList<>(); if (lore == null) lore = new ArrayList<>();
lore.addAll(Arrays.asList(lines)); lore.addAll(Arrays.asList(lines));
return getThis(); return (S) this;
} }
//</editor-fold> //</editor-fold>
//<editor-fold desc="item flags"> //<editor-fold desc="item flags">
public List<ItemFlag> getItemFlags() { public @Nullable List<ItemFlag> getItemFlags() {
return itemFlags; return itemFlags;
} }
public T setItemFlags(@NotNull List<ItemFlag> itemFlags) { @Contract("_ -> this")
public @NotNull S setItemFlags(@NotNull List<ItemFlag> itemFlags) {
this.itemFlags = itemFlags; this.itemFlags = itemFlags;
return getThis(); return (S) this;
} }
public T addItemFlags(@NotNull ItemFlag... itemFlags) { @Contract("_ -> this")
public @NotNull S addItemFlags(@NotNull ItemFlag... itemFlags) {
if (this.itemFlags == null) this.itemFlags = new ArrayList<>(); if (this.itemFlags == null) this.itemFlags = new ArrayList<>();
this.itemFlags.addAll(Arrays.asList(itemFlags)); this.itemFlags.addAll(Arrays.asList(itemFlags));
return getThis(); return (S) this;
} }
public T removeItemFlags(@NotNull ItemFlag... itemFlags) { @Contract("_ -> this")
public @NotNull S removeItemFlags(@NotNull ItemFlag... itemFlags) {
if (this.itemFlags != null) if (this.itemFlags != null)
this.itemFlags.removeAll(Arrays.asList(itemFlags)); this.itemFlags.removeAll(Arrays.asList(itemFlags));
return getThis(); return (S) this;
} }
public T clearItemFlags() { @Contract("-> this")
public @NotNull S clearItemFlags() {
if (itemFlags != null) itemFlags.clear(); if (itemFlags != null) itemFlags.clear();
return getThis(); return (S) this;
} }
//</editor-fold> //</editor-fold>
//<editor-fold desc="enchantments"> //<editor-fold desc="enchantments">
public HashMap<Enchantment, Pair<Integer, Boolean>> getEnchantments() { public @Nullable HashMap<Enchantment, Pair<Integer, Boolean>> getEnchantments() {
return enchantments; return enchantments;
} }
public T setEnchantments(@NotNull HashMap<Enchantment, Pair<Integer, Boolean>> enchantments) { @Contract("_ -> this")
public @NotNull S setEnchantments(@NotNull HashMap<Enchantment, Pair<Integer, Boolean>> enchantments) {
this.enchantments = enchantments; this.enchantments = enchantments;
return getThis(); return (S) this;
} }
public T addEnchantment(Enchantment enchantment, int level, boolean ignoreLevelRestriction) { @Contract("_, _, _ -> this")
public @NotNull S addEnchantment(Enchantment enchantment, int level, boolean ignoreLevelRestriction) {
if (enchantments == null) enchantments = new HashMap<>(); if (enchantments == null) enchantments = new HashMap<>();
enchantments.put(enchantment, new Pair<>(level, ignoreLevelRestriction)); enchantments.put(enchantment, new Pair<>(level, ignoreLevelRestriction));
return getThis(); return (S) this;
} }
public T removeEnchantment(Enchantment enchantment) { @Contract("_ -> this")
public @NotNull S removeEnchantment(Enchantment enchantment) {
if (enchantments == null) enchantments = new HashMap<>(); if (enchantments == null) enchantments = new HashMap<>();
enchantments.remove(enchantment); enchantments.remove(enchantment);
return getThis(); return (S) this;
} }
public T clearEnchantments() { @Contract("-> this")
public @NotNull S clearEnchantments() {
if (enchantments != null) enchantments.clear(); if (enchantments != null) enchantments.clear();
return getThis(); return (S) this;
} }
//</editor-fold> //</editor-fold>
//<editor-fold desc="modifiers"> //<editor-fold desc="modifiers">
public List<Function<ItemStack, ItemStack>> getModifiers() { public @Nullable List<Function<ItemStack, ItemStack>> getModifiers() {
return modifiers; return modifiers;
} }
public T addModifier(Function<ItemStack, ItemStack> modifier) { @Contract("_ -> this")
public @NotNull S addModifier(Function<ItemStack, ItemStack> modifier) {
if (modifiers == null) modifiers = new ArrayList<>(); if (modifiers == null) modifiers = new ArrayList<>();
modifiers.add(modifier); modifiers.add(modifier);
return getThis(); return (S) this;
} }
public T clearModifiers() { @Contract("-> this")
public @NotNull S clearModifiers() {
if (modifiers != null) modifiers.clear(); if (modifiers != null) modifiers.clear();
return getThis(); return (S) this;
} }
//</editor-fold> //</editor-fold>
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Contract(value = "-> new", pure = true)
@Override @Override
public T clone() { public @NotNull S clone() {
try { try {
AbstractItemBuilder<T> clone = ((AbstractItemBuilder<T>) super.clone()); AbstractItemBuilder<S> clone = ((AbstractItemBuilder<S>) super.clone());
if (base != null) clone.base = base.clone(); if (base != null) clone.base = base.clone();
if (lore != null) clone.lore = new ArrayList<>(lore); if (lore != null) clone.lore = new ArrayList<>(lore);
if (itemFlags != null) clone.itemFlags = new ArrayList<>(itemFlags); if (itemFlags != null) clone.itemFlags = new ArrayList<>(itemFlags);
if (enchantments != null) clone.enchantments = new HashMap<>(enchantments); if (enchantments != null) clone.enchantments = new HashMap<>(enchantments);
if (modifiers != null) clone.modifiers = new ArrayList<>(modifiers); if (modifiers != null) clone.modifiers = new ArrayList<>(modifiers);
return (T) clone; return (S) clone;
} catch (CloneNotSupportedException e) { } catch (CloneNotSupportedException e) {
throw new AssertionError(e); throw new AssertionError(e);
} }
} }
protected abstract T getThis();
} }

@ -36,9 +36,4 @@ public final class ItemBuilder extends AbstractItemBuilder<ItemBuilder> {
super(base); super(base);
} }
@Override
protected ItemBuilder getThis() {
return this;
}
} }

@ -6,6 +6,8 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionData; import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -16,36 +18,41 @@ public final class PotionBuilder extends AbstractItemBuilder<PotionBuilder> {
private Color color; private Color color;
private PotionData basePotionData; private PotionData basePotionData;
public PotionBuilder(PotionType type) { public PotionBuilder(@NotNull PotionType type) {
super(type.getMaterial()); super(type.getMaterial());
} }
public PotionBuilder(ItemStack base) { public PotionBuilder(@NotNull ItemStack base) {
super(base); super(base);
} }
public PotionBuilder setColor(Color color) { @Contract("_ -> this")
public @NotNull PotionBuilder setColor(@NotNull Color color) {
this.color = color; this.color = color;
return this; return this;
} }
public PotionBuilder setColor(java.awt.Color color) { @Contract("_ -> this")
public @NotNull PotionBuilder setColor(@NotNull java.awt.Color color) {
this.color = Color.fromRGB(color.getRed(), color.getGreen(), color.getBlue()); this.color = Color.fromRGB(color.getRed(), color.getGreen(), color.getBlue());
return this; return this;
} }
public PotionBuilder setBasePotionData(PotionData basePotionData) { @Contract("_ -> this")
public @NotNull PotionBuilder setBasePotionData(@NotNull PotionData basePotionData) {
this.basePotionData = basePotionData; this.basePotionData = basePotionData;
return this; return this;
} }
public PotionBuilder addEffect(PotionEffect effect) { @Contract("_ -> this")
public @NotNull PotionBuilder addEffect(@NotNull PotionEffect effect) {
effects.add(effect); effects.add(effect);
return this; return this;
} }
@Contract(value = "-> new", pure = true)
@Override @Override
public ItemStack get() { public @NotNull ItemStack get() {
ItemStack item = super.get(); ItemStack item = super.get();
PotionMeta meta = (PotionMeta) item.getItemMeta(); PotionMeta meta = (PotionMeta) item.getItemMeta();
@ -59,30 +66,25 @@ public final class PotionBuilder extends AbstractItemBuilder<PotionBuilder> {
} }
@Override @Override
public PotionBuilder clone() { public @NotNull PotionBuilder clone() {
PotionBuilder builder = super.clone(); PotionBuilder builder = super.clone();
builder.effects = new ArrayList<>(effects); builder.effects = new ArrayList<>(effects);
return builder; return builder;
} }
@Override
protected PotionBuilder getThis() {
return this;
}
public enum PotionType { public enum PotionType {
NORMAL(Material.POTION), NORMAL(Material.POTION),
SPLASH(Material.SPLASH_POTION), SPLASH(Material.SPLASH_POTION),
LINGERING(Material.LINGERING_POTION); LINGERING(Material.LINGERING_POTION);
private final Material material; private final @NotNull Material material;
PotionType(Material material) { PotionType(@NotNull Material material) {
this.material = material; this.material = material;
} }
public Material getMaterial() { public @NotNull Material getMaterial() {
return material; return material;
} }

@ -11,6 +11,7 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import xyz.xenondevs.inventoryaccess.util.ReflectionRegistry; import xyz.xenondevs.inventoryaccess.util.ReflectionRegistry;
import xyz.xenondevs.inventoryaccess.util.ReflectionUtils; import xyz.xenondevs.inventoryaccess.util.ReflectionUtils;
@ -30,7 +31,7 @@ public final class SkullBuilder extends AbstractItemBuilder<SkullBuilder> {
* *
* @param uuid The {@link UUID} of the skull owner. * @param uuid The {@link UUID} of the skull owner.
*/ */
public SkullBuilder(UUID uuid) { public SkullBuilder(@NotNull UUID uuid) {
this(HeadTexture.of(uuid)); this(HeadTexture.of(uuid));
} }
@ -39,7 +40,7 @@ public final class SkullBuilder extends AbstractItemBuilder<SkullBuilder> {
* *
* @param username The username of the skull owner. * @param username The username of the skull owner.
*/ */
public SkullBuilder(String username) { public SkullBuilder(@NotNull String username) {
this(HeadTexture.of(username)); this(HeadTexture.of(username));
} }
@ -48,19 +49,20 @@ public final class SkullBuilder extends AbstractItemBuilder<SkullBuilder> {
* *
* @param headTexture The {@link HeadTexture} to be applied to the skull. * @param headTexture The {@link HeadTexture} to be applied to the skull.
*/ */
public SkullBuilder(HeadTexture headTexture) { public SkullBuilder(@NotNull HeadTexture headTexture) {
super(Material.PLAYER_HEAD); super(Material.PLAYER_HEAD);
setGameProfile(headTexture); setGameProfile(headTexture);
} }
private void setGameProfile(HeadTexture texture) { private void setGameProfile(@NotNull HeadTexture texture) {
gameProfile = new GameProfile(UUID.randomUUID(), null); gameProfile = new GameProfile(UUID.randomUUID(), null);
PropertyMap propertyMap = gameProfile.getProperties(); PropertyMap propertyMap = gameProfile.getProperties();
propertyMap.put("textures", new Property("textures", texture.getTextureValue())); propertyMap.put("textures", new Property("textures", texture.getTextureValue()));
} }
@Contract(value = "-> new", pure = true)
@Override @Override
public ItemStack get() { public @NotNull ItemStack get() {
ItemStack item = super.get(); ItemStack item = super.get();
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();
@ -72,14 +74,16 @@ public final class SkullBuilder extends AbstractItemBuilder<SkullBuilder> {
return item; return item;
} }
@Contract("_ -> this")
@Override @Override
public SkullBuilder setMaterial(@NotNull Material material) { public @NotNull SkullBuilder setMaterial(@NotNull Material material) {
return this; return this;
} }
@Contract(value = "-> new", pure = true)
@Override @Override
protected SkullBuilder getThis() { public @NotNull SkullBuilder clone() {
return this; return super.clone();
} }
/** /**
@ -185,7 +189,7 @@ public final class SkullBuilder extends AbstractItemBuilder<SkullBuilder> {
* *
* @return The stored texture value. * @return The stored texture value.
*/ */
public String getTextureValue() { public @NotNull String getTextureValue() {
return textureValue; return textureValue;
} }

@ -60,13 +60,13 @@ final class AnvilSingleWindowImpl extends AbstractSingleWindow implements AnvilW
private List<Consumer<String>> renameHandlers; private List<Consumer<String>> renameHandlers;
@Override @Override
public BuilderImpl setRenameHandlers(@NotNull List<@NotNull Consumer<String>> renameHandlers) { public @NotNull BuilderImpl setRenameHandlers(@NotNull List<@NotNull Consumer<String>> renameHandlers) {
this.renameHandlers = renameHandlers; this.renameHandlers = renameHandlers;
return this; return this;
} }
@Override @Override
public BuilderImpl addRenameHandler(@NotNull Consumer<String> renameHandler) { public @NotNull BuilderImpl addRenameHandler(@NotNull Consumer<String> renameHandler) {
if (renameHandlers == null) if (renameHandlers == null)
renameHandlers = new ArrayList<>(); renameHandlers = new ArrayList<>();

@ -62,13 +62,13 @@ final class AnvilSplitWindowImpl extends AbstractSplitWindow implements AnvilWin
private List<Consumer<String>> renameHandlers; private List<Consumer<String>> renameHandlers;
@Override @Override
public BuilderImpl setRenameHandlers(@NotNull List<@NotNull Consumer<String>> renameHandlers) { public @NotNull BuilderImpl setRenameHandlers(@NotNull List<@NotNull Consumer<String>> renameHandlers) {
this.renameHandlers = renameHandlers; this.renameHandlers = renameHandlers;
return this; return this;
} }
@Override @Override
public BuilderImpl addRenameHandler(@NotNull Consumer<String> renameHandler) { public @NotNull BuilderImpl addRenameHandler(@NotNull Consumer<String> renameHandler) {
if (renameHandlers == null) if (renameHandlers == null)
renameHandlers = new ArrayList<>(); renameHandlers = new ArrayList<>();

@ -35,10 +35,10 @@ public interface AnvilWindow extends Window {
interface Builder<S extends Builder<S>> extends Window.Builder<AnvilWindow, Player, S> { interface Builder<S extends Builder<S>> extends Window.Builder<AnvilWindow, Player, S> {
@Contract("_ -> this") @Contract("_ -> this")
S setRenameHandlers(@NotNull List<@NotNull Consumer<String>> renameHandlers); @NotNull S setRenameHandlers(@NotNull List<@NotNull Consumer<String>> renameHandlers);
@Contract("_ -> this") @Contract("_ -> this")
S addRenameHandler(@NotNull Consumer<String> renameHandler); @NotNull S addRenameHandler(@NotNull Consumer<String> renameHandler);
interface Single extends Builder<Single>, Window.Builder.Single<AnvilWindow, Player, Single> {} interface Single extends Builder<Single>, Window.Builder.Single<AnvilWindow, Player, Single> {}