Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add remove_recipe(). (#1187)
* Add remove_recipe().

* doc clarification

Co-authored-by: Lildirt <lildirt@lildirt.com>
  • Loading branch information
Lildirt and Lildirt committed May 13, 2020
1 parent 8799c64 commit 64ef2de
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/laytonsmith/abstraction/MCServer.java
Expand Up @@ -142,6 +142,8 @@ public interface MCServer extends AbstractionObject {

boolean addRecipe(MCRecipe recipe);

boolean removeRecipe(String key);

List<MCRecipe> getRecipesFor(MCItemStack result);

List<MCRecipe> allRecipes();
Expand Down
Expand Up @@ -30,6 +30,7 @@
import com.laytonsmith.core.Static;
import org.bukkit.BanList;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.World;
Expand Down Expand Up @@ -554,6 +555,11 @@ public boolean addRecipe(MCRecipe recipe) {
return s.addRecipe((Recipe) recipe.getHandle());
}

@Override
public boolean removeRecipe(String key) {
return s.removeRecipe(NamespacedKey.minecraft(key));
}

@Override
public List<MCRecipe> getRecipesFor(MCItemStack result) {
List<MCRecipe> ret = new ArrayList<>();
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/com/laytonsmith/core/functions/Recipes.java
Expand Up @@ -146,6 +146,41 @@ public ExampleScript[] examples() throws ConfigCompileException {
}
}

@api(environments = {CommandHelperEnvironment.class})
public static class remove_recipe extends recipeFunction {

@Override
public Class<? extends CREThrowable>[] thrown() {
return new Class[0];
}

@Override
public Mixed exec(Target t, Environment environment, Mixed... args) throws ConfigRuntimeException {
return CBoolean.get(Static.getServer().removeRecipe(args[0].val()));
}

@Override
public Version since() {
return MSVersion.V3_3_4;
}

@Override
public String getName() {
return "remove_recipe";
}

@Override
public Integer[] numArgs() {
return new Integer[]{1};
}

@Override
public String docs() {
return "boolean {recipe_key} Remove a certain recipe by its registered key."
+ " Returns whether the recipe was removed successfully or not.";
}
}

@api(environments = {CommandHelperEnvironment.class})
public static class get_recipes_for extends recipeFunction {

Expand Down

0 comments on commit 64ef2de

Please sign in to comment.