Initial item api rework

This commit is contained in:
themode 2021-03-31 16:50:08 +02:00
parent a1548fd35d
commit 308dbe0fdb
2 changed files with 109 additions and 0 deletions

View File

@ -0,0 +1,64 @@
package net.minestom.server.item;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.IntUnaryOperator;
public class Item {
private final Material material;
private final int amount;
private final Component displayName;
private final List<Component> lore;
protected Item(Material material, int amount, Component displayName, List<Component> lore) {
this.material = material;
this.amount = amount;
this.displayName = displayName;
this.lore = lore;
}
@NotNull
public static ItemBuilder builder(@NotNull Material material) {
return new ItemBuilder(material);
}
public ItemBuilder builder() {
return new ItemBuilder(material)
.amount(amount)
.displayName(displayName)
.lore(lore);
}
@NotNull
public Item with(@NotNull Consumer<ItemBuilder> builderConsumer) {
var builder = builder();
builderConsumer.accept(builder);
return builder.build();
}
public int getAmount() {
return amount;
}
@NotNull
public Item withAmount(int amount) {
return builder().amount(amount).build();
}
@NotNull
public Item withAmount(@NotNull IntUnaryOperator intUnaryOperator) {
return withAmount(intUnaryOperator.applyAsInt(amount));
}
public Component getDisplayName() {
return displayName;
}
public List<Component> getLore() {
return lore;
}
}

View File

@ -0,0 +1,45 @@
package net.minestom.server.item;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class ItemBuilder {
private int amount;
private Component displayName;
private List<Component> lore;
protected ItemBuilder(@NotNull Material material) {
}
public ItemBuilder amount(int amount) {
this.amount = amount;
return this;
}
public ItemBuilder displayName(Component displayName) {
this.displayName = displayName;
return this;
}
public ItemBuilder lore(Component... lore) {
this.lore = Arrays.asList(lore);
return this;
}
public ItemBuilder lore(List<Component> lore) {
this.lore = Collections.unmodifiableList(lore);
return this;
}
@NotNull
public Item build() {
return null; // TODO
}
}