Added metadata support
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -3,7 +3,7 @@
|
|||||||
<groupId>org.forkzone.mc</groupId>
|
<groupId>org.forkzone.mc</groupId>
|
||||||
<artifactId>CustomCrafting</artifactId>
|
<artifactId>CustomCrafting</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<version>0.0.3-ALPHA</version>
|
<version>0.0.4-ALPHA</version>
|
||||||
<name>CustomCrafting</name>
|
<name>CustomCrafting</name>
|
||||||
<url></url>
|
<url></url>
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ public final class CustomCrafting extends JavaPlugin
|
|||||||
* @param xp (required) the xp the player will get for this
|
* @param xp (required) the xp the player will get for this
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
@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);
|
String[] item_array = getItemArray(item);
|
||||||
if(Material.getMaterial(item_array[0]) == null)
|
if(Material.getMaterial(item_array[0]) == null)
|
||||||
@@ -145,7 +145,10 @@ public final class CustomCrafting extends JavaPlugin
|
|||||||
return;
|
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))
|
if(!Bukkit.getServer().addRecipe(recipe))
|
||||||
getLogger().warning("Something went wrong! Cannot add \"" + name + "\"");
|
getLogger().warning("Something went wrong! Cannot add \"" + name + "\"");
|
||||||
else
|
else
|
||||||
@@ -160,7 +163,7 @@ public final class CustomCrafting extends JavaPlugin
|
|||||||
* @param shapeless (required) if the recipe is shapeless
|
* @param shapeless (required) if the recipe is shapeless
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
@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);
|
String[] item_array = getItemArray(item);
|
||||||
if(Material.getMaterial(item_array[0]) == null)
|
if(Material.getMaterial(item_array[0]) == null)
|
||||||
@@ -172,7 +175,10 @@ public final class CustomCrafting extends JavaPlugin
|
|||||||
else if(shapeless)
|
else if(shapeless)
|
||||||
{
|
{
|
||||||
String[][] shape_array = getShapeArraySL(shape);
|
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)
|
for(String[] ingredient_array : shape_array)
|
||||||
{
|
{
|
||||||
@@ -187,7 +193,10 @@ public final class CustomCrafting extends JavaPlugin
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
String[][][] shape_array = getShapeArray(shape);
|
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>();
|
Map<String, Character> map = new HashMap<String, Character>();
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
String[] recipe_shape = new String[3];
|
String[] recipe_shape = new String[3];
|
||||||
@@ -233,12 +242,24 @@ public final class CustomCrafting extends JavaPlugin
|
|||||||
for(String key : getConfig().getConfigurationSection("recipes").getKeys(false))
|
for(String key : getConfig().getConfigurationSection("recipes").getKeys(false))
|
||||||
{
|
{
|
||||||
NamespacedKey nkey = new NamespacedKey(this, key);
|
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))
|
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")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user