Getting an instance from another plugin.

Discussion in 'Spigot Plugin Development' started by ericevo, Jul 4, 2018.

  1. Hi all! Today I were "Hooking" my chat plugin with marriagemaster, but Idk how to get the instance from there

    I was using this:
    Code (Text):
        MarriagePlugin mp = new MarriagePlugin();
        MarriageCore core = new MarriageCore(mp);
    And throwing this error:

    Line 306 from Main:
    Code (Text):
     new AsyncPlayerChat();
    Thanks to all!
     
    • Useful Useful x 1
  2. Praya

    Benefactor

    what billy mean is you don't need to create other plugin instance.
    just check if the plugin is already enabled, and then create instance of class do you want.

    if you want to get other plugin main class, just:
    MainClass plugin = JavaPlugin.getPlugin(MainClass.class);
     
  3. Literally exactly what I said...
    Code (Text):
    MariagePlugin mp;
    if (Bukkit.getServer().getPluginManager().isPluginEnabled("Marriage")) {
         mp = (MariagePlugin) Bukkit.getServer().getPluginManager().getPlugin("Marriage");
    }
     
    • Agree Agree x 1
  4. This informs you that the Plugin has already been initialized,
    you can only have one instance of a plugin at a time.

    You can use Bukkit to get the existing instance of the plugin,
    Code (Java):
    Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("{ PLUGIN NAME }");
     
  5. @AspyTheAussie @BillyGalbreath Im getting this error:
    Code:
    Code (Text):


                    if (plugin.servername.equalsIgnoreCase("Creative")) {
                        MarriagePlugin mp;
                        MarriageCore core;
                        if (Bukkit.getServer().getPluginManager().isPluginEnabled("Marriage")) {
                             mp = (MarriagePlugin) Bukkit.getServer().getPluginManager().getPlugin("Marriage");
                             core = (MarriageCore) Bukkit.getServer().getPluginManager().getPlugin("Marriage");
                             MPlayer mp2 = core.getMPlayer(player);
                        if (mp2.isMarried()) {
                            prisonPrefixes = mp2.getGender().getChatPrefix()+" &4&l❤ ";
                        } else {
                            prisonPrefixes = mp2.getGender().getChatPrefix()+" ";
                      }
                   }
     
                } else {
                    prisonPrefixes = Rank.getRank(player).getPrefix(player, true);
                }
     
     
    #7 ericevo, Jul 4, 2018
    Last edited: Jul 4, 2018
  6. Code (Text):
    Caused by: java.lang.ClassCastException: com.lenis0012.bukkit.marriage2.internal.MarriagePlugin cannot be cast to com.lenis0012.bukkit.marriage2.internal.MarriageCore
    Code (Text):
    mp = (MarriagePlugin) Bukkit.getServer().getPluginManager().getPlugin("Marriage");
    core = (MarriageCore) Bukkit.getServer().getPluginManager().getPlugin("Marriage");
    This is why copy pasting shit is bad. You need to think. Read the code given to you, and understand it.
     
  7. My bad lol, now works ^-^
    Code (Text):
                             mp = (MarriagePlugin) Bukkit.getServer().getPluginManager().getPlugin("Marriage");
                             core = (MarriageCore) MarriagePlugin.getCore();