<commit_before>package org.royaldev.royalcommands.rcommands;

import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.FurnaceRecipe;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Recipe;
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.inventory.ShapelessRecipe;
import org.royaldev.royalcommands.MessageColor;
import org.royaldev.royalcommands.RUtils;
import org.royaldev.royalcommands.RoyalCommands;
import org.royaldev.royalcommands.exceptions.InvalidItemNameException;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@ReflectCommand
public class CmdRecipe implements CommandExecutor {

    private final RoyalCommands plugin;
    private final Map<String, Integer> tasks = new HashMap<String, Integer>();

    public CmdRecipe(RoyalCommands instance) {
        plugin = instance;
        plugin.getServer().getPluginManager().registerEvents(new WorkbenchCloseListener(), plugin);
    }

    private void cancelTask(final Player p) {
        if (!tasks.containsKey(p.getName())) return;
        final int taskID = tasks.get(p.getName());
        if (taskID == -1) return;
        plugin.getServer().getScheduler().cancelTask(taskID);
    }

    @Override
    public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) {
        if (cmd.getName().equalsIgnoreCase("recipe")) {
            if (!this.plugin.ah.isAuthorized(cs, cmd)) {
                RUtils.dispNoPerms(cs);
                return true;
            }
            if (args.length < 1) {
                cs.sendMessage(cmd.getDescription());
                return false;
            }
            if (!(cs instanceof Player)) {
                cs.sendMessage(MessageColor.NEGATIVE + "This command is only available to players!");
                return true;
            }
            final Player p = (Player) cs;
            ItemStack is;
            try {
                is = RUtils.getItemFromAlias(args[0], 1);
            } catch (InvalidItemNameException e) {
                is = RUtils.getItem(args[0], 1);
            } catch (NullPointerException e) {
                cs.sendMessage(MessageColor.NEGATIVE + "ItemNameManager was not loaded. Let an administrator know.");
                return true;
            }
            if (is == null) {
                cs.sendMessage(MessageColor.NEGATIVE + "Invalid item name!");
                return true;
            }
            is.setDurability((short) -1);
            final List<Recipe> rs = plugin.getServer().getRecipesFor(is);
            if (rs.size() < 1) {
                cs.sendMessage(MessageColor.NEGATIVE + "No recipes for that item!");
                return true;
            }
            final List<Inventory> workbenches = new ArrayList<Inventory>();
            for (Recipe r : rs) {
                final Inventory i;
                if (r instanceof ShapedRecipe) {
                    i = plugin.getServer().createInventory(null, InventoryType.WORKBENCH);
                    final ShapedRecipe sr = (ShapedRecipe) r;
                    final Map<Character, ItemStack> im = sr.getIngredientMap();<commit_msg>Fixed: Don't set durability | RCMDS-94 #resolve<commit_after>package org.royaldev.royalcommands.rcommands;

import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.FurnaceRecipe;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Recipe;
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.inventory.ShapelessRecipe;
import org.royaldev.royalcommands.MessageColor;
import org.royaldev.royalcommands.RUtils;
import org.royaldev.royalcommands.RoyalCommands;
import org.royaldev.royalcommands.exceptions.InvalidItemNameException;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@ReflectCommand
public class CmdRecipe implements CommandExecutor {

    private final RoyalCommands plugin;
    private final Map<String, Integer> tasks = new HashMap<>();

    public CmdRecipe(RoyalCommands instance) {
        plugin = instance;
        plugin.getServer().getPluginManager().registerEvents(new WorkbenchCloseListener(), plugin);
    }

    private void cancelTask(final Player p) {
        if (!tasks.containsKey(p.getName())) return;
        final int taskID = tasks.get(p.getName());
        if (taskID == -1) return;
        plugin.getServer().getScheduler().cancelTask(taskID);
    }

    @Override
    public boolean onCommand(CommandSender cs, Command cmd, String label, String[] args) {
        if (cmd.getName().equalsIgnoreCase("recipe")) {
            if (!this.plugin.ah.isAuthorized(cs, cmd)) {
                RUtils.dispNoPerms(cs);
                return true;
            }
            if (args.length < 1) {
                cs.sendMessage(cmd.getDescription());
                return false;
            }
            if (!(cs instanceof Player)) {
                cs.sendMessage(MessageColor.NEGATIVE + "This command is only available to players!");
                return true;
            }
            final Player p = (Player) cs;
            ItemStack is;
            try {
                is = RUtils.getItemFromAlias(args[0], 1);
            } catch (InvalidItemNameException e) {
                is = RUtils.getItem(args[0], 1);
            } catch (NullPointerException e) {
                cs.sendMessage(MessageColor.NEGATIVE + "ItemNameManager was not loaded. Let an administrator know.");
                return true;
            }
            if (is == null) {
                cs.sendMessage(MessageColor.NEGATIVE + "Invalid item name!");
                return true;
            }
            final List<Recipe> rs = plugin.getServer().getRecipesFor(is);
            if (rs.size() < 1) {
                cs.sendMessage(MessageColor.NEGATIVE + "No recipes for that item!");
                return true;
            }
            final List<Inventory> workbenches = new ArrayList<>();
            for (Recipe r : rs) {
                final Inventory i;
                if (r instanceof ShapedRecipe) {
                    i = plugin.getServer().createInventory(null, InventoryType.WORKBENCH);
                    final ShapedRecipe sr = (ShapedRecipe) r;
                    final Map<Character, ItemStack> im = sr.getIngredientMap();
{'fraction_non_alphanumeric': 0.10303959843837145, 'fraction_numerical': 0.002370329057445622, 'mean_word_length': 2.500732064421669, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5567469', 'n_tokens_mistral': 2070, 'n_tokens_neox': 1971, 'n_words': 437}