From 0d9dc1712862f18c222c267adb555f935c9072e6 Mon Sep 17 00:00:00 2001 From: basman93 Date: Thu, 25 Jan 2018 20:25:56 +0100 Subject: [PATCH] Added metadata support --- pom.xml | 2 +- .../mc/customcrafting/CustomCrafting.java | 35 +++++++++++++++---- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index abf264d..aa58a4a 100755 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ org.forkzone.mc CustomCrafting jar - 0.0.3-ALPHA + 0.0.4-ALPHA CustomCrafting diff --git a/src/main/java/org/forkzone/mc/customcrafting/CustomCrafting.java b/src/main/java/org/forkzone/mc/customcrafting/CustomCrafting.java index 11b40c2..833b7e2 100755 --- a/src/main/java/org/forkzone/mc/customcrafting/CustomCrafting.java +++ b/src/main/java/org/forkzone/mc/customcrafting/CustomCrafting.java @@ -127,7 +127,7 @@ public final class CustomCrafting extends JavaPlugin * @param xp (required) the xp the player will get for this */ @SuppressWarnings("deprecation") - private void addNewFurnaceRecipe(String name, String shape, String item, float xp) + private void addNewFurnaceRecipe(String name, String shape, String item, float xp, String nbtdata) { String[] item_array = getItemArray(item); if(Material.getMaterial(item_array[0]) == null) @@ -145,7 +145,10 @@ public final class CustomCrafting extends JavaPlugin return; } - FurnaceRecipe recipe = new FurnaceRecipe(new ItemStack(Material.getMaterial(item_array[0]), toInt(item_array[2]), toShort(item_array[1])), new MaterialData(Material.getMaterial(shape_array[0]), (byte) 0), xp); + ItemStack is = new ItemStack(Material.getMaterial(item_array[0]), toInt(item_array[2]), toShort(item_array[1])); + if(nbtdata != null && !nbtdata.isEmpty()) + Bukkit.getUnsafe().modifyItemStack(is, nbtdata); + FurnaceRecipe recipe = new FurnaceRecipe(is, new MaterialData(Material.getMaterial(shape_array[0]), (byte) 0), xp); if(!Bukkit.getServer().addRecipe(recipe)) getLogger().warning("Something went wrong! Cannot add \"" + name + "\""); else @@ -160,7 +163,7 @@ public final class CustomCrafting extends JavaPlugin * @param shapeless (required) if the recipe is shapeless */ @SuppressWarnings("deprecation") - private void addNewRecipe(NamespacedKey name, String shape, String item, boolean shapeless) + private void addNewRecipe(NamespacedKey name, String shape, String item, boolean shapeless, String nbtdata) { String[] item_array = getItemArray(item); if(Material.getMaterial(item_array[0]) == null) @@ -172,7 +175,10 @@ public final class CustomCrafting extends JavaPlugin else if(shapeless) { String[][] shape_array = getShapeArraySL(shape); - ShapelessRecipe recipe = new ShapelessRecipe(name, new ItemStack(Material.getMaterial(item_array[0]), toInt(item_array[2]), toShort(item_array[1]))); + ItemStack is = new ItemStack(Material.getMaterial(item_array[0]), toInt(item_array[2]), toShort(item_array[1])); + if(nbtdata != null && !nbtdata.isEmpty()) + Bukkit.getUnsafe().modifyItemStack(is, nbtdata); + ShapelessRecipe recipe = new ShapelessRecipe(name, is); for(String[] ingredient_array : shape_array) { @@ -187,7 +193,10 @@ public final class CustomCrafting extends JavaPlugin else { String[][][] shape_array = getShapeArray(shape); - ShapedRecipe recipe = new ShapedRecipe(name, new ItemStack(Material.getMaterial(item_array[0]), toInt(item_array[2]), toShort(item_array[1]))); + ItemStack is = new ItemStack(Material.getMaterial(item_array[0]), toInt(item_array[2]), toShort(item_array[1])); + if(nbtdata != null && !nbtdata.isEmpty()) + Bukkit.getUnsafe().modifyItemStack(is, nbtdata); + ShapedRecipe recipe = new ShapedRecipe(name, is); Map map = new HashMap(); int counter = 0; String[] recipe_shape = new String[3]; @@ -233,12 +242,24 @@ public final class CustomCrafting extends JavaPlugin for(String key : getConfig().getConfigurationSection("recipes").getKeys(false)) { NamespacedKey nkey = new NamespacedKey(this, key); - addNewRecipe(nkey, getConfig().getString("recipes." + key + ".shape"), getConfig().getString("recipes." + key + ".item"), getConfig().getBoolean("recipes." + key + ".shapeless")); + addNewRecipe( + nkey, + getConfig().getString("recipes." + key + ".shape"), + getConfig().getString("recipes." + key + ".item"), + getConfig().getBoolean("recipes." + key + ".shapeless"), + getConfig().getString("recipes." + key + ".nbt") + ); } for(String key : getConfig().getConfigurationSection("furnace_recipes").getKeys(false)) { - addNewFurnaceRecipe(key, getConfig().getString("furnace_recipes." + key + ".shape"), getConfig().getString("furnace_recipes." + key + ".item"), (float) getConfig().getDouble("furnace_recipes." + key + ".xp")); + addNewFurnaceRecipe( + key, + getConfig().getString("furnace_recipes." + key + ".shape"), + getConfig().getString("furnace_recipes." + key + ".item"), + (float) getConfig().getDouble("furnace_recipes." + key + ".xp"), + getConfig().getString("furnace_recipes." + key + ".nbt") + ); } }