Skip to content

Commit

Permalink
add tag server.list_recipe_ids
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Sep 20, 2019
1 parent a58bdc2 commit e35798e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
Expand Up @@ -5,6 +5,7 @@
import com.denizenscript.denizen.scripts.containers.core.ItemScriptContainer;
import com.denizenscript.denizen.scripts.containers.core.ItemScriptHelper;
import com.denizenscript.denizen.utilities.MaterialCompat;
import com.denizenscript.denizen.utilities.Utilities;
import com.denizenscript.denizen.utilities.blocks.OldMaterialsHelper;
import com.denizenscript.denizen.utilities.debugging.Debug;
import com.denizenscript.denizencore.objects.*;
Expand Down Expand Up @@ -973,16 +974,7 @@ public ObjectTag run(Attribute attribute, ObjectTag object) {
ItemScriptContainer container = item.isItemscript() ? ItemScriptHelper.getItemScriptContainer(item.getItemStack()) : null;
ListTag list = new ListTag();
for (Recipe recipe : Bukkit.getRecipesFor(item.getItemStack())) {
if (type != null && (
(type.equals("crafting") && !(recipe instanceof ShapedRecipe || recipe instanceof ShapelessRecipe)) ||
(type.equals("furnace") && !(recipe instanceof FurnaceRecipe)) ||
(type.equals("cooking") && !(recipe instanceof CookingRecipe)) ||
(type.equals("blasting") && !(recipe instanceof BlastingRecipe)) ||
(type.equals("shaped") && !(recipe instanceof ShapedRecipe)) ||
(type.equals("shapeless") && !(recipe instanceof ShapelessRecipe)) ||
(type.equals("smoking") && !(recipe instanceof SmokingRecipe)) ||
(type.equals("stonecutting") && !(recipe instanceof StonecuttingRecipe))
)) {
if (!Utilities.isRecipeOfType(recipe, type)) {
continue;
}
if (recipe instanceof Keyed) {
Expand Down
Expand Up @@ -212,6 +212,27 @@ public void serverTag(ReplaceableTagEvent event) {
return;
}

// <--[tag]
// @attribute <server.list_recipe_ids[(<type>)]>
// @returns ListTag
// @description
// Returns a list of all recipe IDs on the server.
// Returns a list in the Namespace:Key format, for example "minecraft:gold_nugget".
// Optionally, specify a recipe type (CRAFTING, FURNACE, COOKING, BLASTING, SHAPED, SHAPELESS, SMOKING, STONECUTTING)
// to limit to just recipes of that type.
// -->
if (attribute.startsWith("list_recipe_ids")) {
String type = attribute.hasContext(1) ? CoreUtilities.toLowerCase(attribute.getContext(1)) : null;
ListTag list = new ListTag();
Bukkit.recipeIterator().forEachRemaining((recipe) -> {
if (Utilities.isRecipeOfType(recipe, type) && recipe instanceof Keyed) {
list.add(((Keyed) recipe).getKey().toString());
}
});
event.setReplaced(list.getAttribute(attribute.fulfill(1)));
return;
}

// <--[tag]
// @attribute <server.list_advancements>
// @returns ListTag
Expand Down
Expand Up @@ -23,6 +23,7 @@
import org.bukkit.block.Sign;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.*;
import org.bukkit.util.Vector;

import java.io.File;
Expand Down Expand Up @@ -58,6 +59,18 @@ else if ((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '_') {
return output.toString();
}

public static boolean isRecipeOfType(Recipe recipe, String type) {
return type == null || (
(type.equals("crafting") && (recipe instanceof ShapedRecipe || recipe instanceof ShapelessRecipe)) ||
(type.equals("furnace") && recipe instanceof FurnaceRecipe) ||
(type.equals("cooking") && recipe instanceof CookingRecipe) ||
(type.equals("blasting") && recipe instanceof BlastingRecipe) ||
(type.equals("shaped") && recipe instanceof ShapedRecipe) ||
(type.equals("shapeless") && recipe instanceof ShapelessRecipe) ||
(type.equals("smoking") && recipe instanceof SmokingRecipe) ||
(type.equals("stonecutting") && recipe instanceof StonecuttingRecipe));
}

public static boolean canReadFile(File f) {
if (Settings.allowStupids()) {
return true;
Expand Down

1 comment on commit e35798e

@mcmonkey4eva
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for #2038

Please sign in to comment.