Skip to content

Commit

Permalink
Resolve issues with ProRecipes.
Browse files Browse the repository at this point in the history
- Ignore null recipe results.
- Ignore recipes with all null results.
- Ignore air ingredients.
  • Loading branch information
BenWoodworth committed Nov 15, 2016
1 parent bab87f2 commit e9ee6d2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>co.kepler.fastcraftplus</groupId>
<artifactId>fastcraftplus</artifactId>
<version>0.26.1</version>
<version>0.26.2</version>

<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import co.kepler.fastcraftplus.recipes.Ingredient;
import mc.mcgrizzz.prorecipes.ProRecipes;
import mc.mcgrizzz.prorecipes.RecipeAPI;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Recipe;
Expand Down Expand Up @@ -56,6 +57,7 @@ public Set<FastRecipe> getRecipes(Player player) {
for (int id = 0; id < count; id++) {
// Get the recipe of this type and id
RecipeAPI.RecipeContainer recipe = api.getRecipe(type, id);
if (allNullOrAir(recipe.getResult())) continue;
if (player == null || !recipe.hasPermission() || player.hasPermission(recipe.getPermission())) {
// If player has permission to craft
FastRecipe fastRecipe = getRecipe(recipe);
Expand All @@ -66,6 +68,13 @@ public Set<FastRecipe> getRecipes(Player player) {
return recipes;
}

public boolean allNullOrAir(ItemStack... items) {
for (ItemStack is : items)
if (is != null && is.getType() != Material.AIR)
return false;
return true;
}

public FastRecipe getRecipe(RecipeAPI.RecipeContainer recipe) {
int hash = hash(recipe);
if (!loadRecipe(recipe, hash)) return null;
Expand All @@ -92,10 +101,15 @@ public int hash(RecipeAPI.RecipeContainer recipe) {
}

public static class FastRecipeCompat extends FastRecipe {
private final List<ItemStack> results = new ArrayList<>();
private final List<ItemStack> results;

public FastRecipeCompat(RecipeAPI.RecipeContainer recipe) {
Collections.addAll(results, recipe.getResult());
results = new ArrayList<>(4);
for (ItemStack result : recipe.getResult()) {
if (result != null && result.getType() != Material.ACACIA_DOOR)
results.add(result);
}

for (ItemStack is : recipe.getIngredients()) {
if (is == null) continue;
addIngredient(new Ingredient(is));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public abstract class FastRecipe implements Comparable<FastRecipe> {
* @param ingredient The ingredient to add.
*/
protected void addIngredient(Ingredient ingredient) {
if (ingredient == null) return;
if (ingredient == null || ingredient.getType() == Material.AIR) return;
Ingredient key = ingredient.clone(0);
Integer amount = ingredients.get(key);
amount = (amount == null ? 0 : amount) + ingredient.getAmount();
Expand Down

0 comments on commit e9ee6d2

Please sign in to comment.