1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00

Add the get optional methods

This commit is contained in:
JustAHuman-xD 2023-08-29 16:47:29 -05:00
parent 27caae8647
commit 361c83fd73

View File

@ -1161,6 +1161,17 @@ public class SlimefunItem implements Placeable {
return Slimefun.getRegistry().getSlimefunItemIds().get(id);
}
/**
* Retrieve a {@link Optional}<{@link SlimefunItem}> by its id.
*
* @param id
* The id of the {@link SlimefunItem}
* @return The {@link Optional}<{@link SlimefunItem}> associated with that id. Empty if non-existent
*/
public static @Nonnull Optional<SlimefunItem> getOptionalById(@Nonnull String id) {
return Optional.ofNullable(getById(id));
}
/**
* Retrieve a {@link SlimefunItem} from an {@link ItemStack}.
*
@ -1208,4 +1219,15 @@ public class SlimefunItem implements Placeable {
return null;
}
/**
* Retrieve a {@link Optional}<{@link SlimefunItem}> from an {@link ItemStack}.
*
* @param item
* The {@link ItemStack} to check
* @return The {@link Optional}<{@link SlimefunItem}> associated with this {@link ItemStack} if present, otherwise empty
*/
public @Nonnull Optional<SlimefunItem> getOptionalByItem(@Nullable ItemStack item) {
return Optional.ofNullable(getByItem(item));
}
}