Refactored shaped recipes
This commit is contained in:
@@ -34,7 +34,7 @@ import com.willfp.eco.spigot.integrations.antigrief.AntigriefLands;
|
||||
import com.willfp.eco.spigot.integrations.antigrief.AntigriefTowny;
|
||||
import com.willfp.eco.spigot.integrations.antigrief.AntigriefWorldGuard;
|
||||
import com.willfp.eco.spigot.integrations.mcmmo.McmmoIntegrationImpl;
|
||||
import com.willfp.eco.spigot.recipes.RecipeListener;
|
||||
import com.willfp.eco.spigot.recipes.ShapedRecipeListener;
|
||||
import com.willfp.eco.util.BlockUtils;
|
||||
import com.willfp.eco.util.SkullUtils;
|
||||
import com.willfp.eco.util.TridentUtils;
|
||||
@@ -72,7 +72,7 @@ public class EcoSpigotPlugin extends EcoPlugin {
|
||||
this.getEventManager().registerListener(new ArmorListener());
|
||||
this.getEventManager().registerListener(new DispenserArmorListener());
|
||||
this.getEventManager().registerListener(new EntityDeathByEntityListeners(this));
|
||||
this.getEventManager().registerListener(new RecipeListener());
|
||||
this.getEventManager().registerListener(new ShapedRecipeListener());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.willfp.eco.core.items.CustomItems;
|
||||
import com.willfp.eco.core.items.TestableItem;
|
||||
import com.willfp.eco.core.recipe.Recipes;
|
||||
import com.willfp.eco.core.recipe.parts.MaterialTestableItem;
|
||||
import com.willfp.eco.core.recipe.recipes.CraftingRecipe;
|
||||
import com.willfp.eco.core.recipe.recipes.ShapedCraftingRecipe;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.Event;
|
||||
@@ -17,7 +18,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.ShapedRecipe;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class RecipeListener implements Listener {
|
||||
public class ShapedRecipeListener implements Listener {
|
||||
/**
|
||||
* Called on item craft.
|
||||
*
|
||||
@@ -36,7 +37,7 @@ public class RecipeListener implements Listener {
|
||||
}
|
||||
|
||||
ItemStack[] matrix = event.getInventory().getMatrix();
|
||||
ShapedCraftingRecipe matched = Recipes.getMatch(matrix);
|
||||
CraftingRecipe matched = Recipes.getMatch(matrix);
|
||||
|
||||
if (matched == null) {
|
||||
event.getInventory().setResult(new ItemStack(Material.AIR));
|
||||
@@ -68,7 +69,7 @@ public class RecipeListener implements Listener {
|
||||
}
|
||||
|
||||
ItemStack[] matrix = event.getInventory().getMatrix();
|
||||
ShapedCraftingRecipe matched = Recipes.getMatch(matrix);
|
||||
CraftingRecipe matched = Recipes.getMatch(matrix);
|
||||
|
||||
if (matched == null) {
|
||||
event.getInventory().setResult(new ItemStack(Material.AIR));
|
||||
@@ -99,15 +100,17 @@ public class RecipeListener implements Listener {
|
||||
|
||||
ShapedRecipe recipe = (ShapedRecipe) event.getRecipe();
|
||||
|
||||
ShapedCraftingRecipe shapedCraftingRecipe = Recipes.getShapedRecipe(recipe.getKey());
|
||||
CraftingRecipe craftingRecipe = Recipes.getRecipe(recipe.getKey());
|
||||
|
||||
if (shapedCraftingRecipe == null) {
|
||||
if (!(craftingRecipe instanceof ShapedCraftingRecipe)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ShapedCraftingRecipe shapedCraftingRecipe = (ShapedCraftingRecipe) craftingRecipe;
|
||||
|
||||
for (int i = 0; i < 9; i++) {
|
||||
ItemStack itemStack = event.getInventory().getMatrix()[i];
|
||||
TestableItem part = shapedCraftingRecipe.getParts()[i];
|
||||
TestableItem part = shapedCraftingRecipe.getParts().get(i);
|
||||
if (part instanceof MaterialTestableItem) {
|
||||
if (CustomItems.isCustomItem(itemStack)) {
|
||||
event.getInventory().setResult(new ItemStack(Material.AIR));
|
||||
@@ -130,15 +133,17 @@ public class RecipeListener implements Listener {
|
||||
|
||||
ShapedRecipe recipe = (ShapedRecipe) event.getRecipe();
|
||||
|
||||
ShapedCraftingRecipe shapedCraftingRecipe = Recipes.getShapedRecipe(recipe.getKey());
|
||||
CraftingRecipe craftingRecipe = Recipes.getRecipe(recipe.getKey());
|
||||
|
||||
if (shapedCraftingRecipe == null) {
|
||||
if (!(craftingRecipe instanceof ShapedCraftingRecipe)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ShapedCraftingRecipe shapedCraftingRecipe = (ShapedCraftingRecipe) craftingRecipe;
|
||||
|
||||
for (int i = 0; i < 9; i++) {
|
||||
ItemStack itemStack = event.getInventory().getMatrix()[i];
|
||||
TestableItem part = shapedCraftingRecipe.getParts()[i];
|
||||
TestableItem part = shapedCraftingRecipe.getParts().get(i);
|
||||
if (part instanceof MaterialTestableItem) {
|
||||
if (CustomItems.isCustomItem(itemStack)) {
|
||||
event.getInventory().setResult(new ItemStack(Material.AIR));
|
||||
Reference in New Issue
Block a user