CustomRecipe

Discussion in 'Spigot Plugin Development' started by MadMaxCookie, May 19, 2016.

  1. Hello so I had a customrecipe plugin seems already finished
    but I'm asking how do I add a permission

    craft.<itemname> || to craft the item name

    and what's the event name of it ?
     
  2. if(p.hasPermission("lel.lol")){
    }
     
  3. sorry my bad not asking how to create the permission really

    I'm asking how do I stop people from crafting certain items without the permission

    craft.<itemname>
     
  4. In your method for testing when they craft it, just use that check.

    Code (Text):
    @EventHandler
    (crafting event omg)
    Player p = event.getPlayer();
    if(p.hasPermission("i.can.craft"){
    (do the mlg crafting)
    }else{
    return;
    }
     
  5.  
  6. PrepareItemCraftEvent

    And you were asking for how to check permissions before.
     
  7. I both ask them :D

    with "AND"
     
  8. ;p Well I mean you saying it is "already finished" makes me think it is already finished. :p
     
  9. well sorry I said such things that is nonsense :D

    now I don't know how to cancel the event with this event
     
  10. is this going to worked ?
    Code (Java):
        @EventHandler
        public void preparecraft(PrepareItemCraftEvent e) {
            Player p = (Player)e.getViewers();
         
            if(!p.hasPermission("customrecipe.craft." + e.getRecipe().getResult().getItemMeta().getDisplayName()) || (!p.hasPermission("customrecipe.craft.*"))) {
                e.getRecipe().getResult().setType(Material.AIR);
                return;
            }
            return;
        }
     
  11. You're never testing what the recipe is.
     
  12. testing for what purpose ?
     
    • Creative Creative x 1
  13. You aren't checking if the item they're trying to craft is your custom item, so this will set all crafting recipes to air.
     
  14. yeah that's what I'm planning I'm including all recipes.
     
  15. That code will throw more NullPointerExceptions in your face than you can count because normal items don't have a display name ...
    You should probably use ItemStack#getType().toString() instead.

    For custom items which indeed have a display name you have to check if they have a display name first using ItemMeta#hasDisplayName() and then you can actually compare the display name with something.