Solved Plugin loading problem on server start

LinuxSquare

New member
Jan 20, 2024
2
0
1
I have two self-written plugins. NovEcon2 and RealBanks2.

NovEcon2 is my economy-plugin, which depends on Vault and RealBanks2 as softdepend.
RealBanks2 is my banking-plugin, which also depends on Vault.

Source-code is available here (important, stay in branch kotlin-rewrite):
NovEcon2: https://codeberg.org/Noveria/NovEcon2/src/branch/kotlin-rewrite
RealBanks2: https://codeberg.org/Noveria/RealBanks2/src/branch/kotlin-rewrite

I have implemented an api inside RealBanks2, to access some functions inside NovEcon2.

The api can be enabled in NovEcon2, via a configlet-bool set to true
However, since both plugins depend on Vault, loading them while the configlet-bool set to true is impossible as of now.

Since RealBanks2 requires an economy-plugin to be loaded and NovEcon2 requires RealBanks2 to be loaded, none of them are getting loaded.
That ends in NovEcon2 failing to load, because RealBanks2 isn't loaded and RealBanks2 failing to load , because there is no economy-plugin hooked into vault, such as NovEcon2.

Is there any way, I can prevent that?
I have thought about a separate bridge plugin, but afaik, it would end in the same issue, since the bridge-plugin would be needed by NovEcon2, and the bridge-plugin would depend on RealBanks2.

I'm open for any idea.

Thanks.
 
Logs
https://paste.gg/p/anonymous/94a480a6d35249c08ffff16c52c58c33
Version Output
This server is running Paper version git-Paper-550 (MC: 1.19.4) (Implementing API version 1.19.4-R0.1-SNAPSHOT) (Git: 483368e on ver/1.19.4)
You are running the latest version

LinuxSquare

New member
Jan 20, 2024
2
0
1
After a long search, the following procedure solved my problem:

There is an event, called ServiceRegisterEvent. It can be used to get services, when they are registered on server start.

I listened for the service Economy and if that occured, I loaded the Economy-Plugin.

I also had to edit the plugin.yml of the Banking-Plugin, to load before the Economy-Plugin.

ServiceRegisterEvent:
Code:
internal class ServiceRegisterListener(private val realBanks2: RealBanks) : Listener {
    @EventHandler
    fun onEconomyServiceRegister(e: ServiceRegisterEvent) {
        if(e.provider.service.simpleName.equals("Economy")) {
            if(!realBanks2.setupEconomy()) {
                RealBanks.LOG.severe(String.format("[%s] - Disabled due to no Vault dependency found!", realBanks2.name))
                realBanks2.server.pluginManager.disablePlugin(realBanks2)
                return
            }
        }
    }
}

plugin.yml
YAML:
name: RealBanks2
version: ${project.version}
main: me.linuxsquare.realbanks2.RealBanks
api-version: "1.19"
depend: [Vault, PlayerUUIDCache]
loadbefore:
    - NovEcon2
author: LinuxSquare
website: https://codeberg.org/Noveria/RealBanks2