Help!!!!

Discussion in 'Plugin Development' started by Zachster, Jul 27, 2012.

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

    Zachster

    Ok I think I might have already posted something similar to this before, but I wasn't specific. I have a plugin that adds in a shaped recipe. I already have the recipe added in and it works. What I want to do is add a permission node for this recipe, so that people who have the permission, or ops, are the only ones who can use that recipe. How would I do that? (If possible could I have an example please)
     
  2. Offline

    Numenorean95

    Code:
    Player p = <something>;
    if(p.hasPermission("thing.canCreate")){
        //do whatever.
    }
     
  3. Offline

    Zachster

    Numenorean95

    I know how permissions work but how do I tie that into a recipe? The way I do the recipe now, it gets added in at onEnable I need to know some way to cancel it or enable it for a certain player or something
     
  4. Offline

    Numenorean95

    Sorry, this should work. This would be in a listener class, if you need help with that ask.

    Code:
    @EventHandler
    public void onPlayerCraft(CraftItemEvent e){
        if(e.getRecipe().equals(myRecipe) && !e.getWhoClicked().hasPermission("thing.perm"){
                e.setCancelled(true);
        }
    }
    Edit: im not sure whether the method would be called onPlayerCraft or something else, maybe onItemCrafted, or whether it even matters.
     
  5. Offline

    Zachster

    Numenorean95

    It's alright I should have elaborated more in my original post. I pretty well have events covered and the .setCancelled thing, I was just having an issue with detecting if it was my recipe. However, do I still add in the recipe in onEnable? If so would I make an instance of my main class [MainClass i = new MainClass();] or would I make the recipe static or what?

    Thanks
     
  6. Offline

    Numenorean95

    Sorry for my misunderrrstanding, Yes, still do it there, but when you create your listener class, pass in the the constructer the current Object that is you plugin, so that it can retrieve your recipe

    Code:
    MyListener list = new MyListener(this);
     
Thread Status:
Not open for further replies.

Share This Page