Solved Event variables accross classes

Discussion in 'Plugin Development' started by hjackson140701, Jul 30, 2016.

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

    hjackson140701

    Hey everyone,

    I have made a Variables class to easily change things in my plugins without opening all of the individual classes.

    Things like
    public static String pluginName = "ApexHub";​
    work and all I have to do is use
    Variables.pluginName​
    to access it. (the variables class is called Variables).

    I am trying to clear the players inventory on JoinEvent, instead of creating a variable for player in the same JoinEvent class I am trying to create it in the Variables class. Of cource just using
    Player player = e.getPlayer();
    will not work because e is undefined as it is not in the same class as the playerjoinevent.

    Please help me as I want to create all of my variables in the same class.
    How would I create a variable using e.getPlayer() in a different class and make it understand what e. means

    Sorry its really badly written its hard to explain and get my head around
     
  2. Offline

    ArsenArsen

    Why so much static abuse? OOP

    Just do it in the event. I do not see why to do something else.
     
  3. Offline

    Zombie_Striker

    @hjackson140701
    Having separate classes to store certain objects is good for some things, but not for everything. Only do what you are trying to do for constant objects (objects that are not likely to change, like the plugin names, kits, layouts,ect.) The rest can be created in their own classes/methods.

    To answer your question: Just add "Player player" to the parameter of any method that requires the "e.getPlayer()" instance. After that, provide the player's instance when calling the method.
     
  4. Offline

    hjackson140701

    Alright thanks everyone, I will only create things like strings and ints in my variables class and do the rest in the classes where I want to use them.
     
  5. Offline

    Corndogoz

    Is this solved? If so, mark it as solved.
     
Thread Status:
Not open for further replies.

Share This Page