Need a hand- Permissions Integration [Solved]

Discussion in 'Plugin Development' started by Specops343, Jun 26, 2011.

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

    Specops343

    Hey guys, i am trying to integrate permissions into my plugin, Simplewand. Im having quite a problem with it :/ . Im still a little unsure how to do the check for permissions. Do i do a boolean?
    Code:
     if (!(Simplewand).permissionHandler.has(player, "simplewand.fireball")) {
          return;
      }
    For me, in eclipse, both Simplewand and player return as undefined. How would I go about fixing this?
     
  2. Offline

    Weltall 7

    You can not refer to variables you haven't defined anywhere. Define player and permissionHandler first, so the program knows what you mean.
     
  3. Offline

    Specops343

    @Weltall 7
    Alright, so (still a little new to this) but would I do:
    Code:
    Player player = null
    permissionHandler = null
    ?
    If not, how might I define them?
     
  4. Offline

    Weltall 7

    player is the Player who wants to shoot a fireball (e.g. event.getPlayer(), if inside of an event), and for the permissionHandler read the Permission tutorial again.
     
  5. Offline

    Specops343

    Right, so i was able to define player and simplewand (I was making a dumb mistake :/) Im now a little confused about this:
    Code:
        public static Player player;
        {
            if (Simplewand.permissionHandler.has(player, "simplewand.fireball")) {
            return;
            }
                } 
    And return is now coming back as an error. Any ideas how to fix this?
     
  6. Offline

    Specops343

    Still need a bit of help with this please.
     
  7. Offline

    feildmaster

    Do you have any messengers? (Skype preferred) if so shoot me a private message. I'll help you on there (where necessary)
     
  8. Offline

    dragos240

    Could you please link me to this? I would appreciate it greatly.
     
  9. Offline

    feildmaster

    to shooting fireballs?
    That is "SimpleWand" by the topic starter, you can see it in his signature.
     
  10. Offline

    dragos240

    Oh no. The permissions tutorial. I could really use it.
     
  11. Offline

    feildmaster

    schools and dragos240 like this.
  12. Offline

    dragos240

    Thank you very much. If we had REP in this forum, I would REP++ you.
     
  13. Offline

    feildmaster

    Likes work well enough my friend. ;)
     
  14. Offline

    DrBowe

    @Specops343
    You haven't defined player at all. You simply stated the variable...
    I'm assuming the error that you're getting is something along the lines of "player undefined...or NPE at player"

    I'm going to assume this is inside a PlayerListener, and that you have something along the lines of this set up:

    Code:java
    1.  
    2. public void onPlayerInteract(PlayerInteractEvent event){
    3. //do stuff
    4. }
    5.  


    Anywho, back to my original statement, 'player' has to actually store a value. So lets say, for this SimpleWand plugin, you wanted it so that every time a player right clicked with a stick (and had the permission node 'simplewand.fireball'), it shot a fireball:

    Code:java
    1.  
    2. public void onPlayerInteract(PlayerInteraxtEvent event){
    3. //not only state the variable, player, but actually fill it with a player
    4. Player player = event.getPlayer();
    5. //checking for right-click and whether or not the player is holding a stick
    6. if(event.getAction() == Action.RIGHT_CLICK_AIR ){
    7. if(event.getItem() == null)
    8. return;
    9. if(event.getItem().getMaterial() == Material.STICK) {
    10. //checking for permissions
    11. if(Simplewand.permissionHandler.has(player, "simplewand.fireball")) {
    12. //insert fireball shooting shenanigans here
    13. }
    14. }
    15. }
    16. }
    17.  


    Also, ignore the excessive if statements. I know I could have condensed them, but I needed to explain each part (just to be sure we were on the same page ;) )
     
  15. Offline

    Specops343

    -snip-
    I'm dumb.
    Thank you guys, especially @DrBoweNur , for helping me with this.
     
  16. Offline

    DrBowe

    My pleasure :)
     
  17. Offline

    Kohle

    Hehe... I love how you didn't say he wasnt dumb... but really, anyone who can develop a pluin isnt dumb :p Some people are just better at some things...

    TAKE THAT, MOM!
    Hehe. jk.

    -Kohle ;)
     
Thread Status:
Not open for further replies.

Share This Page