4 Commits

Author SHA1 Message Date
0d9dc17128 Added metadata support 2018-01-25 20:25:56 +01:00
66f327a581 Update README.md
Added latest CustomCrafting version
2018-01-01 20:38:12 +00:00
275be9812e Added furnance crafting recipes 2018-01-01 21:31:19 +01:00
87e0f5b6bb Update README.md 2018-01-01 15:44:51 +00:00
5 changed files with 433 additions and 317 deletions

View File

@@ -1 +1,6 @@
Bukkit Plugin
Download the Plugin here:
* [Latest](https://gitlab.com/basman93/CustomCrafting/uploads/1cb1378b7ac7ab88ebce876dfa648417/CustomCrafting-0.0.3-ALPHA.jar)
* [Version 0.0.3-Alpha](https://gitlab.com/basman93/CustomCrafting/uploads/1cb1378b7ac7ab88ebce876dfa648417/CustomCrafting-0.0.3-ALPHA.jar)
* [Version 0.0.2-Alpha](https://gitlab.com/basman93/CustomCrafting/uploads/b711ed3061aaaadaffe9f9dd954f1237/CustomCrafting-0.0.2-ALPHA.jar)

View File

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

View File

@@ -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,18 +107,63 @@ 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 addNewRecipe(NamespacedKey name, String shape, String item, boolean shapeless)
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)
{
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;
}
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
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, String nbtdata)
{
String[] item_array = getItemArray(item);
if(Material.getMaterial(item_array[0]) == null)
@@ -88,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)
{
@@ -96,20 +186,20 @@ 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])));
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];
for(int i = 0; i < shape_array.length; ++i)
{
recipe_shape[i] = "";
@@ -128,9 +218,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 +227,48 @@ 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"));
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"),
getConfig().getString("furnace_recipes." + key + ".nbt")
);
}
}
/**
* 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 +277,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 +298,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!");
}

View File

@@ -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

View File

@@ -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: