1.16.5 Cannot get provider of service 1.16.5

Discussion in 'Spigot Plugin Development' started by Hoshion, Jul 9, 2021.

  1. Hi!

    I have 2 own plugins. In one plugin i made a service registration:
    Code (Text):
    public void onEnable(){
            this.mongoProvider = MongoProvider.connect();
            try{
                Bukkit.getServer().getServicesManager().register(Mongo.class, this.mongoProvider, this, ServicePriority.Normal);
            } catch(Exception e){
                Logger.getLogger("").info(e.getMessage());
            }
            getLogger().info("enabled!");
        }
    In another i connect to it:
    Code (Text):
    this.DB = this.getServer().getServicesManager().getRegistration(com.hoshion.mongoapi.Mongo.class).getProvider();
    And get an error:
    Code (Text):
    [19:07:10] [Server thread/ERROR]: Error occurred while enabling HubPlugin v1.0 (Is it up to date?)
    java.lang.NullPointerException: Cannot invoke "org.bukkit.plugin.RegisteredServiceProvider.getProvider()" because the return value of "org.bukkit.plugin.ServicesManager.getRegistration(java.lang.Class)" is null
          at general.Plugin.onEnable(Plugin.java:65) ~[?:?]
          at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:263) ~[server.jar:3096-Spigot-9fb885e-296df56]
          at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:342) ~[server.jar:3096-Spigot-9fb885e-296df56]
          at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:480) ~[server.jar:3096-Spigot-9fb885e-296df56]
          at org.bukkit.craftbukkit.v1_16_R3.CraftServer.enablePlugin(CraftServer.java:492) ~[server.jar:3096-Spigot-9fb885e-296df56]
          at org.bukkit.craftbukkit.v1_16_R3.CraftServer.enablePlugins(CraftServer.java:406) ~[server.jar:3096-Spigot-9fb885e-296df56]
          at net.minecraft.server.v1_16_R3.MinecraftServer.loadWorld(MinecraftServer.java:554) ~[server.jar:3096-Spigot-9fb885e-296df56]
          at net.minecraft.server.v1_16_R3.DedicatedServer.init(DedicatedServer.java:257) ~[server.jar:3096-Spigot-9fb885e-296df56]
          at net.minecraft.server.v1_16_R3.MinecraftServer.w(MinecraftServer.java:928) ~[server.jar:3096-Spigot-9fb885e-296df56]
          at net.minecraft.server.v1_16_R3.MinecraftServer.lambda$0(MinecraftServer.java:273) ~[server.jar:3096-Spigot-9fb885e-296df56]
          at java.lang.Thread.run(Thread.java:831) [?:?]
     
    I made my second plugin depend on the first one. Also I checked services that are available before calling provider:
    Code (Text):
    [19:07:08] [Server thread/INFO]: net.luckperms.api.LuckPerms
    [19:07:08] [Server thread/INFO]: me.wolfyscript.armorstandtool.metrics.bukkit.Metrics
    [19:07:08] [Server thread/INFO]: com.hoshion.mongoapi.Mongo
    [19:07:08] [Server thread/INFO]: me.gfly.Management.BStatsManagement
    [19:07:08] [Server thread/INFO]: me.wolfyscript.utilities.main.metrics.bukkit.Metrics
    [19:07:08] [Server thread/INFO]: com.comphenix.protocol.metrics.Metrics
    And there is my service. I compile both plugins on Java 15, using maven. Also my first plugin is used as maven dependency for the second (thus, i use the same Mongo.class for getRegistration())