1 Commits

Author SHA1 Message Date
0d9dc17128 Added metadata support 2018-01-25 20:25:56 +01:00
2 changed files with 29 additions and 8 deletions

View File

@@ -3,7 +3,7 @@
<groupId>org.forkzone.mc</groupId>
<artifactId>CustomCrafting</artifactId>
<packaging>jar</packaging>
<version>0.0.3-ALPHA</version>
<version>0.0.4-ALPHA</version>
<name>CustomCrafting</name>
<url></url>
<build>

View File

@@ -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<String, Character> map = new HashMap<String, Character>();
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")
);
}
}