Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ItemUtils#changeItemMeta, #setItem #7217

Open
wants to merge 13 commits into
base: dev/feature
Choose a base branch
from

Conversation

TheAbsolutionism
Copy link
Contributor

@TheAbsolutionism TheAbsolutionism commented Nov 15, 2024

Description

This PR is to help with shorthand ItemStack changes.
Example: (Before)

for (Object object : getExpr().getArray(event)) {
    ItemStack item = ItemUtils.asItemStack(object);
    if (item == null)
        continue;
    ItemMeta meta = item.getItemMeta();
    consumer.accept(meta);
    item.setItemMeta(meta);
    if (object instanceof Slot slot) {
        slot.setItem(item);
    } else if (object instaceof ItemType itemType) {
        itemType.setItemMeta(meta);
    } else if (object instanceof ItemStack itemStack) {
        itemStack.setItemMeta(meta);
    }
}

(After)

for (Object object : getExpr().getArray(event)) {
    ItemStack item = ItemUtils.asItemStack(object);
    if (item == null)
        continue;
    ItemUtils.setItem(object, ItemUtils.changeItemMeta(item, consumer));
}

Obviously this will more than likely be up for debate but here's hoping.


Target Minecraft Versions: any
Requirements: none
Related Issues: none

@sovdeeth sovdeeth added the feature Pull request adding a new feature. label Nov 16, 2024
Copy link
Member

@APickledWalrus APickledWalrus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. It might be nice to have a changeItemMeta method that lets you work with specific ItemMeta implementations. See https://jd.papermc.io/paper/1.19/org/bukkit/inventory/ItemStack.html#editMeta(java.lang.Class,java.util.function.Consumer)

src/main/java/ch/njol/skript/bukkitutil/ItemUtils.java Outdated Show resolved Hide resolved
src/main/java/ch/njol/skript/bukkitutil/ItemUtils.java Outdated Show resolved Hide resolved
@TheAbsolutionism
Copy link
Contributor Author

Looks good. It might be nice to have a changeItemMeta method that lets you work with specific ItemMeta implementations. See https://jd.papermc.io/paper/1.19/org/bukkit/inventory/ItemStack.html#editMeta(java.lang.Class,java.util.function.Consumer)

I thought you had said because my method is almost the exact same as Paper's editMeta, it would be better off leaving as is?

@Fusezion
Copy link
Contributor

Fusezion commented Dec 17, 2024

Looks good. It might be nice to have a changeItemMeta method that lets you work with specific ItemMeta implementations. See https://jd.papermc.io/paper/1.19/org/bukkit/inventory/ItemStack.html#editMeta(java.lang.Class,java.util.function.Consumer)

I thought you had said because my method is almost the exact same as Paper's editMeta, it would be better off leaving as is?

I believe the idea behind his suggestion is to accept a meta class in the parameter similar to how paper does

@sovdeeth sovdeeth added the 2.10 Targeting a 2.10.X version release label Dec 17, 2024
@Efnilite Efnilite added the feature-ready A PR/issue that has been approved, tested and can be merged/closed in the next feature version. label Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.10 Targeting a 2.10.X version release feature Pull request adding a new feature. feature-ready A PR/issue that has been approved, tested and can be merged/closed in the next feature version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants