Fixed error with talismans being able to be used in internal recipes
This commit is contained in:
@@ -47,7 +47,7 @@ allprojects {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly 'com.willfp:eco:3.6.0'
|
||||
compileOnly 'com.willfp:eco:3.7.0'
|
||||
|
||||
compileOnly 'org.jetbrains:annotations:19.0.0'
|
||||
|
||||
|
||||
@@ -154,7 +154,7 @@ public class TalismansPlugin extends AbstractEcoPlugin {
|
||||
return Arrays.asList(
|
||||
new WatcherTriggers(this),
|
||||
new BlockPlaceListener(),
|
||||
new TalismanCraftListener(),
|
||||
new TalismanCraftListener(this),
|
||||
new TalismanEquipEventListeners(this),
|
||||
new DiscoverRecipeListener(this)
|
||||
);
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package com.willfp.talismans.talismans.util;
|
||||
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.eco.util.recipe.EcoShapedRecipe;
|
||||
import com.willfp.eco.util.recipe.parts.RecipePart;
|
||||
import com.willfp.eco.util.recipe.parts.SimpleRecipePart;
|
||||
import com.willfp.talismans.talismans.Talisman;
|
||||
import com.willfp.talismans.talismans.Talismans;
|
||||
import org.bukkit.Material;
|
||||
@@ -13,9 +17,19 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.ShapedRecipe;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class TalismanCraftListener implements Listener {
|
||||
public class TalismanCraftListener extends PluginDependent implements Listener {
|
||||
/**
|
||||
* Create new talisman craft listener.
|
||||
*
|
||||
* @param plugin Instance of talismans.
|
||||
*/
|
||||
public TalismanCraftListener(@NotNull final AbstractEcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on item craft.
|
||||
*
|
||||
* @param event The event to listen for.
|
||||
*/
|
||||
@EventHandler
|
||||
@@ -43,8 +57,42 @@ public class TalismanCraftListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on item craft.
|
||||
*
|
||||
* @param event The event to listen for.
|
||||
*/
|
||||
@EventHandler
|
||||
public void preventUsingTalismanInTalCraft(@NotNull final PrepareItemCraftEvent event) {
|
||||
if (!(event.getRecipe() instanceof ShapedRecipe)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ShapedRecipe recipe = (ShapedRecipe) event.getRecipe();
|
||||
|
||||
Talisman talisman = Talismans.getByKey(recipe.getKey());
|
||||
|
||||
if (talisman == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
EcoShapedRecipe ecoShapedRecipe = talisman.getRecipe();
|
||||
|
||||
for (int i = 0; i < 9; i++) {
|
||||
ItemStack itemStack = event.getInventory().getMatrix()[i];
|
||||
RecipePart part = ecoShapedRecipe.getParts()[i];
|
||||
if (part instanceof SimpleRecipePart) {
|
||||
if (TalismanChecks.getTalismanOnItem(itemStack) != null) {
|
||||
event.getInventory().setResult(new ItemStack(Material.AIR));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents using talismans in recipes.
|
||||
*
|
||||
* @param event The event to listen for.
|
||||
*/
|
||||
@EventHandler
|
||||
@@ -69,6 +117,7 @@ public class TalismanCraftListener implements Listener {
|
||||
|
||||
/**
|
||||
* Called on item craft.
|
||||
*
|
||||
* @param event The event to listen for.
|
||||
*/
|
||||
@EventHandler
|
||||
@@ -99,6 +148,7 @@ public class TalismanCraftListener implements Listener {
|
||||
|
||||
/**
|
||||
* Prevents using talismans in recipes.
|
||||
*
|
||||
* @param event The event to listen for.
|
||||
*/
|
||||
@EventHandler
|
||||
@@ -121,4 +171,38 @@ public class TalismanCraftListener implements Listener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on item craft.
|
||||
*
|
||||
* @param event The event to listen for.
|
||||
*/
|
||||
@EventHandler
|
||||
public void preventUsingTalismanInTalCraft(@NotNull final CraftItemEvent event) {
|
||||
if (!(event.getRecipe() instanceof ShapedRecipe)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ShapedRecipe recipe = (ShapedRecipe) event.getRecipe();
|
||||
|
||||
Talisman talisman = Talismans.getByKey(recipe.getKey());
|
||||
|
||||
if (talisman == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
EcoShapedRecipe ecoShapedRecipe = talisman.getRecipe();
|
||||
|
||||
for (int i = 0; i < 9; i++) {
|
||||
ItemStack itemStack = event.getInventory().getMatrix()[i];
|
||||
RecipePart part = ecoShapedRecipe.getParts()[i];
|
||||
if (part instanceof SimpleRecipePart) {
|
||||
if (TalismanChecks.getTalismanOnItem(itemStack) != null) {
|
||||
event.getInventory().setResult(new ItemStack(Material.AIR));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user