Esempio n. 1
0
 private boolean removeShapeless(ShapelessRecipe recipe) {
   boolean failed = false;
   Plugin plugin = recipe.getPlugin();
   if (plugin != null) {
     if (!registeredShapelessRecipes.containsKey(plugin)) {
       return false;
     }
     if (!registeredShapelessRecipes.get(plugin).containsKey(recipe.getIngredients().size())) {
       return false;
     }
     if (!registeredShapelessRecipes
         .get(plugin)
         .get(recipe.getIngredients().size())
         .contains(recipe)) {
       return false;
     }
     failed =
         !registeredShapelessRecipes
                 .get(recipe.getPlugin())
                 .get(recipe.getIngredients().size())
                 .remove(recipe)
             || failed;
   }
   if (!allShapelessRecipes.containsKey(recipe.getIngredients().size())) {
     return false;
   }
   failed = !allShapelessRecipes.get(recipe.getIngredients().size()).remove(recipe) || failed;
   return !failed;
 }
Esempio n. 2
0
  private boolean registerShapeless(ShapelessRecipe recipe) {
    boolean failed = false;
    Plugin plugin = recipe.getPlugin();
    if (plugin != null) {
      ConcurrentHashMap<Integer, Set<ShapelessRecipe>> recipesMap =
          (ConcurrentHashMap<Integer, Set<ShapelessRecipe>>) registeredShapelessRecipes.get(plugin);
      if (recipesMap == null) {
        recipesMap = new ConcurrentHashMap<Integer, Set<ShapelessRecipe>>();
        registeredShapelessRecipes.put(plugin, recipesMap);
      }
      if (recipesMap.get(recipe.getIngredients().size()) == null) {
        Set<ShapelessRecipe> recipes =
            Collections.newSetFromMap(new ConcurrentHashMap<ShapelessRecipe, Boolean>());
        registeredShapelessRecipes.get(plugin).put(recipe.getIngredients().size(), recipes);
      }
      failed =
          !registeredShapelessRecipes.get(plugin).get(recipe.getIngredients().size()).add(recipe)
              || failed;
    }

    if (allShapelessRecipes.get(recipe.getIngredients().size()) == null) {
      Set<ShapelessRecipe> recipes =
          Collections.newSetFromMap(new ConcurrentHashMap<ShapelessRecipe, Boolean>());
      allShapelessRecipes.put(recipe.getIngredients().size(), recipes);
    }
    failed = !allShapelessRecipes.get(recipe.getIngredients().size()).add(recipe) || failed;
    return !failed;
  }