Solved Integer gets reset after onEnable

Discussion in 'Plugin Development' started by ItsComits, Oct 10, 2017.

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

    ItsComits

    Hello, The issue lies between the onEnable and the method that loads up the data from a yml file.
    This is the method that I use to load up the data. This is activated when the plugin starts:

    Code:
    Make sure not to make 2 instances. This will set any variable to the default value in the class.
        }
     
    Last edited: Oct 11, 2017
  2. Offline

    MightyOne

    But you just misspelled int in the first line here?
    Where exactly are you getting the error? Console error? Sent message?
     
  3. Offline

    ItsComits

    @MightyOne There is no error in console. The arenaSize gets reset after loadArenas() for some reason. ('in' was a mistype.)
     
  4. Offline

    MightyOne

    How do you recieve that information? Wrong arena size is an error and Id like to know where you get that error. Otherise its hard to determine you did the mistake or something complete else is failing
     
  5. Offline

    Caderape2

    @ItsComits
    We can't say much with just this code, but do you use the same instance for both methods ?
     
  6. Offline

    ItsComits

    @Caderape2 I have this in my on Enable method if this effects it. Also, I just use a global variable to access the arenaSize wherever in the class:
    ArenaManager manager = new ArenaManager(this);
    manager.loadArenas();
     
  7. Offline

    Caderape2

    @ItsComits and how do you call the method for create an arena ?

    If y ou have this in your onEnable, do you store the variable manager in a field ? Or do you call again the constructor for create an arena
     
  8. Offline

    ItsComits

    @Caderape2 I have this:
    public static ArenaManager am = new ArenaManager(plugin);

    public static ArenaManager getManager() {
    return am;
    }
    So when I want to do something in another class. I do ArenaManager.getManager.createArena.
     
  9. Offline

    Caderape2

    @ItsComits
    Can y ou show the onEnable method ?
     
  10. Offline

    ItsComits

    @Caderape2 Here is my onEnable:
    Code:
        public void onEnable() {
            new ArenasYML(this).createArenasYML();
            new MessagesYML(this).createMessagesYML();
            ArenaManager manager = new ArenaManager(this);
            manager.loadArenas();
            getCommand("arena").setExecutor(new cmd());
    }
     
  11. Offline

    Caderape2

    @ItsComits Yea. You create two instance of the same class. One in your onEnable, and one static. Both are not the same, this is why you arenaSize is at 0.
    Remove this and use the static one.
     
  12. Offline

    ItsComits

    @Caderape2 Yeh I got it work. Your help is much appreciated. :D Also any tips on how to improve the code?
     
Thread Status:
Not open for further replies.

Share This Page