diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItem.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItem.java index 0d4b1f12f..7db2dc5a2 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItem.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItem.java @@ -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 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 getOptionalByItem(@Nullable ItemStack item) { + return Optional.ofNullable(getByItem(item)); + } + } \ No newline at end of file