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 ?
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>
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; }
well sorry I said such things that is nonsense now I don't know how to cancel the event with this event
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; }
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.
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.