Solved I need help for the arraylist

Discussion in 'Spigot Help' started by PabloGamer380YT, Apr 23, 2017.

  1. Hello, I am trying to make in my plugin the command / freeze
    This would be the main code

    I'm using ArrayList active, what I would like to know is that how do I use an arraylist in some other class ?? Since the Freeze Command I have it in a separate class and the listeners I have in another class, and I am using this code in the listeners class:

    And at the time of executing the command / freeze on the server, I execute the normal actions of the command, but the events do not register them, the onPlayerMove event does not register me and I already put in the main class
    "getServer().getPluginManager().registerEvents(new LFreeze(), this);

    And I do not know if it is that arraylist, they only work in a class, or if there is some way to use it in several classes
  2. electronicboy

    IRC Staff

    I would suggest reading up on OOP, the general idea is that you shouldn't expose the arraylist itself (a hashset would also be much better in this case), but expose methods to manipulate the array list as needed from other classes, create a new instance of LFreeze, store it to a field as needed, and pass that field to registerEvents (Or, refactor your code so that you pass a plugin reference to the constructor of LFreeze which will call registerEvents)
  3. Hello, thanks for the answer, but I could give a more detailed answer, is that I am something new in this programming, and my English is something bad and I did not understand much of what he meant
  4. The simplest way is to make the ArrayList public static but this looks really bad but if you do it you can accses the arraylist from other classes like; for example c:;;

    I hope i can helpt you with this answere

    (and oop means
    Object-oriented programming that means you create a object and do something with it and do not use static (i cant go into details from oop because this would be to long. but you can read
  5. @Group

    Thank you very much @GROUPDEV
    I solved my problem thanks to your advice: D