diff --git a/src/main/java/org/skriptlang/skript/bukkit/recipes/elements/ExprRecipeIngredients.java b/src/main/java/org/skriptlang/skript/bukkit/recipes/elements/ExprRecipeIngredients.java index 392068cdc1c..e3d070190ef 100644 --- a/src/main/java/org/skriptlang/skript/bukkit/recipes/elements/ExprRecipeIngredients.java +++ b/src/main/java/org/skriptlang/skript/bukkit/recipes/elements/ExprRecipeIngredients.java @@ -3,6 +3,7 @@ import ch.njol.skript.Skript; import ch.njol.skript.aliases.ItemType; import ch.njol.skript.classes.Changer.ChangeMode; +import ch.njol.skript.config.Node; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Examples; import ch.njol.skript.doc.Name; @@ -28,6 +29,7 @@ import org.skriptlang.skript.bukkit.recipes.CreateRecipeEvent.CraftingRecipeEvent.ShapedRecipeEvent; import org.skriptlang.skript.bukkit.recipes.CreateRecipeEvent.SmithingRecipeEvent.SmithingTransformRecipeEvent; import org.skriptlang.skript.bukkit.recipes.CreateRecipeEvent.SmithingRecipeEvent.SmithingTrimRecipeEvent; +import org.skriptlang.skript.log.runtime.SyntaxRuntimeErrorProducer; import java.util.*; @@ -67,7 +69,7 @@ "\tset the recipe transmute item to nether star named \"Free Upgrade\"", "\tset the recipe result to netherite helmet" }) -public class ExprRecipeIngredients extends PropertyExpression { +public class ExprRecipeIngredients extends PropertyExpression implements SyntaxRuntimeErrorProducer { enum RecipePattern { INGREDIENTS("[recipe] ingredients", "recipe ingredients", CraftingRecipeEvent.class, @@ -121,9 +123,10 @@ enum RecipePattern { private boolean isEvent = false; private RecipePattern selectedPattern; + private Node node; + private String rawExpr; @Override - @SuppressWarnings("unchecked") public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { selectedPattern = recipePatterns[matchedPattern / 2]; if (exprs[0].isDefault()) { @@ -137,6 +140,8 @@ public boolean init(Expression[] exprs, int matchedPattern, Kleenean isDelaye } //noinspection unchecked setExpr((Expression) exprs[0]); + node = getParser().getNode(); + rawExpr = parseResult.expr; return true; } @@ -187,7 +192,7 @@ private List getterIngredients(Recipe recipe) { } else if (recipe instanceof ShapelessRecipe shapelessRecipe) { ingredients.addAll(shapelessRecipe.getIngredientList()); } else { - Skript.error("You can only get the ingredients of a Shaped or Shapeless Recipe."); + error("You can only get the ingredients of a Shaped or Shapeless Recipe."); } return ingredients; } @@ -211,7 +216,7 @@ private List getterRows(Recipe recipe) { ingredients.add(stack); } } else { - Skript.error("You can only get the ingredients of a row for a Shaped Recipe."); + error("You can only get the ingredients of a row for a Shaped Recipe."); } return ingredients; } @@ -253,7 +258,7 @@ else if (recipe instanceof SmithingTrimRecipe trimRecipe) ); } } else { - Skript.error("You can only get the base items of a Smithing, Smithing Transform and Smithing Trim Recipe."); + error("You can only get the base items of a Smithing, Smithing Transform and Smithing Trim Recipe."); } return ingredients; } @@ -277,7 +282,7 @@ private List getterInput(Recipe recipe) { } else if (recipe instanceof TransmuteRecipe transmuteRecipe) { choice = transmuteRecipe.getInput(); } else { - Skript.error("You can only get the input item of a Cooking, Blasting, Furnace, Campfire, Smoking and Stonecutting Recipe."); + error("You can only get the input item of a Cooking, Blasting, Furnace, Campfire, Smoking and Stonecutting Recipe."); } if (choice instanceof ExactChoice exactChoice) { ingredients.addAll(exactChoice.getChoices()); @@ -306,7 +311,7 @@ private List getterTransmute(Recipe recipe) { @Override public Class @Nullable [] acceptChange(ChangeMode mode) { if (!isEvent) { - Skript.error("You can not set the " + selectedPattern.toString + " of existing recipes."); + error("You can not set the " + selectedPattern.toString + " of existing recipes."); } else if (mode == ChangeMode.SET) { return CollectionUtils.array(ItemType[].class); } @@ -354,7 +359,7 @@ private void changerIngredients(Map items, MutableRecipe m return; if (items.size() > 9) { - Skript.error("You can only provide up to 9 items when setting the ingredients for a '" + recipeEvent.getRecipeType() + "' recipe."); + error("You can only provide up to 9 items when setting the ingredients for a '" + recipeEvent.getRecipeType() + "' recipe."); recipeEvent.setErrorInSection(); return; } @@ -362,7 +367,7 @@ private void changerIngredients(Map items, MutableRecipe m ItemStack[] ingredients = entry.getValue(); if (Arrays.stream(ingredients).anyMatch(itemStack -> itemStack.getType().isAir())) { if (ingredients.length > 1) { - Skript.error("You can not provide air with a list of other items."); + error("You can not provide air with a list of other items."); recipeEvent.setErrorInSection(); return; } else { @@ -378,7 +383,7 @@ private void changerRows(Map items, MutableRecipe mutableR if (!(mutableRecipe instanceof MutableShapedRecipe mutableShapedRecipe)) return; if (items.size() > 3) { - Skript.error("You can only provide up to 3 items when setting the ingredients of a row for a '" + recipeEvent.getRecipeType() + "' recipe."); + error("You can only provide up to 3 items when setting the ingredients of a row for a '" + recipeEvent.getRecipeType() + "' recipe."); recipeEvent.setErrorInSection(); return; } @@ -386,7 +391,7 @@ private void changerRows(Map items, MutableRecipe mutableR ItemStack[] ingredients = entry.getValue(); if (Arrays.stream(ingredients).anyMatch(itemStack -> itemStack.getType().isAir())) { if (ingredients.length > 1) { - Skript.error("You can not provide 'air' with a list of other items."); + error("You can not provide 'air' with a list of other items."); recipeEvent.setErrorInSection(); return; } else { @@ -404,7 +409,7 @@ private void changerSmithing(Map items, MutableRecipe muta List stackList = new ArrayList<>(); items.entrySet().stream().forEach(entry -> stackList.addAll(Arrays.asList(entry.getValue()))); if (stackList.stream().anyMatch(itemStack -> itemStack.getType().isAir())) { - Skript.error("You can not provide 'air' with this expression."); + error("You can not provide 'air' with this expression."); recipeEvent.setErrorInSection(); return; } @@ -420,7 +425,7 @@ private void changerInput(Map items, MutableRecipe mutable List stackList = new ArrayList<>(); items.entrySet().stream().forEach(entry -> stackList.addAll(Arrays.asList(entry.getValue()))); if (stackList.stream().anyMatch(itemStack -> itemStack.getType().isAir())) { - Skript.error("You can not provide 'air' with this expression."); + error("You can not provide 'air' with this expression."); recipeEvent.setErrorInSection(); return; } @@ -438,7 +443,7 @@ private void changerTransmute(Map items, MutableRecipe mut List stackList = new ArrayList<>(); items.entrySet().stream().forEach(entry -> stackList.addAll(Arrays.asList(entry.getValue()))); if (stackList.stream().anyMatch(itemStack -> itemStack.getType().isAir())) { - Skript.error("You can not provide 'air' with this expression."); + error("You can not provide 'air' with this expression."); recipeEvent.setErrorInSection(); return; } @@ -453,6 +458,16 @@ public Class getReturnType() { return ItemStack.class; } + @Override + public Node getNode() { + return node; + } + + @Override + public @Nullable String toHighlight() { + return rawExpr; + } + @Override public String toString(@Nullable Event event, boolean debug) { return "the " + selectedPattern.toString + " of " + getExpr().toString(event, debug); diff --git a/src/main/java/org/skriptlang/skript/bukkit/recipes/elements/ExprSecCreateRecipe.java b/src/main/java/org/skriptlang/skript/bukkit/recipes/elements/ExprSecCreateRecipe.java index 3fcb33050fe..f42b9fdf505 100644 --- a/src/main/java/org/skriptlang/skript/bukkit/recipes/elements/ExprSecCreateRecipe.java +++ b/src/main/java/org/skriptlang/skript/bukkit/recipes/elements/ExprSecCreateRecipe.java @@ -1,6 +1,7 @@ package org.skriptlang.skript.bukkit.recipes.elements; import ch.njol.skript.Skript; +import ch.njol.skript.config.Node; import ch.njol.skript.config.SectionNode; import ch.njol.skript.doc.Description; import ch.njol.skript.doc.Examples; @@ -19,6 +20,7 @@ import org.skriptlang.skript.bukkit.recipes.CreateRecipeEvent; import org.skriptlang.skript.bukkit.recipes.MutableRecipe; import org.skriptlang.skript.bukkit.recipes.RecipeUtils.RecipeType; +import org.skriptlang.skript.log.runtime.SyntaxRuntimeErrorProducer; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; @@ -79,7 +81,7 @@ "\tset the recipe result to netherite helmet" }) @Since("INSERT VERSION") -public class ExprSecCreateRecipe extends SectionExpression { +public class ExprSecCreateRecipe extends SectionExpression implements SyntaxRuntimeErrorProducer { private static final boolean SUPPORT_SMITHING = !Skript.isRunningMinecraft(1, 20, 0); @@ -92,6 +94,8 @@ public class ExprSecCreateRecipe extends SectionExpression { private RecipeType providedType; private Expression providedName; private Trigger trigger; + private Node node; + private String rawExpr; @Override public boolean init(Expression[] exprs, int pattern, Kleenean isDelayed, ParseResult result, @Nullable SectionNode node, @Nullable List triggerItems) { @@ -121,6 +125,8 @@ public boolean init(Expression[] exprs, int pattern, Kleenean isDelayed, Pars Skript.error("Delays cannot be used within a 'create recipe' section."); return false; } + this.node = getParser().getNode(); + rawExpr = result.expr; return true; } @@ -128,12 +134,12 @@ public boolean init(Expression[] exprs, int pattern, Kleenean isDelayed, Pars protected Recipe @Nullable [] get(Event event) { String name = providedName.getSingle(event); if (name == null || name.isEmpty()) { - Skript.error("The id for a recipe must not be null nor empty."); + error("The id for a recipe must not be null nor empty."); return null; } NamespacedKey key = NamespacedKey.fromString(name, Skript.getInstance()); if (key == null) { - Skript.error("The provided id is invalid."); + error("The provided id is invalid."); return null; } CreateRecipeEvent recipeEvent = providedType.createRecipeEvent(key); @@ -149,7 +155,7 @@ public boolean init(Expression[] exprs, int pattern, Kleenean isDelayed, Pars Recipe recipe = recipeWrapper.create(); // If the recipe failed to build if (recipe == null) { - Skript.error(recipeWrapper.getErrors().toString()); + error(recipeWrapper.getErrors().toString()); return null; } return new Recipe[]{recipe}; @@ -165,6 +171,16 @@ public Class getReturnType() { return Recipe.class; } + @Override + public Node getNode() { + return node; + } + + @Override + public @Nullable String toHighlight() { + return rawExpr; + } + @Override public String toString(@Nullable Event event, boolean debug) { return "a new " + providedType + " recipe with the key " + providedName.toString(event, debug);