Can't get String from my MainClass [1.8]

Discussion in 'Plugin Help/Development/Requests' started by UniqueNameDen, Jan 12, 2015.

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

    UniqueNameDen

    Hello, I used to just getString from my MainClass. but something changed in bukkit/spigot 1.8 or Java 8

    But now I can't

    Any help...?

    [I want to copy version string to another class

    Code:
    String version = "0.0.24"
    I need this to warn about outdated config
     
  2. Offline

    ProMCKingz

  3. Offline

    Skionz

  4. Offline

    mythbusterma

    @ProMCKingz

    How about we actually learn how Object Oriented Programming works before we try to post here.


    @UniqueNameDen

    Make the string a constant, i.e. "public static final." However, the version is already defined and able to be accessed from the plugin description file, or JavaPlugin#getVersion().
     
    AdamQpzm and teej107 like this.
  5. Code:
    public class Main extends JavaPlugin {
       
        private String version;
       
       
        public void onEnable() {
            version = getDescription().getVersion();
        }
       
        public String getVersion() {
            return version;
        }
    }
    
    You should always keep the visibility of your variables in mind when creating or getting them.
    Just make a get method for each value you'd like to access from outside the class.
    For the most part, you should never really have a public variable anyways....
    Or, if you have multiple string values like this, a good way to organize them is to create an enum, and just get them from there.
    All the code you see above is all basic things that you should have learned by now if you're coding bukkit plugins.
    If you've somehow found yourself coding bukkit plugins with zero java knowledge, then instead of searching for answers to your bukkit problems, I suggest searching for answers to you java problems.
    Every time you run into something you're not sure about, strip the Bukkit aspect away, and just bring it back to the basics. That's how you learn.
    If anything I've written confuses you, please don't hesitate to ask for a detailed explanation.
    Good luck!
     
  6. Offline

    UniqueNameDen

    Thank you I just got the version from plugin.yml! [Thanks to @mythbusterma]
     
  7. Offline

    mrCookieSlime

    Moved to Alternatives Section.
     
Thread Status:
Not open for further replies.

Share This Page