How to connect two plugin?

Discussion in 'Spigot Plugin Help' started by Hocbum01, Jul 20, 2018.

  1. Hi, I'm new in java, and I'm trying to connect two plugin:
    I want a plugin for execute a function in an other plugin.
    (Sorry for my english, i don't speak it very well..)
    I made this:
    FirstPlugin:
    Code (Text):

    package me.Hocbum01.PluginHooking1;
    import org.bukkit.plugin.java.JavaPlugin;
    import net.md_5.bungee.api.ChatColor;

    public class Principale extends JavaPlugin {
        public void onEnable() {
            getServer().getConsoleSender().sendMessage(ChatColor.GREEN + "Test Hooking1 Abilitato");
        }

        public float ProvaHooking() {
            return 10;
        }
    }
     
    and the second one (that read the value):
    Code (Text):

    package me.Hocbum01.Hook2;
    import org.bukkit.plugin.java.JavaPlugin;
    import me.Hocbum01.PluginHooking1.Principale;
    import net.md_5.bungee.api.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;

    public class Main extends JavaPlugin implements Listener{
        Principale Principal = new Principale();
       
        public void onEnable() {
            getServer().getConsoleSender().sendMessage(ChatColor.GREEN + "Test Hooking2 Abilitato");
        }
        @EventHandler
        public void onJoin(PlayerJoinEvent event) {
            float Soldi = Principal.ProvaHooking();
            Player player = event.getPlayer();
            player.sendMessage(ChatColor.GREEN + "Soldi: " + Soldi);
           
        }
       
    }
     
    i know i have to add the first plugin in the library of the second, but when i upload the plugin he gave me this error:
    Code (Text):

    [16:21:28] [Server thread/ERROR]: Could not load 'plugins/PluginHooking2.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.IllegalArgumentException: Plugin already initialized!
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:135) ~[spigot-1.9-R0.1-SNAPSHOT-latest.jar:git-Spigot-7d15d07-c194444]
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:329) ~[spigot-1.9-R0.1-SNAPSHOT-latest.jar:git-Spigot-7d15d07-c194444]
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:251) [spigot-1.9-R0.1-SNAPSHOT-latest.jar:git-Spigot-7d15d07-c194444]
        at org.bukkit.craftbukkit.v1_9_R1.CraftServer.loadPlugins(CraftServer.java:296) [spigot-1.9-R0.1-SNAPSHOT-latest.jar:git-Spigot-7d15d07-c194444]
        at org.bukkit.craftbukkit.v1_9_R1.CraftServer.reload(CraftServer.java:743) [spigot-1.9-R0.1-SNAPSHOT-latest.jar:git-Spigot-7d15d07-c194444]
        at org.bukkit.Bukkit.reload(Bukkit.java:539) [spigot-1.9-R0.1-SNAPSHOT-latest.jar:git-Spigot-7d15d07-c194444]
        at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:25) [spigot-1.9-R0.1-SNAPSHOT-latest.jar:git-Spigot-7d15d07-c194444]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) [spigot-1.9-R0.1-SNAPSHOT-latest.jar:git-Spigot-7d15d07-c194444]
        at org.bukkit.craftbukkit.v1_9_R1.CraftServer.dispatchCommand(CraftServer.java:645) [spigot-1.9-R0.1-SNAPSHOT-latest.jar:git-Spigot-7d15d07-c194444]
        at org.bukkit.craftbukkit.v1_9_R1.CraftServer.dispatchServerCommand(CraftServer.java:631) [spigot-1.9-R0.1-SNAPSHOT-latest.jar:git-Spigot-7d15d07-c194444]
        at net.minecraft.server.v1_9_R1.DedicatedServer.aL(DedicatedServer.java:437) [spigot-1.9-R0.1-SNAPSHOT-latest.jar:git-Spigot-7d15d07-c194444]
        at net.minecraft.server.v1_9_R1.DedicatedServer.D(DedicatedServer.java:401) [spigot-1.9-R0.1-SNAPSHOT-latest.jar:git-Spigot-7d15d07-c194444]
        at net.minecraft.server.v1_9_R1.MinecraftServer.C(MinecraftServer.java:655) [spigot-1.9-R0.1-SNAPSHOT-latest.jar:git-Spigot-7d15d07-c194444]
        at net.minecraft.server.v1_9_R1.MinecraftServer.run(MinecraftServer.java:554) [spigot-1.9-R0.1-SNAPSHOT-latest.jar:git-Spigot-7d15d07-c194444]
        at java.lang.Thread.run(Thread.java:748) [?:1.8.0_171]
    Caused by: java.lang.IllegalArgumentException: Plugin already initialized!
        at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:122) ~[spigot-1.9-R0.1-SNAPSHOT-latest.jar:git-Spigot-7d15d07-c194444]
        at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:66) ~[spigot-1.9-R0.1-SNAPSHOT-latest.jar:git-Spigot-7d15d07-c194444]
        at me.Hocbum01.PluginHooking1.Principale.<init>(Principale.java:7) ~[?:?]
        at me.Hocbum01.Hook2.Main.<init>(Main.java:9) ~[?:?]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_171]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[?:1.8.0_171]
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:1.8.0_171]
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[?:1.8.0_171]
        at java.lang.Class.newInstance(Class.java:442) ~[?:1.8.0_171]
        at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:76) ~[spigot-1.9-R0.1-SNAPSHOT-latest.jar:git-Spigot-7d15d07-c194444]
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:131) ~[spigot-1.9-R0.1-SNAPSHOT-latest.jar:git-Spigot-7d15d07-c194444]
        ... 14 more
    Caused by: java.lang.IllegalStateException: Initial initialization
        at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:125) ~[spigot-1.9-R0.1-SNAPSHOT-latest.jar:git-Spigot-7d15d07-c194444]
        at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:66) ~[spigot-1.9-R0.1-SNAPSHOT-latest.jar:git-Spigot-7d15d07-c194444]
        at me.Hocbum01.PluginHooking1.Principale.<init>(Principale.java:7) ~[?:?]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_171]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[?:1.8.0_171]
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:1.8.0_171]
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[?:1.8.0_171]
        at java.lang.Class.newInstance(Class.java:442) ~[?:1.8.0_171]
        at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:76) ~[spigot-1.9-R0.1-SNAPSHOT-latest.jar:git-Spigot-7d15d07-c194444]
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:131) ~[spigot-1.9-R0.1-SNAPSHOT-latest.jar:git-Spigot-7d15d07-c194444]
        ... 14 more
     
    please help me! thank you
     
  2. Do they have seperate names in plugin.yml?
     
  3. yes,
    plugin.yml of the first:

    Code (Text):

    name: PluginHokking1
    author: Hocbum01
    version: 1.0
    main: me.Hocbum01.PluginHooking1.Principale
     
    and the second:

    Code (Text):

    name: Hook
    author: Hocbum01
    version: 1.0
    main: me.Hocbum01.Hook2.Main
     
     
  4. You create a new instance instead of getting the existing one.
     
  5. so how can i solve? :unsure: