mirror of
https://github.com/HibiscusMC/HibiscusCommons.git
synced 2025-12-19 15:09:26 +00:00
feat: move to static for initializations of ItemBuilder
This commit is contained in:
@@ -63,7 +63,7 @@ public class ItemBuilderSerializer implements TypeSerializer<ItemBuilder> {
|
|||||||
|
|
||||||
if (materialNode.virtual()) return null;
|
if (materialNode.virtual()) return null;
|
||||||
|
|
||||||
ItemBuilder builder = new ItemBuilder(materialNode.getString("AIR"));
|
ItemBuilder builder = ItemBuilder.of(materialNode.getString("AIR"));
|
||||||
if (!amountNode.virtual()) builder.amount(amountNode.getInt(1));
|
if (!amountNode.virtual()) builder.amount(amountNode.getInt(1));
|
||||||
if (!nameNode.virtual()) builder.name(nameNode.getString(""));
|
if (!nameNode.virtual()) builder.name(nameNode.getString(""));
|
||||||
if (!unbreakableNode.virtual()) builder.unbreakable(unbreakableNode.getBoolean());
|
if (!unbreakableNode.virtual()) builder.unbreakable(unbreakableNode.getBoolean());
|
||||||
|
|||||||
@@ -39,19 +39,31 @@ public class ItemBuilder {
|
|||||||
private boolean glowing = false;
|
private boolean glowing = false;
|
||||||
private Color color;
|
private Color color;
|
||||||
|
|
||||||
public ItemBuilder(String material) {
|
public static @NotNull ItemBuilder of(@NotNull String material) {
|
||||||
|
return new ItemBuilder(material);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull ItemBuilder of(@NotNull Material material) {
|
||||||
|
return new ItemBuilder(material);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull ItemBuilder of(@NotNull ItemStack itemStack) {
|
||||||
|
return new ItemBuilder(itemStack);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ItemBuilder(String material) {
|
||||||
material(material);
|
material(material);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemBuilder(Material material) {
|
private ItemBuilder(Material material) {
|
||||||
material(material.toString());
|
material(material.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemBuilder(@NotNull ItemStack itemStack) {
|
private ItemBuilder(@NotNull ItemStack itemStack) {
|
||||||
this.material = Hooks.getStringItem(itemStack);
|
this.material = Hooks.getStringItem(itemStack);
|
||||||
this.amount = itemStack.getAmount();
|
this.amount = itemStack.getAmount();
|
||||||
ItemMeta meta = itemStack.getItemMeta();
|
ItemMeta meta = itemStack.getItemMeta();
|
||||||
if (meta == null) return;
|
if (meta == null) meta = Objects.requireNonNull(Bukkit.getItemFactory().getItemMeta(itemStack.getType()));
|
||||||
if (meta.hasDisplayName()) this.display = meta.getDisplayName();
|
if (meta.hasDisplayName()) this.display = meta.getDisplayName();
|
||||||
if (meta.hasCustomModelData()) this.model = meta.getCustomModelData();
|
if (meta.hasCustomModelData()) this.model = meta.getCustomModelData();
|
||||||
if (meta.isUnbreakable()) this.unbreakable = true;
|
if (meta.isUnbreakable()) this.unbreakable = true;
|
||||||
@@ -368,7 +380,7 @@ public class ItemBuilder {
|
|||||||
if (itemStack == null) return null;
|
if (itemStack == null) return null;
|
||||||
itemStack.setAmount(amount);
|
itemStack.setAmount(amount);
|
||||||
ItemMeta meta = itemStack.getItemMeta();
|
ItemMeta meta = itemStack.getItemMeta();
|
||||||
if (meta == null) return itemStack;
|
if (meta == null) meta = Objects.requireNonNull(Bukkit.getItemFactory().getItemMeta(itemStack.getType()));
|
||||||
if (display != null) meta.setDisplayName(StringUtils.parseStringToString(display));
|
if (display != null) meta.setDisplayName(StringUtils.parseStringToString(display));
|
||||||
if (model >= 0) meta.setCustomModelData(model);
|
if (model >= 0) meta.setCustomModelData(model);
|
||||||
if (!lore.isEmpty()) {
|
if (!lore.isEmpty()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user