Package digi.recipeManager.data

Examples of digi.recipeManager.data.Item


   *            item is ingredient (true) or result (false) ?
   * @return list of recipes
   */
  public List<Recipe> getRecipesForItem(ItemStack item, boolean ingredient)
  {
    return getRecipesForItem(new Item(item), ingredient);
  }
View Full Code Here


    recipeErrors.put(currentFile, errors);
  }
 
  protected ItemData processItemData(String string, int defaultData, boolean allowData, boolean printRecipeErrors)
  {
    Item item = processItem(string, defaultData, allowData, false, false, printRecipeErrors);
   
    return (item == null ? null : new ItemData(item));
  }
View Full Code Here

   
    String itemString[] = string.split("\\|");
    String stringArray[] = itemString[0].trim().split(":");
   
    if(stringArray.length <= 0 || stringArray[0].isEmpty())
      return new Item(0);
   
    stringArray[0] = stringArray[0].trim();
    String alias = RecipeManager.plugin.getAliases().get(stringArray[0]);
   
    if(alias != null)
    {
      if(stringArray.length > 2 && printRecipeErrors)
        recipeError("'" + stringArray[0] + "' is an alias with data and amount.", "You can only set amount e.g.: alias:amount.");
     
      return processItem(string.replace(stringArray[0], alias), defaultData, allowData, allowAmount, allowEnchantments, printRecipeErrors);
    }
   
    Material mat = Material.matchMaterial(stringArray[0]);
   
    if(mat == null)
    {
      if(printRecipeErrors)
        recipeError("Item '" + stringArray[0] + "' does not exist!", "Name could be different, look in readme.txt for links");
     
      return null;
    }
   
    int type = mat.getId();
   
    if(type <= 0)
      return new Item(0);
   
    int data = defaultData;
   
    if(stringArray.length > 1)
    {
      if(allowData)
      {
        try
        {
          stringArray[1] = stringArray[1].trim();
         
          if(stringArray[1].charAt(0) != '*')
            data = Math.max(Integer.valueOf(stringArray[1]), data);
        }
        catch(Exception e)
        {
          if(printRecipeErrors)
            recipeError("Item '" + mat + " has data value that is not a number: '" + stringArray[1] + "', defaulting to " + defaultData);
        }
      }
      else if(printRecipeErrors)
        recipeError("Item '" + mat + "' can't have data value defined in this recipe's slot, data value ignored.");
    }
   
    int amount = 1;
   
    if(stringArray.length > 2)
    {
      if(allowAmount)
      {
        try
        {
          amount = Math.max(Integer.valueOf(stringArray[2].trim()), 1);
        }
        catch(Exception e)
        {
          if(printRecipeErrors)
            recipeError("Item '" + mat + "' has amount value that is not a number: " + stringArray[2] + ", defaulting to 1");
        }
      }
      else if(printRecipeErrors)
        recipeError("Item '" + mat + "' can't have amount defined in this recipe's slot, amount ignored.");
    }
   
    Item item = new Item(type, amount, (short)data);
   
    if(itemString.length > 1)
    {
      if(allowEnchantments)
      {
        if(item.getAmount() > 1)
        {
          if(printRecipeErrors)
            recipeError("Item '" + mat + "' has enchantments and more than 1 amount, it can't have both, amount set to 1.");
         
          item.setAmount(1);
        }
       
        String[] enchants = itemString[1].split(",");
        String[] enchData;
        Enchantment ench;
        int level;
       
        for(String enchant : enchants)
        {
          enchant = enchant.trim();
          enchData = enchant.split(":");
         
          if(enchData.length != 2)
          {
            if(printRecipeErrors)
              recipeError("Enchantments have to be 'ENCHANTMENT:LEVEL' format.", "Look in readme.txt for enchantment list link.");
           
            continue;
          }
         
          ench = Enchantment.getByName(enchData[0]);
         
          if(ench == null)
          {
            try
            {
              ench = Enchantment.getById(Integer.valueOf(enchData[0]));
            }
            catch(Exception e)
            {
              ench = null;
            }
           
            if(ench == null)
            {
              if(printRecipeErrors)
                recipeError("Enchantment '" + enchData[0] + "' does not exist!", "Name or ID could be different, look in readme.txt for enchantments list links.");
             
              continue;
            }
          }
         
          if(enchData[1].equals("MAX"))
            level = ench.getMaxLevel();
         
          else
          {
            try
            {
              level = Integer.valueOf(enchData[1]);
            }
            catch(Exception e)
            {
              if(printRecipeErrors)
                recipeError("Invalid enchantment level: '" + enchData[1] + "' must be a valid number, positive, zero or negative.");
             
              continue;
            }
          }
         
          item.addEnchantment(ench, level);
        }
      }
      else if(printRecipeErrors)
        recipeError("Item '" + mat + "' can't use enchantments in this recipe slot!");
    }
View Full Code Here

    if(results == null)
      return null;
   
    ShapelessRecipe bukkitRecipe = new ShapelessRecipe(new ItemStack(placeholderItem.getTypeId(), combineNum, placeholderItem.getDurability()));
    List<Item> ingredients = new ArrayList<Item>();
    Item item;
    int items = 0;
   
    for(String itemRaw : ingredientsRaw)
    {
      item = processItem(itemRaw, -1, true, true, false, true);
     
      if(item == null)
        return new String[]
        {
          "Recipe has some invalid ingredients, fix them!"
        };
     
      if((items += item.getAmount()) > 9)
        return new String[]
        {
          "Combine recipes can't have more than 9 ingredients !"
        };
     
      ingredients.add(item);
      bukkitRecipe.addIngredient(item.getAmount(), item.getMaterial(), item.getData());
    }
   
    if(simulation)
      return null;
   
