Recipe Permissions

Discussion in 'Plugin Development' started by xtreampb, May 30, 2013.

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

    xtreampb

    this is more of a theory question with no actual code in dev (currently).

    If i wanted to set permission nodes for recipes, where can i find the nodes or how would i limit recipes from players. Such as player Z can't craft item R until i set a var associated with him whether in a perm manager with nodes or in code.

    any ideas would be greatly appreciated. Let me know if you need more clarification on my question.

    Thanks

    ~Xtreampb~

    bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  2. Offline

    GodzOfMadness

    xtreampb Try PrepareItemCraftEvent. Then cancel it if they don't have a permission for the result. The event runs right when a recipe in the craft box was valid.
     
  3. xtreampb
    Basically you check player.hasPermission("whatever.permission.node"), the node does not need to be registered for that to work, but registering permissions allows you to set who has them by default.
    That along with what GodzOfMadness said and you're done, but it still leaves the part where you have to detect the recipe... and since recipes are unique by ingredients and not by results, you'd have to do something complicated.

    I made an example with this exact thing in my utility class for comparing recipes: http://forums.bukkit.org/threads/ut...e-with-permissions-restricted-recipes.144319/

    Or you could just make permissions based on results if you're going to offer the end-user a simple config thing to restrict stuff from being crafted.

    However, on furnace recipes it's a bit more tricky because you have to do alot of trial and error in InventoryClickEvent to see if the crafter is allowed to craft that.

    Also, in PrepareItemCraftEvent there is no cancel option, the way you can cancel it is by setting inventory's result to null.
     
    xtreampb likes this.
  4. Offline

    xtreampb

    that is a lot of good useful information but still leaves the question where can i find the permission nodes for recipes. How do i set if a player can craft the recipe or has perms to craft the recipe.

    Edit:
    Just to clarify, i want to test for permissions for default crafting recipes such as the default for tools and everything. Where can i find a list of these permissions so i can disable them for the players.
     
  5. xtreampb
    There aren't any permissions for recipes, you must make/use a plugin to prevent recipes from being used if player doesn't have a permission.
     
  6. Offline

    xtreampb

    Digi
    ok so here is where i'm getting confused at. i create this permission CraftPerm.Craft.WoodAxe: true
    then on the prepareitemcraftevent test get what item was attempted to be crafted and then test if a player has the perm and if not send cancel event and display an error message. Is this logic correct. I was confusing myself thinking how do i link a custom perm to default items.
     
  7. xtreampb
    Yes it's fine, but to avoid manually checking permissions I suggest you use the item type directly in the permission, e.g. "craftperm.craft." + item.getType().toString().toLowerCase() which would be "wood_axe".
     
    xtreampb likes this.
  8. Offline

    xtreampb

    ok so i could generate a plugin that gets a list of all official item names and output that to a file and use that to populate my permissions file. Thank you for your help.
     
Thread Status:
Not open for further replies.

Share This Page