Hi ,
I have asked in Discord without luck, it is something complex and there is little information in google, I have searched several websites and docs for information about it and I can't find anything either, I have been several days without sleeping well just thinking about this, I have only looked at plugins like Vault that applies this interface to create its API, the problem is the following.
I have an API which I have an interface that I'm using to test if this works, the interface is called "TestClazzImpl", then in my main plugin I have a class called "TestClazz" where I apply and get a version (a stupid example, it's just for testing) and where I instantiate with the interface, there I register the interface as a service.
The problem is that when I get the service in the other plugin that wants to use my API the value it returns is null, instead if I use the following it returns the active services of the plugin where only one active service appears which is the interface "TestClazzImpl":
So I don't understand why getting the services by passing the plugin instance parameter works but getting the service by passing the interface class parameter doesn't work.
I make softdepend in plugin.yml. It is the first time that I work with ServicesManager and it may be difficult for me to understand some things, but for the moment I understand what I have explained, I only have this problem that I don't know what it is due to.
In my plugin it returns the service and I get this in the console:
The other plugin tells me that it is empty and returns null. Thanks and I am attentive to anyone who wants to help me.
Code:
My plugin:
My other plugin:
Docs: https://jd.papermc.io/paper/1.16/org/bukkit/plugin/ServicesManager.html
I have asked in Discord without luck, it is something complex and there is little information in google, I have searched several websites and docs for information about it and I can't find anything either, I have been several days without sleeping well just thinking about this, I have only looked at plugins like Vault that applies this interface to create its API, the problem is the following.
I have an API which I have an interface that I'm using to test if this works, the interface is called "TestClazzImpl", then in my main plugin I have a class called "TestClazz" where I apply and get a version (a stupid example, it's just for testing) and where I instantiate with the interface, there I register the interface as a service.
The problem is that when I get the service in the other plugin that wants to use my API the value it returns is null, instead if I use the following it returns the active services of the plugin where only one active service appears which is the interface "TestClazzImpl":
Java:
Plugin sbr = Bukkit.getPluginManager().getPlugin("SimpleBlockRegen");
List<RegisteredServiceProvider<?>> list = getServer().getServicesManager().getRegistrations(sbr);
So I don't understand why getting the services by passing the plugin instance parameter works but getting the service by passing the interface class parameter doesn't work.
I make softdepend in plugin.yml. It is the first time that I work with ServicesManager and it may be difficult for me to understand some things, but for the moment I understand what I have explained, I only have this problem that I don't know what it is due to.
In my plugin it returns the service and I get this in the console:
YAML:
[18:08:34 INFO]: [SimpleBlockRegen] [STDOUT] [org.bukkit.plugin.RegisteredServiceProvider@6d937b49]
The other plugin tells me that it is empty and returns null. Thanks and I am attentive to anyone who wants to help me.
Code:
My plugin:
Java:
public class SimpleBlockRegen extends JavaPlugin {
@Getter
private static SimpleBlockRegen plugin;
private MainModule mainModule;
private TestClazzImpl testClazz;
private ServicesManager sm;
@Override
public void onEnable() {
SimpleBlockRegen.plugin = this;
mainModule = new MainModule(this);
mainModule.load();
this.testClazz = new TestClazz();
this.sm = getServer().getServicesManager();
sm.register(TestClazzImpl.class, this.testClazz, plugin, ServicePriority.Normal);
Collection<RegisteredServiceProvider<TestClazzImpl>> a = getServer().getServicesManager().getRegistrations(TestClazzImpl.class);
if(!a.isEmpty()){
for (RegisteredServiceProvider provider : a) {
System.out.println("Service: " + provider.getService());
}
} else {
System.out.println("Empty");
}
testClazz.setVersion("0.2.0");
System.out.println("Version: " + testClazz.getVersion());
}
@Override
public void onDisable() {
mainModule.unload();
}
}
My other plugin:
Java:
public class SimpleDropInventory extends JavaPlugin {
@Getter
static SimpleDropInventory plugin;
private MainModule mainModule;
private TestClazzImpl testClazz;
@Override
public void onEnable() {
mainModule = new MainModule(this);
mainModule.load();
this.testClazz = getProvider(TestClazzImpl.class);
Collection<RegisteredServiceProvider<TestClazzImpl>> a = getServer().getServicesManager().getRegistrations(TestClazzImpl.class);
if(!a.isEmpty()){
for (RegisteredServiceProvider provider : a) {
System.out.println("Service:" + provider.getService());
}
System.out.println("Version: " + testClazz.getVersion());
} else {
System.out.println("Empty");
}
}
private <T> T getProvider(Class<T> classz) {
RegisteredServiceProvider<T> provider = getServer().getServicesManager().getRegistration(classz);
if (provider == null){
System.out.println("Null");
return null;
}
System.out.println("No null");
return provider.getProvider();
}
@Override
public void onDisable() {
mainModule.unload();
}
}
Docs: https://jd.papermc.io/paper/1.16/org/bukkit/plugin/ServicesManager.html