Refactor ItemStackBuilder#meta to use ItemStack#editMeta method

This commit is contained in:
Marc Baloup 2023-01-07 17:22:09 +01:00
parent c5e59537a0
commit 721175f965
Signed by: marcbal
GPG Key ID: BBC0FE3ABC30B893

View File

@ -92,19 +92,14 @@ public class ItemStackBuilder {
} }
public ItemStackBuilder meta(Consumer<ItemMeta> metaUpdater) { public ItemStackBuilder meta(Consumer<ItemMeta> metaUpdater) {
metaUpdater.accept(getOrInitMeta()); return meta(metaUpdater, ItemMeta.class);
updateMeta();
return this;
} }
public <T extends ItemMeta> ItemStackBuilder meta(Consumer<T> metaUpdater, Class<T> metaType) { public <T extends ItemMeta> ItemStackBuilder meta(Consumer<T> metaUpdater, Class<T> metaType) {
ItemMeta m = getOrInitMeta(); stack.editMeta(metaType, m -> {
if (!metaType.isInstance(m)) { metaUpdater.accept(m);
Log.warning("Item meta of " + stack.getType() + " is not of type " + metaType.getSimpleName(), new Throwable()); cachedMeta = m;
return this; });
}
metaUpdater.accept(metaType.cast(m));
updateMeta();
return this; return this;
} }