Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Map;
- import java.util.Map.Entry;
- import org.bukkit.Material;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.inventory.Recipe;
- import org.bukkit.inventory.ShapedRecipe;
- import org.ourcraft.daskrr.smp.inventory.items.handler.ItemModifier.MArmor;
- import org.ourcraft.daskrr.smp.inventory.items.handler.ItemModifier.MWeapon;
- import com.google.common.collect.Maps;
- public class CustomShapedRecipe extends CustomRecipe
- {
- protected ItemStack result;
- protected String[] shape = new String[3];
- protected ItemStack[] matrix = new ItemStack[9];
- public CustomShapedRecipe (ItemStack result)
- {
- super(result);
- this.recipe = new ShapedRecipe (key(), result);
- }
- public CustomShapedRecipe (ShapedRecipe recipe)
- {
- super(recipe.getResult());
- this.recipe = recipe;
- if (recipe.getShape().length > 0)
- shape[0] = recipe.getShape()[0];
- else
- shape[0] = " ";
- if (recipe.getShape().length > 1)
- shape[1] = recipe.getShape()[1];
- else
- shape[1] = " ";
- if (recipe.getShape().length > 2)
- shape[2] = recipe.getShape()[2];
- else
- shape[2] = " ";
- Map<Character, ItemStack> finalMap = Maps.newHashMap();
- for (Entry<Character, ItemStack> entry : recipe.getIngredientMap().entrySet())
- {
- if (entry.getValue() == null)
- continue;
- ItemStack ingredientFinal = new ItemStack(entry.getValue());
- if (!entry.getValue().hasItemMeta())
- if (MWeapon.contains(entry.getValue().getType().toString()))
- ingredientFinal = MWeapon.convertDefaultItem(new ItemStack(entry.getValue()));
- else if (MArmor.contains(entry.getValue().getType().toString()))
- ingredientFinal = MArmor.convertDefaultItem(new ItemStack(entry.getValue()));
- finalMap.put(entry.getKey(), ingredientFinal);
- }
- int row = 0;
- for (String line : recipe.getShape())
- {
- int index = 0;
- for (String ing : line.split("(?!^)"))
- {
- if (!ing.equals(" "))
- matrix[row + index] = finalMap.get(ing.charAt(0));
- index++;
- }
- row += 3;
- }
- }
- public CustomShapedRecipe shape(String m0, String m1, String m2)
- {
- shape[0] = m0;
- shape[1] = m1;
- shape[2] = m2;
- ((ShapedRecipe) recipe).shape(m0, m1, m2);
- return this;
- }
- public CustomShapedRecipe setIngredient (char key, ItemStack ingredient)
- {
- ((ShapedRecipe) recipe).setIngredient(key, ingredient.getType());
- int row = 0;
- for (String line : shape)
- {
- int index = 0;
- for (String item : line.split("(?!^)"))
- {
- if (item.equals(String.valueOf(key)))
- matrix[row + index] = ingredient;
- index++;
- }
- row += 3;
- }
- return this;
- }
- public CustomShapedRecipe setIngredient (char key, Material ingredient)
- {
- ((ShapedRecipe) recipe).setIngredient(key, ingredient);
- ItemStack ingredientFinal;
- if (MWeapon.contains(ingredient.toString()))
- ingredientFinal = MWeapon.convertDefaultItem(new ItemStack(ingredient));
- else if (MArmor.contains(ingredient.toString()))
- ingredientFinal = MArmor.convertDefaultItem(new ItemStack(ingredient));
- else
- ingredientFinal = new ItemStack(ingredient);
- int row = 0;
- for (String line : shape)
- {
- int index = 0;
- for (String item : line.split("(?!^)"))
- {
- if (item.equals(String.valueOf(key)))
- matrix[row + index] = ingredientFinal;
- index++;
- }
- row += 3;
- }
- return this;
- }
- public ItemStack[] getMatrix()
- {
- return this.matrix;
- }
- @Override
- public Recipe getBukkitRecipe ()
- {
- return recipe;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement