Solved Use an ArrayList from another plugin

Discussion in 'Spigot Plugin Development' started by ELPUPAS2015, Jul 12, 2019 at 2:23 PM.

  1. Hello, i have a plugin and i'm doing another plugin but i need to use an ArrayList that i have in the other plugin.
    A think like that if(MyPlugin.ArrayListname.contains(p))
     
  2. the arraylist should be static in order to use it in other classes / plugins
    You'll need to add on plugin.yml the softdepend with the plugin name
     
    • Funny Funny x 2
  3. Ok, ill try in one moment
     
  4. Yep, I've deleted my precedent message, but you can have an access to it by putting the variable as static, and add the .jar of the plugin you want to have the arraylist from as a library of the plugin you are coding
     
  5. This isn't true. You need to use the other plugin with the arraylist as a dependency, though. You'd need to work with an instance of your other plugin or whatever class it's in.
    It should only be static if it's meant to be the same across all instances of that class and doesn't require an instance of the class it's in to be functional.
     
    • Agree Agree x 1
  6. Can someone teach me how to do it step by step?
    I do not undertnad, sorry.
     
  7. We are not here to spoonfeed you
     
    • Like Like x 1
  8. Depending on what IDE you're using, figure out how to add your plugin with the arraylist as a dependency to the plugin trying to access it. Then figure out how you access another plugin instance running on the same server. From there, it's working with any other object, just that it's a plugin object.
     
    • Like Like x 1
  9. Sorry but... how i acces my other plugin?
    Like Staffchat sc = staffchat.getPlugin() or similar
     
  10. Code (Text):
    Bukkit.getPluginManager().getPlugin("The plugin name here");
     
  11. With this: upload_2019-7-12_15-55-0.png
    How to acces the ArrayList?
     
    • Useful Useful x 1
  12. Sorry for my ignorance, this is the last thing, upload_2019-7-12_16-9-25.png
    How to cast the main class?
     
  13. Replace "Main" by the main class of the plugin you want to take the variable from

    Code (Text):
    Main mainSC = (Main)Bukkit.getPluginManager().getPlugin("staffchat");
     
    • Useful Useful x 1
  14. Is getting the Main of the Plugin B and not of the plugin A (StaffChat) upload_2019-7-12_16-16-36.png
     
  15. It's because the Main of the plugin B has the same name of the Main of the plugin A
     
  16. Read my signature, but remember that using Main as a plugin main class name is discouraged for this reason.
     
  17. Ok, i changed the main class name, now is StaffChat, but isn't running upload_2019-7-12_16-55-23.png
     
  18. It still needs to be present during workspace time AND in runtime. In order to do this you could use maven, and import it, or as your using eclipse, add a dependency the same way you did the spigot jar.
     
  19. You have put StaffChat as dependency ?