yannicklamprecht/WorldBorderAPI

worldBorderApiRegisteredServiceProvider always returning null

EnriqueGF opened this issue · 2 comments

Describe the bug
My plugin is set to start before all plugins, so I wait 30 tics before instanciating the worldBorderApiRegisteredServiceProvider. But no matters how much time I wait, the worldBorderApiRegisteredServiceProvider is always null....

My main:

package devep;

import com.github.yannicklamprecht.worldborder.api.WorldBorderApi;
import org.bukkit.*;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;

public class SalvosMCRPG extends JavaPlugin {

    public static DB db;
    public static Plugin plugin;
    public static Location spawnLocation;
    public static WorldBorderApi worldBorderAPI;

    @Override
    public void onEnable(){

        this.plugin = this;
        //db = new DB(this.getLogger());

        getServer().getPluginManager().registerEvents(new EventListener(), SalvosMCRPG.plugin);
        getServer().getPluginManager().registerEvents(new SwordAbilitySystem(), SalvosMCRPG.plugin);

        new BukkitRunnable() {
            @Override
            public void run() {

                RegisteredServiceProvider<WorldBorderApi> worldBorderApiRegisteredServiceProvider = SalvosMCRPG.plugin.getServer().getServicesManager().getRegistration(WorldBorderApi.class);

                if (worldBorderApiRegisteredServiceProvider == null) {
                    getLogger().info("ERROR WorldBorder API not found");
                    getServer().getPluginManager().disablePlugin(SalvosMCRPG.plugin);
                    return;
                }

                WorldBorderApi worldBorderAPI = worldBorderApiRegisteredServiceProvider.getProvider();
                if (worldBorderAPI != null) {
                    getLogger().info("[SalvosMC-RPG] WorldBorderApi Cargado");
                }

                SalvosMCRPG.worldBorderAPI = worldBorderAPI;

            }

        }.runTaskLater(plugin, 30);

        Bukkit.getLogger().info("[SalvosMC-RPG] Iniciado y cargado");
    }

    @Override
    public void onDisable(){
        //Fired when the server stops and disables all plugins
    }

}

My pom:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>000001</groupId>
    <artifactId>SalvosMC-RPG</artifactId>
    <version>1.0-SNAPSHOT</version>
    <build>
        <resources>
            <resource>
                <directory>${basedir}/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>*</include>
                </includes>
            </resource>
        </resources>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.4</version>
                <configuration>
                    <!-- put your configurations here -->
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <repositories>
        <repository>
            <id>spigot-repo</id>
            <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
        </repository>
        <repository>
            <id>eldonexus</id>
            <url>https://eldonexus.de/repository/maven-releases/</url>
        </repository>
    </repositories>
    <dependencies>
        <dependency>
            <groupId>org.spigotmc</groupId>
            <artifactId>spigot-api</artifactId>
            <version>1.17.1-R0.1-SNAPSHOT</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.22</version>
        </dependency>
        <dependency>
            <groupId>com.github.yannicklamprecht.worldborderapi</groupId>
            <artifactId>api</artifactId>
            <version>1.170.0</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.6</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>16</maven.compiler.source>
        <maven.compiler.target>16</maven.compiler.target>
        <java.version>16</java.version>
    </properties>
</project>

My plugin.yml:


name: SalvosMC-RPG
version: 0.1
author: Enrique
main: devep.SalvosMCRPG
api-version: 1.16
depend: [WorldBorderAPI]
load: STARTUP

I have to say that worldborderapiplugin-1.171.0-all.jar is in plugin folder and is correctly loaded.

Thanks you

Do not shade the plugin. Switch to scope provided. Updated Readme, expected developers to know what they're doing when using shade plugin.

Do not shade the plugin. Switch to scope provided. Updated Readme, expected developers to know what they're doing when using shade plugin.

Hello, first of all sorry about that, I dont develop compiled applications usually.

Switching to scope provided solved the issue.

Thank's you very much.