Added furnance crafting recipes
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -3,7 +3,7 @@
|
||||
<groupId>org.forkzone.mc</groupId>
|
||||
<artifactId>CustomCrafting</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>0.0.2-ALPHA</version>
|
||||
<version>0.0.3-ALPHA</version>
|
||||
<name>CustomCrafting</name>
|
||||
<url></url>
|
||||
<build>
|
||||
|
||||
@@ -9,16 +9,38 @@ import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.inventory.FurnaceRecipe;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.ShapedRecipe;
|
||||
import org.bukkit.inventory.ShapelessRecipe;
|
||||
import org.bukkit.material.MaterialData;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
|
||||
/**
|
||||
* CustomCrafting Plugin for Bukkit by basma93
|
||||
*
|
||||
* <P>Allows to add custom crafting recipes for the workbench or furnace
|
||||
*
|
||||
* @author basman93
|
||||
* @version 0.0.3
|
||||
*
|
||||
*/
|
||||
public final class CustomCrafting extends JavaPlugin
|
||||
{
|
||||
/** Prefix {@value} for chat messages */
|
||||
private static final String PREFIX = "[CustomCrafting] ";
|
||||
//ArrayList<NamespacedKey> recipeList = new ArrayList<NamespacedKey>();
|
||||
|
||||
/** Version number to check if the configfile is uptodate */
|
||||
private static final int CONFIG_VERSION = 1;
|
||||
|
||||
/**
|
||||
* @param shape (required) raw shape string
|
||||
* @return returns the raw shape as an array:<br>
|
||||
* first level are the rows of the recipe,<br>
|
||||
* second level are the collums of the recipe,<br>
|
||||
* third level are the item ID's and Data values.
|
||||
*/
|
||||
private String[][][] getShapeArray(String shape)
|
||||
{
|
||||
String[][][] shape_array = new String[3][3][2];
|
||||
@@ -39,6 +61,17 @@ public final class CustomCrafting extends JavaPlugin
|
||||
return shape_array;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param shape (required) raw shape string
|
||||
* @return returns the raw shape as an array:<br>
|
||||
* first level are the different items,<br>
|
||||
* second level are the different attribute of the item:<br>
|
||||
* <ol>
|
||||
* <li>Item ID</li>
|
||||
* <li>Item data value</li>
|
||||
* <li>Item amount</li>
|
||||
* </ol>
|
||||
*/
|
||||
private String[][] getShapeArraySL(String shape)
|
||||
{
|
||||
ArrayList<String[]> shape_array = new ArrayList<String[]>();
|
||||
@@ -52,6 +85,15 @@ public final class CustomCrafting extends JavaPlugin
|
||||
return shape_array.toArray(new String[shape_array.size()][3]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param item (required) raw item string
|
||||
* @return returns the raw shape as an array:<br>
|
||||
* <ol>
|
||||
* <li>Item ID</li>
|
||||
* <li>Item data value</li>
|
||||
* <li>Item amount</li>
|
||||
* </ol>
|
||||
*/
|
||||
private String[] getItemArray(String item)
|
||||
{
|
||||
String[] item_array = new String[3];
|
||||
@@ -65,16 +107,58 @@ public final class CustomCrafting extends JavaPlugin
|
||||
return item_array;
|
||||
}
|
||||
|
||||
/** parse a string to a int */
|
||||
private int toInt(String string)
|
||||
{
|
||||
return Integer.parseInt(string);
|
||||
}
|
||||
|
||||
/** parse a string to a short */
|
||||
private short toShort(String string)
|
||||
{
|
||||
return Short.parseShort(string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a custom furnace recipe to bukkit
|
||||
* @param name (required) the name of the recipe
|
||||
* @param shape (required) the raw shape of the input item
|
||||
* @param item (required) the raw shape of the output item
|
||||
* @param xp (required) the xp the player will get for this
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
private void addNewFurnaceRecipe(String name, String shape, String item, float xp)
|
||||
{
|
||||
String[] item_array = getItemArray(item);
|
||||
if(Material.getMaterial(item_array[0]) == null)
|
||||
{
|
||||
getLogger().warning("Could not add \"" + name + "\"");
|
||||
getLogger().warning("Unknown: " + item_array[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
String[] shape_array = getItemArray(shape);
|
||||
if(Material.getMaterial(shape_array[0]) == null)
|
||||
{
|
||||
getLogger().warning("Could not add \"" + name + "\"");
|
||||
getLogger().warning("Unknown: " + shape_array[0]);
|
||||
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);
|
||||
if(!Bukkit.getServer().addRecipe(recipe))
|
||||
getLogger().warning("Something went wrong! Cannot add \"" + name + "\"");
|
||||
else
|
||||
getLogger().info("Add Furnace Recipe \"" + name + "\"");
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a custom crafting recipe to bukkit
|
||||
* @param name (required) the name of the recipe
|
||||
* @param shape (required) the raw shape of the input item
|
||||
* @param item (required) the raw shape of the output item
|
||||
* @param shapeless (required) if the recipe is shapeless
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
private void addNewRecipe(NamespacedKey name, String shape, String item, boolean shapeless)
|
||||
{
|
||||
@@ -96,20 +180,17 @@ public final class CustomCrafting extends JavaPlugin
|
||||
}
|
||||
|
||||
if(!Bukkit.getServer().addRecipe(recipe))
|
||||
getLogger().warning("Something went wrong!");
|
||||
getLogger().warning("Something went wrong! Cannot add \"" + name.getKey() + "\"");
|
||||
else
|
||||
getLogger().info("Add Recipe \"" + name.getKey() + "\"");
|
||||
}
|
||||
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])));
|
||||
|
||||
Map<String, Character> map = new HashMap<String, Character>();
|
||||
|
||||
int counter = 0;
|
||||
|
||||
String[] recipe_shape = new String[3];
|
||||
|
||||
for(int i = 0; i < shape_array.length; ++i)
|
||||
{
|
||||
recipe_shape[i] = "";
|
||||
@@ -128,9 +209,7 @@ public final class CustomCrafting extends JavaPlugin
|
||||
recipe_shape[i] += map.get(shape_array[i][j][0] + ":" + shape_array[i][j][1]);
|
||||
}
|
||||
}
|
||||
|
||||
recipe.shape(recipe_shape);
|
||||
|
||||
for (Map.Entry<String, Character> entry : map.entrySet())
|
||||
{
|
||||
if(!entry.getValue().equals(' '))
|
||||
@@ -139,43 +218,36 @@ public final class CustomCrafting extends JavaPlugin
|
||||
recipe.setIngredient(entry.getValue(), Material.getMaterial(buffer[0]), toInt(buffer[1]));
|
||||
}
|
||||
}
|
||||
|
||||
if(!Bukkit.getServer().addRecipe(recipe))
|
||||
getLogger().warning("Something went wrong!");
|
||||
getLogger().warning("Something went wrong! Cannot add \"" + name.getKey() + "\"");
|
||||
else
|
||||
getLogger().info("Add Recipe \"" + name.getKey() + "\"");
|
||||
}
|
||||
getLogger().info("Add Recipe \"" + name.getKey() + "\"");
|
||||
}
|
||||
|
||||
/**
|
||||
* reads the configfile and adds every recipe found in it.
|
||||
*/
|
||||
private void readConfigAndAddRecipe()
|
||||
{
|
||||
for(String key : getConfig().getConfigurationSection("recipes").getKeys(false))
|
||||
{
|
||||
NamespacedKey nkey = new NamespacedKey(this, key);
|
||||
//recipeList.add(nkey);
|
||||
addNewRecipe(nkey, getConfig().getString("recipes." + key + ".shape"), getConfig().getString("recipes." + key + ".item"), getConfig().getBoolean("recipes." + key + ".shapeless"));
|
||||
}
|
||||
|
||||
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"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* removes the custom recipes from bukkit.
|
||||
* At this moment its only possible to reset the recipes list to default.
|
||||
*/
|
||||
private void removeRecipe()
|
||||
{
|
||||
/*
|
||||
Iterator<Recipe> iter = Bukkit.getServer().recipeIterator();
|
||||
while(iter.hasNext())
|
||||
{
|
||||
Recipe r = iter.next();
|
||||
if(r != null && r instanceof ShapedRecipe)
|
||||
{
|
||||
if(recipeList.contains(((ShapedRecipe) r).getKey()))
|
||||
iter.remove();
|
||||
}
|
||||
else if(r != null && r instanceof ShapelessRecipe)
|
||||
{
|
||||
if(recipeList.contains(((ShapelessRecipe) r).getKey()))
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
recipeList.clear();
|
||||
*/
|
||||
Bukkit.getServer().resetRecipes();
|
||||
}
|
||||
|
||||
@@ -184,6 +256,11 @@ public final class CustomCrafting extends JavaPlugin
|
||||
{
|
||||
saveDefaultConfig();
|
||||
reloadConfig();
|
||||
|
||||
// Checks if the configfile is the required version, give out a warning otherwise.
|
||||
if(getConfig().getInt("version", 0) < CONFIG_VERSION)
|
||||
getLogger().warning("Please delete your configfile. Your configfile is outdated!");
|
||||
|
||||
readConfigAndAddRecipe();
|
||||
}
|
||||
|
||||
@@ -200,8 +277,9 @@ public final class CustomCrafting extends JavaPlugin
|
||||
{
|
||||
if(args.length == 1 && args[0].equalsIgnoreCase("reload") && sender.hasPermission("customcrafting.reload"))
|
||||
{
|
||||
reloadConfig();
|
||||
removeRecipe();
|
||||
saveDefaultConfig();
|
||||
reloadConfig();
|
||||
readConfigAndAddRecipe();
|
||||
sender.sendMessage(PREFIX + "reloaded!");
|
||||
}
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
#Do not edit the version number!
|
||||
#INFO: xp by furnace_recipes don't work at this moment
|
||||
version: 1
|
||||
recipes:
|
||||
dirtyDiamond:
|
||||
shapeless: false
|
||||
@@ -11,3 +14,12 @@ recipes:
|
||||
shapeless: false
|
||||
shape: "gold_block,gold_block,gold_block;gold_block,apple,gold_block;gold_block,gold_block,gold_block"
|
||||
item: "golden_apple:1"
|
||||
furnace_recipes:
|
||||
diamond_recycle:
|
||||
shape: "diamond_sword"
|
||||
item: "diamond:0#1"
|
||||
xp: 0
|
||||
breadfromwheat:
|
||||
shape: "HAY_BLOCK"
|
||||
item: "BREAD:0#3"
|
||||
xp: 0
|
||||
@@ -1,7 +1,7 @@
|
||||
name: CustomCrafting
|
||||
main: org.forkzone.mc.customcrafting.CustomCrafting
|
||||
version: "${project.version}"
|
||||
description: Add possibility to add custom crafting receipts to the game.
|
||||
description: Add possibility to add custom crafting recipts to the game.
|
||||
author: basman93
|
||||
commands:
|
||||
customcrafting:
|
||||
|
||||
Reference in New Issue
Block a user