diff --git a/src/main/java/io/github/simplexdev/simplexcore/crafting/ItemBuilder.java b/src/main/java/io/github/simplexdev/simplexcore/crafting/ItemBuilder.java new file mode 100644 index 0000000..65a3387 --- /dev/null +++ b/src/main/java/io/github/simplexdev/simplexcore/crafting/ItemBuilder.java @@ -0,0 +1,90 @@ +package io.github.simplexdev.simplexcore.crafting; + +import io.github.simplexdev.simplexcore.module.SimplexModule; +import io.github.simplexdev.simplexcore.utils.Utilities; +import org.bukkit.Material; +import org.bukkit.attribute.Attribute; +import org.bukkit.attribute.AttributeModifier; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.inventory.ItemFlag; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import java.util.Arrays; + +public class ItemBuilder { + private final SimplexModule plugin; + + public ItemBuilder(SimplexModule plugin) { + this.plugin = plugin; + } + + public ItemStack createNoBounds(Material material) { + return new ItemStack(material, 1); + } + + public ItemStack createWithMeta(Material material, ItemMeta metaData) { + ItemStack stack = new ItemStack(material, 1); + stack.setItemMeta(metaData); + return stack; + } + + public Worker itemBuilder(Material material) { + return new Worker(new ItemStack(material, 1)); + } + + public AttributeModifier add(String name, double amount, boolean scalar) { + if (scalar) { + return new AttributeModifier(name, amount, AttributeModifier.Operation.ADD_SCALAR); + } + return new AttributeModifier(name, amount, AttributeModifier.Operation.ADD_NUMBER); + } + + public AttributeModifier multiply(String name, double amount) { + return new AttributeModifier(name, amount, AttributeModifier.Operation.MULTIPLY_SCALAR_1); + } + + protected final class Worker { + private final ItemStack stack; + private final ItemMeta meta; + + public Worker(ItemStack stack) { + this.stack = stack; + this.meta = stack.getItemMeta(); + } + + public final Worker addLore(String... lore) { + meta.setLore(Arrays.asList(lore)); + stack.setItemMeta(meta); + return this; + } + + public final Worker setName(String customName) { + meta.setDisplayName(customName); + stack.setItemMeta(meta); + return this; + } + + public final Worker addEnchant(Enchantment enchantment, int level) { + meta.addEnchant(enchantment, level, true); + stack.setItemMeta(meta); + return this; + } + + public final Worker addAttribute(Attribute attribute, AttributeModifier modifier) { + meta.addAttributeModifier(attribute, modifier); + stack.setItemMeta(meta); + return this; + } + + public final Worker addItemFlags(ItemFlag... flags) { + meta.addItemFlags(flags); + stack.setItemMeta(meta); + return this; + } + + public final ItemStack get() { + return stack; + } + } +} diff --git a/src/main/java/io/github/simplexdev/simplexcore/crafting/RBImpl.java b/src/main/java/io/github/simplexdev/simplexcore/crafting/RBImpl.java new file mode 100644 index 0000000..a4b8770 --- /dev/null +++ b/src/main/java/io/github/simplexdev/simplexcore/crafting/RBImpl.java @@ -0,0 +1,47 @@ +package io.github.simplexdev.simplexcore.crafting; + +import io.github.simplexdev.simplexcore.module.SimplexModule; +import org.bukkit.Material; +import org.bukkit.attribute.Attribute; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.inventory.ItemStack; + +public class RBImpl { + private final RecipeBuilder builder; + private final SimplexModule plugin; + private final ItemBuilder bldr; + + public RBImpl(SimplexModule plugin) { + this.plugin = plugin; + this.builder = new RecipeBuilder(plugin); + this.bldr = new ItemBuilder(plugin); + + chainMailBoots(); + customWand(); + } + + public void chainMailBoots() { + ItemStack is = bldr.createNoBounds(Material.CHAINMAIL_BOOTS); + builder.of(is, "chainmail_boots", true) + .addIngredient('c', Material.CHAIN) + .addIngredient('a', Material.AIR) + .setShape("aaa", "cac", "cac") + .create(); + } + + public void customWand() { + ItemStack is = bldr.itemBuilder(Material.BLAZE_ROD) + .setName("Magic Wand") + .addLore("This wand is magical.") + .addEnchant(Enchantment.KNOCKBACK, 10) + .addAttribute(Attribute.GENERIC_ATTACK_KNOCKBACK, + bldr.multiply("generic_attack_knockback", 24.0)) + .get(); + builder.of(is, "magic_wand", true) + .addIngredient('b', Material.BLAZE_ROD) + .addIngredient('n', Material.NETHER_STAR) + .addIngredient('a', Material.AIR) + .setShape("aan", "aba", "baa") + .create(); + } +} diff --git a/src/main/java/io/github/simplexdev/simplexcore/crafting/RecipeBuilder.java b/src/main/java/io/github/simplexdev/simplexcore/crafting/RecipeBuilder.java index 0fe0136..7090cd0 100644 --- a/src/main/java/io/github/simplexdev/simplexcore/crafting/RecipeBuilder.java +++ b/src/main/java/io/github/simplexdev/simplexcore/crafting/RecipeBuilder.java @@ -26,13 +26,13 @@ public final class RecipeBuilder { return new Worker(result, recipeName, isShaped); } - private final class Worker { + protected final class Worker { private final Map ingredients = new HashMap<>(); private final ItemStack stack; private final NamespacedKey key; private final boolean shaped; private final List materials = new ArrayList<>(); - private String[] shape = {"", "", ""}; + private String[] shape = {"aaa", "aaa", "aaa"}; public Worker(ItemStack stack, String name, boolean isShaped) { this.stack = stack; @@ -57,7 +57,7 @@ public final class RecipeBuilder { return recipe; } - public void make() { + public void create() { plugin.getServer().addRecipe(shaped ? sha() : nosha()); }