Solved hasPermission() working backwards!

Discussion in 'Plugin Development' started by mtrack260, Feb 2, 2016.

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

    mtrack260

    Hi everybody!
    Today I have a little trouble with the hasPermission() tag.

    In my code, I defined that:

    Code:
    THREAD SOLVED
    But, when I run it on the server if the player has got the "rank.user" permission can use the command, but Op players can't.

    My question is, what I'm doing wrong? It doesn't supposed that if the player has the rank.user permission return an error message?

    PS: I did't use quotation marks inside the hasPermission(-HERE-) because I'm calling a class named "rank" who has got a String named "user". The same with the sendMessage().

    PS 2: I'm sorry about my english but isn't my native language :p
     
    Last edited: Feb 6, 2016
  2. Offline

    Go Hard

    Check to see if the player is OP
    Code:
    if(player.isOp()) {
     
  3. Offline

    WolfMage1

    1.In your plugin.yml have you registered the permission and defaulted it to op?
    2.In order to better assist you with this problem, we need to see the rank.user
    3.In this case for a ranking system, it would be better to use an ENUM (if you're not already and for some reason are using an enum lower case)
     
  4. Offline

    mtrack260

    1. No, I did not registered the permission 'cause in other Bukkit versions the code that I use worked perfectly fine.
    2. The class "rank" have just a list of String = "text". But, here is the code:
    Code:
    THREAD SOLVED
    
    I use this method because, if I want to rename some of the server ranks I will not have to modify class by class of the plugin.
    3. I'm not using ENUM or enum, as you can see in the code posted above, I use a simple class with public Strings to access them from any class of the server, this is because, if I use enum instead of class I can't put dots in the permissions.
    PS: I'm coding a private plugin for my server that is because I don't use individual permissions as "server.fly.hasPerm", for example.
     
    Last edited: Feb 6, 2016
  5. Offline

    Firestar311

    @mtrack260 Have you tried Final? And it would be even more helpful if you posted more of the code, like the declaration of the player object and I assume the onCommand() method is where this is located

    Code:java
    1. package me.frank.repository;
    2. public class Rank {
    3. public static final String user = "rank.user";
    4. public static final String vip = "rank.vip";
    5. public static final String mod = "rank.mod";
    6. public static final String dev = "rank.dev";
    7. public static final String admin = "rank.admin";
    8. public static final String master = "rank.master";
    9. }
     
  6. Offline

    I Al Istannen

    @Jayfeather311
    @mtrack260

    And now we could agree to write them in Uppercase. That way you can see they are constants after a short glance :)
     
  7. Offline

    mtrack260

    Code:java
    1.  
     
    Last edited: Feb 6, 2016
  8. Offline

    Firestar311

    @mtrack260 Due to the fact that you do not have a constructor, I know the problem. Add this line to the top of your "fly" class. I am substituting "Main" as the class name for the one that extends JavaPlugin, change it to how yours is setup.
    Code:java
    1. Main plugin;

    Then create a constructor shown below.
    Code:java
    1. public fly(Main passedPlugin) {
    2. plugin = passedPlugin;
    3. plugin.getServer().getPluginManager().registerEvents(this, plugin);
    4. }

    Then in your main class in your onEnable() method, remove the register events if you have it there and add this
    Code:java
    1. new fly(this);
     
  9. Offline

    mtrack260

    I tried, and it keeps working backwards.
     
    Last edited: Feb 3, 2016
  10. Offline

    WolfMage1

    @mtrack260
    Have you tried putting the permission in directly instead of getting it from another class?

    And please start your class names with an upper-case letter.
     
  11. @Jayfeather311
    How would this affect anything? Do you even know what constructors are for? And with your example, why isn't that field private and final?
     
  12. That's just an example... But i wouldn't register events like that.
     
  13. Offline

    WinX64

    Quoting from your lastest code:
    Code:
    if(p.hasPermission(rank.user)) {
                p.sendMessage(text.flySuff + text.noPerm);
                p.playSound(p.getLocation(), sounds.errorSound, 1, 1);
                return true;
            } else { ...
    
    So, you're checking if the player has the permission, and if they have... tell them they don't? Isn't it supposed to be the other way around?
     
Thread Status:
Not open for further replies.

Share This Page