1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 03:35:51 +00:00

Deprecate the public constructor of ItemStackWrapper(ItemStack). More docs and use #ofItem where possible

This commit is contained in:
Andrew Wong 2021-05-17 21:46:59 +02:00
parent 727c8d34b9
commit 6f042e60ad
No known key found for this signature in database
GPG Key ID: F59F2C3DA0936DE4

View File

@ -30,6 +30,19 @@ public final class ItemStackWrapper extends ItemStack {
private final int amount;
private final boolean hasItemMeta;
/**
* @deprecated This constructor is often misused leading to duplicate
* wrappers being made, used once, and then discarded.
* <p>
* Use {@link #forceWrapItem(ItemStack)} to wrap an {@link ItemStack}
* regardless of whether it has already been wrapped.
* </p>
* <p>
* Use {@link #ofItem(ItemStack)} to wrap an {@link ItemStack} if
* and only if it has not already been wrapped
* </p>
*/
@Deprecated
public ItemStackWrapper(@Nonnull ItemStack item) {
super(item.getType());
amount = item.getAmount();
@ -46,6 +59,10 @@ public final class ItemStackWrapper extends ItemStack {
this(new ItemStack(material));
}
public static @Nonnull ItemStackWrapper forceWrapItem(@Nonnull ItemStack itemStack) {
return new ItemStackWrapper(itemStack);
}
public static @Nonnull ItemStackWrapper ofItem(@Nonnull ItemStack itemStack) {
if (itemStack instanceof ItemStackWrapper) {
return (ItemStackWrapper) itemStack;
@ -128,7 +145,7 @@ public final class ItemStackWrapper extends ItemStack {
for (int i = 0; i < items.length; i++) {
if (items[i] != null) {
array[i] = new ItemStackWrapper(items[i]);
array[i] = ofItem(items[i]);
}
}
@ -150,7 +167,7 @@ public final class ItemStackWrapper extends ItemStack {
for (ItemStack item : items) {
if (item != null) {
list.add(new ItemStackWrapper(item));
list.add(ofItem(item));
} else {
list.add(null);
}