mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-07 16:01:55 +01:00
Initial item api rework
This commit is contained in:
parent
a1548fd35d
commit
308dbe0fdb
64
src/main/java/net/minestom/server/item/Item.java
Normal file
64
src/main/java/net/minestom/server/item/Item.java
Normal 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;
|
||||
}
|
||||
}
|
45
src/main/java/net/minestom/server/item/ItemBuilder.java
Normal file
45
src/main/java/net/minestom/server/item/ItemBuilder.java
Normal 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
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user