How would I add another plugin as an dependency?

I wanted to make a plugin for a chest shop, however, I need to make it dependent on an economy plugin (EconomyLite) so that it wouldn’t load before the economy plugin and throw a huge fit. Would it be as easy as

dependencies {
    compile 'org.spongepowered:spongeapi:7.0.0'
    compile 'io.github.flibio:EconomyLite:2.14.4'
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

or something else?

I believe you also need to add the dependsOn field to the plugin annotation. There should be documentation for this on sponge docs.

Hold up, you’re going about this in the wrong way in multiple places. Unlike Bukkit/Spigot, Sponge has an EconomyService that plugins can make use of without the need for something like Vault. An implementation of this service must be provided at runtime (aka, installing an economy plugin), but it is not your responsibility to depend on a specific implementation - you only need to verify that something is providing the EconomyService. The Sponge Docs has pages on the Economy Service and general services that I would recommend reading through.

I’m going to presume that your loading issue is a class loading problem, and thus defining a dependency will resolve that. However, you also need to be conscientious of when certain things are initialized during the plugin lifecycle. Certain features, such as the EconomyService, may not be initialized until a later game state. You’ll need to keep this in mind during initialization to ensure you’re not requesting something before it’s available.

For completion, adding a plugin as a dependency can be done through the @Plugin annotation using the dependencies element, as shown below:

@Plugin(id="myplugin", dependencies=@Dependency(id"mydependency"))
1 Like

Yeah, I now realize that registering and doing everything in the GamePreInitializationEvent was probably a BIT early.
So I already have code to check for a economy but I have it commented out for testing purposes. In order to implement the economy plugin would I do something like

Sponge.getServiceManager().provide(EconomyService.class);

to implement the economy service?

That is roughly the correct code, but not the correct terminology. You aren’t implementing the EconomyService, only ensuring that it is being provided by some plugin and using it. In your case, EconomyLite is the plugin that is actually implementing it. Once again, please see the docs on the Economy API for how to handle this properly.

In EconomyLite they register the service like this
game.getServiceManager().setProvider(this, EconomyService.class, economyService);
I was just using the same .class since I’m not on my computer to test the code rn

Also, thanks A LOT for the help! The problem indeed was that I was checking if the economy service was there too early!