How to cancel a specific recipe?

Discussion in 'Plugin Development' started by sniddunc, Dec 13, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    sniddunc

    Hello,

    I am using the plugin CrackShot for my server and am using diamond and gold tools as the guns.
    I want to use crackshot's recipe system, but stop the players from crafting diamond and gold tools using the typical recipe system.

    I managed to cancel the recipe, but it canceled the crackshot recipe as well.

    What I am trying to do now is to get the recipe, get the item type and then if the name of the item contains "AK-47" then it proceeds with the crafting. If it doesn't, it cancels the recipe.

    This is my code:
    Code:
        
        @EventHandler
        public void craftItem(PrepareItemCraftEvent e) {
           
            Material itemType = e.getRecipe().getResult().getType();
            ItemMeta meta = e.getRecipe().getResult().getItemMeta();
           
            if (itemType == Material.GOLD_AXE) {
                if (meta.getDisplayName().contains("AK-47")) {
                   
                }
                else {
                   
                    e.getInventory().setResult(new ItemStack(Material.AIR));
                   
                    for (HumanEntity he:e.getViewers()) {
                       
                        if (he instanceof Player) {
                            ((Player)he).sendMessage(ChatColor.RED + "This recipe is disabled!");
                        }
                    }
                }
            }
        }
    
    Any help would be greatly appreciated.
    Thanks!
     
  2. Offline

    Zombie_Striker

  3. Offline

    mcdorli

    Removing a certain item's recipe, and making the players not able to use these items is probably the worst thing you can do. Use an item with a lore instead.
     
  4. Offline

    sniddunc

    What do you mean by using an item with a lore, exactly?

    Players need to be able to craft the guns, but they can't be able to craft their counterpart items (ex: diamond pickaxe) with the normal vanilla recipe. It seems a bit extreme, and it is, but there is no need for players to have access to these tools on my server in the first place.
     
Thread Status:
Not open for further replies.

Share This Page