View Full Code Here

      return null;
   
    if(results.size() > 1)
      recipeError("Can't have more than 1 result in this recipe, the rest were ignored.");
   
    Item result = results.get(0);
   
    // TODO: revert allowData to true when data values for furnaces have been fixed
    ItemData ingredient = processItemData(split[0], -1, false, true);
   
    if(ingredient == null)
      return new String[]
      {
        "Invalid ingredient '" + split[0] + "'.",
        "Name could be diferent, look in readme.txt for links."
      };
   
    double minTime = -1.0;
    double maxTime = -1.0;
   
    if(split.length >= 2)
    {
      String[] timeSplit = split[1].trim().split("-");
     
      if(!timeSplit[0].equals("INSTANT"))
      {
        minTime = Double.valueOf(timeSplit[0]);
       
        if(timeSplit.length >= 2)
          maxTime = Double.valueOf(timeSplit[1]);
      }
      else
        minTime = 0.0;
     
      if(maxTime > -1.0 && minTime >= maxTime)
        return new String[]
        {
          "Smelting recipe has minimum time less or equal to maximum time!",
          "Use a single number if you want a fixed value."
        };
    }
   
    // the recipe
   
    if(simulation)
      return null;
   
    if(smeltRecipes.containsKey(ingredient.getType() + (ingredient.getData() == -1 ? "" : ":" + ingredient.getData())))
      return new String[]
      {
        "Recipe for '" + ingredient.printItemData() + "' is already defined in one of your recipe files.",
        (recipe.getOverride() ? "You can't override recipes that are already handled by this plugin because you can simply edit them!" : null)
      };
   
    Iterator<org.bukkit.inventory.Recipe> recipes = Bukkit.getServer().recipeIterator();
    org.bukkit.inventory.Recipe rec;
    FurnaceRecipe r;
    String ingredientsString = "smelt," + ingredient.convertString();
    boolean override = recipe.getOverride();
    boolean exists = false;
   
    while(recipes.hasNext())
    {
      rec = recipes.next();
     
      if(rec == null || !(rec instanceof FurnaceRecipe) || isCustomRecipe(rec.getResult()))
        continue;
     
      r = (FurnaceRecipe)rec;
     
      if(ingredient.compareItemStack(r.getInput()))
      {
        exists = true;
       
        if(override)
        {
          recipes.remove();
          overriddenRecipes.add(ingredientsString);
        }
      }
    }
   
    if(override)
    {
      if(!exists && !overriddenRecipes.contains(ingredientsString))
        recipeError("The @override flag couldn't find the original recipe to override, added new recipe instead.");
    }
    else
    {
      if(exists)
        return new String[]
        {
          "Recipe for '" + ingredient.printItemData() + "' already exists! It's either vanilla or added by another plugin/mod.",
          "Add @override flag to the recipe to supercede it."
        };
    }
   
    if(!Bukkit.addRecipe(new FurnaceRecipe((result.getType() == 0 ? new ItemStack(placeholderItem.getTypeId()) : result.getItemStack()), ingredient.getMaterial(), ingredient.getData())))
      return new String[]
      {
        "Couldn't add recipe to server, unknown error"
      };
   
View Full Code Here

  }
 
  private List<Item> getResults(String line, BufferedReader reader, boolean allowAir, boolean oneResult) throws Exception
  {
    List<Item> results = new ArrayList<Item>();
    Item noPercentItem = null;
    String[] resultRawSplit;
    Item item;
    int totalpercentage = 0;
   
    while(line != null && !line.isEmpty() && line.charAt(0) == '=')
    {
      resultRawSplit = line.substring(1).trim().split("%"); // remove the = character and see if it's got percentage
     
      if(resultRawSplit.length >= 2)
      {
        item = processItem(resultRawSplit[1].trim(), 0, true, true, true, true);
       
        if(item == null || (!allowAir && item.getType() == 0))
        {
          recipeError("Invalid result !");
          return null;
        }
       
        try
        {
          item.setChance(Math.min(Math.max(Integer.valueOf(resultRawSplit[0].trim()), 0), 100));
        }
        catch(Exception e)
        {
          recipeError("Invalid percentage number: " + resultRawSplit[0]);
          return null;
        }
       
        if((totalpercentage += item.getChance()) > 100)
        {
          recipeError("Total result items' chance exceeds 100% !", "Not defining percentage for one item will make its chance fit with the rest until 100%");
          return null;
        }
       
        results.add(item);
      }
      else
      {
        if(resultRawSplit[0] == null)
        {
          recipeError("Missing result !");
          return null;
        }
       
        if(noPercentItem != null)
        {
          recipeError("Can't have more than 1 item without procentage to fill the rest!");
          return null;
        }
       
        noPercentItem = processItem(resultRawSplit[0].trim(), 0, true, true, true, true);
       
        if(noPercentItem == null || (!allowAir && noPercentItem.getType() == 0))
        {
          recipeError("Invalid result !");
          return null;
        }
      }
     
      line = processLine(readLine(reader), true);
    }
   
    if(noPercentItem != null)
    {
      noPercentItem.setChance(100 - totalpercentage);
      results.add(noPercentItem);
    }
    else if(results.isEmpty())
    {
      recipeError("Missing result !");
      return null;
    }
    else if(!oneResult && totalpercentage < 100)
      results.add(new Item(0, 0, (short)0, (100 - totalpercentage)));
   
    return results;
  }
View Full Code Here

TOP

Related Classes of digi.recipeManager.data.Item

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.