Allow to directly pass an ItemMeta

This commit is contained in:
themode 2021-04-01 20:06:10 +02:00
parent cbfeb4e15b
commit 066b041bba
2 changed files with 13 additions and 1 deletions

View File

@ -18,7 +18,7 @@ public class ItemBuilder {
protected ItemBuilder(@NotNull Material material, @NotNull ItemMetaBuilder metaBuilder) {
this.material = material;
this.amount = 0;
this.metaBuilder=metaBuilder;
this.metaBuilder = metaBuilder;
}
protected ItemBuilder(@NotNull Material material) {
@ -32,6 +32,12 @@ public class ItemBuilder {
return this;
}
@Contract(value = "_ -> this")
public @NotNull ItemBuilder meta(@NotNull ItemMeta itemMeta) {
this.metaBuilder = itemMeta.builder();
return this;
}
@Contract(value = "_, _ -> this")
public <T extends ItemMetaBuilder> @NotNull ItemBuilder meta(Class<T> metaType, Consumer<T> itemMetaConsumer) {
itemMetaConsumer.accept((T) metaBuilder);

View File

@ -66,8 +66,14 @@ public class PlayerInit {
//inventory.setItemStack(3, new ItemStack(Material.DIAMOND, (byte) 34));
{
CompassMeta compassMeta = new CompassMeta.Builder()
.lodestonePosition(new Position(0, 0, 0))
.build();
Item item = Item.builder(Material.COMPASS)
.amount(5)
.meta(compassMeta)
.meta(CompassMeta.Builder.class, builder -> {
builder.lodestonePosition(new Position(0, 0, 0));
})