Static variables different from plugins

Discussion in 'BungeeCord Plugin Development' started by snowyCoder, Jun 22, 2016.

  1. Hello,
    I have two plugin that must work togheter, I cannot say the exact names so lets call them A and B.
    Like I said they must coexist and work togheter, the only problem is that when they try to interact something reeealy strange happends, it seems like they are working in two different java machines.
    when A tries to reache B static variables or method (even the Plugin.getInstance()) it says that it's null and the same for B.
    same thing from onEnable and onCommand (after the initialization).

    to "prove" this I used two commands from the 2 different plugins that must print each other istances of the plugin.

    Code (Text):
    public class ACommand extends Command {

        public ACommand() {
            super("a");
        }

        @Override
        public void execute(CommandSender commandSender, String[] strings) {
            System.out.println("A->" + A.getInstance());
            System.out.println("B->" + B.getInstance());
        }
    }
    same thing for BCommand but with super("b").

    when I execute the command i find this in the console
    Code (Text):
    >a
    09:05:48 [INFORMAZIONI] A->[email protected]
    09:05:48 [INFORMAZIONI] B->null
    >b
    09:05:52 [INFORMAZIONI] A->null
    09:05:52 [INFORMAZIONI] B->[email protected]
    I cannot figure this out, really.
    Can someone please help me?
     
  2. Teg

    Teg
    Supporter

    Most likely the getInstance methods of both class A and class B are returning null. Can you show us the main classes of both plugins?
     
  3. Code (Text):
    public class A extends Plugin {

        private static A instance;

        public A() {
            instance = this;
        }

        public static A getInstance() {
            return instance;
        }
    }
    Same thing for B
     
  4. Move instance = this; to the onEnable().

    (Idk if the name is the same in Bungee...)
     
  5. Ok this is too much simplified.
    In my project I have a common part and a part shared between bungeecord and bukkit with two different wrappers.
    This is super useful when you have to do things like database api.
    to create two different jars I used Ant.

    The project structure is this:
    TestBungeeA
    |
    -plugin_descriptor
    | -bukkit
    | | -plugin.yml
    | -bungee
    | -plugin.yml
    -src
    | -a.wrappers //those are two folders
    | | -bukkit
    | | | -ABukkit
    | | -bungee
    | | | -ABungee
    | | | -ACommand
    -build.xml //the ant file
    -build.proprietes

    the ant file (It's too large, no one will read it) simply compiles the source with bukkit and bungee and after he creates two versions, one for bukkit, without wrappers.bungee and with plugin_descriptor.bukkit.plugin.yml in his path and the other for bungee without wrappers.bukkit and with plugin_descriptor.bungee.plugin.yml in his path.
    this thing works and creates two different jars for either bungee or bukkit.
    the problem is that (I don't freaking know why) two plugins made with this cannot comunicate (in bungee, i don't know for bukkit)
     
  6. Here's the project files.
    Thanks for any help
     

    Attached Files:

  7. For now I'll use multiple modules as wrappers but I want to be updated with this, if someone knows the solution let me know!
    Necroposting allowed here!
     
  8. Look into plugin messaging channels or sockets.
    PS: When you have one plugin on the bungee side and one on the spigot side, they of course are in two different JVMs!
     
  9. They are made to create two versions of themselves, for example lets say you have two plugins: database and databaseUtilizer, if this code works you would have databaseBukkit, databaseBungee, databaseUtilizerBukkit and databaseUtilizerBungee.
    But, I don't know why the databaseBungee and databaseUtilizerBungee (which are running on the same bungeecord) cannot communicate