Using a 'getter' from another class.

Discussion in 'Plugin Development' started by pers2981, Aug 20, 2012.

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

    pers2981

    Hey there

    So inside my main class I have a pretty simple 'getter' function.

    boolean HasBegun = false;

    public boolean GetHasBegun()
    {
    return HasBegun;
    }

    How would I use this function inside another class? The main class is called battledome

    BattleDome.GetHasBegun(); doesn't work
     
  2. Offline

    mcgamer99

    You need to set your methods to static, like this:
    Code:
    static boolean HasBegun = false;
     
    public static boolean GetHasBegun()
    {
    return HasBegun;
    }
    And then
    Code:
    BattleDome.GetHasBegun();
    Should works.
     
  3. Offline

    Tog

    The method doesn't have to be static.
    One way of doing this is by passing your main class to the other class when declaring it:
    Code:
    private final YOURCLASS variablename = new YOURCLASS(this);
    and the constructor of "YOURCLASS":
    Code:
        public YOURCLASS(BattleDome plugin) {
            this.plugin = plugin;
        }
    If you've done that you should be able to use any public methods inside your main class like this:
    Code:
    plugin.getHasBegun();
     
Thread Status:
Not open for further replies.

Share This Page