Solved 2 Classes.

Discussion in 'Spigot Plugin Development' started by Aeryes, May 14, 2016.

  1. Hey guys, I know this will sound trivial but I am totally stuck on making a separate class for my perms.

    How can I place my perms in a PermissionsClass and then use them in my Main class.

    Thank you for your time.
  2. 1. Learn java
    2. Profit
    • Agree Agree x 3
  3. You can use static or a constructor to achieve access to your permissions class from your main. In your method where you save the permissions, make it static like this: public static void perms();

    Then in your main class to access them do this:
  4. > Create a class
    > put in "public static final Permission yourPerm = new Permission(...)"
  5. Code (Java):
    class Permissions
        protected static final String PLUGIN_PREFIX = "pluginprefix.";
        public class Commands
            private final String PREFIX = PLUGIN_PREFIX + "commands.";
            public static final Permission HELP = new Permission(PREFIX + "help");
       // etc
    Code (Java):
    void onEnable()
        for (Field f : Permissions.Commands.class.getFields())
    To use one, Permissions.Commands.HELP.
  6. I like this. Really neat and tidy. I will use this method of doing it. Thanks very much for the help !!
    EDIT: Its is saying that I cannot use PREFIX from a non static context.
  7. Put PREFIX as static then...?
  8. I failed on two things.
    Inner classes have to be static, and the PREFIX field has to be static.
  9. Okay. Ill figure it out.

    I can't get the constructor to work.

    Example of what I am doing.

    I make a constructor:
    public Permissions() {

    I put the Permissions in the constructor as final.

    Then in my main class I make a new object:

    PermissionsClass pm = new PermissionsClass();

    Then do:


    But it won't work.

    EDIT: Figured it out. Thanks.
    #9 Aeryes, May 15, 2016
    Last edited: May 15, 2016