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

Merge pull request #3962 from JustAHuman-xD/api/slimefun-item-get-optional-by

Add SlimefunItem#getOptionalByX
This commit is contained in:
Sfiguz7 2023-09-06 11:27:20 +02:00 committed by GitHub
commit 4d7c13e350
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1159,6 +1159,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}.
*
@ -1181,4 +1192,14 @@ public class SlimefunItem implements Placeable {
}
/**
* 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));
}
}