我的插件代码错误

时间:2018-07-17 11:46:39

标签: api minecraft bukkit

我已经使用Spigot API创建了一个插件。

我创建了一个插件来对播放器列表中的播放器进行排序。

package fr.criptolabs;

public class Tablist extends JavaPlugin implements Listener{

    @Override
    public void onEnable() {
        getServer().getPluginManager().registerEvents(this, this);

        System.out.println("Tablist Sorter : ON");

        onTabClear();
        onTab();
    } 

    public void setScoreboard() {
        Scoreboard bd =Bukkit.getScoreboardManager().getMainScoreboard();
        for(Player pls:Bukkit.getOnlinePlayers()) {
            pls.setScoreboard(bd);

        }
    }

    public void onTabClear() {
        Scoreboard bd =Bukkit.getScoreboardManager().getMainScoreboard();
        for(int i=01;i!=23;i++) {

            if((bd.getTeams()).contains(bd.getTeam( String.format( "%02d", i)))) {
                (bd.getTeam( String.format( "%02d", i))).unregister();
            }
            bd.registerNewTeam(( String.format( "%02d", i) ));
        }
    }

    public void onTabPlayerJoin(Player player) {
        List<String> ranks = Collections.unmodifiableList(
                 Arrays.asList(new String[]{"Admin" ,"Operateur","Moderateur","Moderateurtest","Developpeur","Architecte","Redacteur","Chevalier", "Ecuyer", "Tavernier", "Armurier","Charpentier","Enchanteur","Eleveur","Forgeron","Ebeniste","Alchimiste","Fermier","Mineur","Bucheron","Chasseur","Vagabond"}));
        Scoreboard bd =Bukkit.getScoreboardManager().getMainScoreboard();
        File file = new File("plugins/GroupManager/worlds/ressources/users.yml");
        FileConfiguration configuration = YamlConfiguration.loadConfiguration(file);

        UUID uuidpls= player.getUniqueId();
        String grade = configuration.getString("users."+uuidpls+".group");

        for(String rank:ranks) {
            if(rank.equals(grade)) {
                Team place=bd.getTeam(String.format("%02d",((ranks.indexOf(rank)+1))));
                place.addEntry(player.getName());


                break;
            }
        }
        setScoreboard();
    }

    public void onTabPlayerQuit(OfflinePlayer player) {
        Scoreboard bd =Bukkit.getScoreboardManager().getMainScoreboard();
        for(int i=01;i!=23;i++) {
            Team team=bd.getTeam( String.format( "%02d", i));
            if(team.hasEntry(player.getName())) {
                team.removeEntry(player.getName());
            }
        }
        setScoreboard();
    }

    public void onTab() {
        List<String> ranks = Collections.unmodifiableList(
                 Arrays.asList(new String[]{"Admin" ,"Operateur","Moderateur","Moderateurtest","Developpeur","Architecte","Redacteur","Chevalier", "Ecuyer", "Tavernier", "Armurier","Charpentier","Enchanteur","Eleveur","Forgeron","Ebeniste","Alchimiste","Fermier","Mineur","Bucheron","Chasseur","Vagabond"}));
        Scoreboard bd =Bukkit.getScoreboardManager().getMainScoreboard();
        File file = new File("plugins/GroupManager/worlds/ressources/users.yml");
        FileConfiguration configuration = YamlConfiguration.loadConfiguration(file);

        for (Player pls: Bukkit.getOnlinePlayers()) {
            UUID uuidpls= pls.getUniqueId();
            String grade = configuration.getString("users."+uuidpls+".group");

            for(String rank:ranks) {
                if(rank.equals(grade)) {
                    Team place=bd.getTeam(String.format("%02d",((ranks.indexOf(rank)+1))));
                    place.addEntry(pls.getName());

                    break;
                }       
            }

        }
        setScoreboard();
    }
    @EventHandler
    public void OnJoin(PlayerJoinEvent event) {
        Player player=event.getPlayer();

        onTabPlayerJoin(player);
    }

    @EventHandler
    public void OnQuit(PlayerQuitEvent event) {
        Player player=event.getPlayer();
        onTabPlayerQuit(player);
    }

    @EventHandler
    public void onCommandManuAdd(PlayerCommandPreprocessEvent event) {
        String command = event.getMessage().replaceFirst("/", "");
        String[] tab=command.split(" ");
        if(tab[0].contains("manuadd")||tab[0].contains("manuaddsub")||tab[0].contains("manudelsub")) {
            Player player= Bukkit.getServer().getPlayer(tab[1]);
            if(!(player==null)) {
                Bukkit.getScheduler().runTaskLater(this,new  Runnable() {

                    @Override
                    public void run() {
                        onTabPlayerQuit(player);
                        onTabPlayerJoin(player);

                    }
                }, 20);
            }
        }
    }

    @EventHandler
    public void onCommandManuAddServer(ServerCommandEvent event) {
        String command = event.getCommand();
        String[] tab=command.split(" ");
        if(tab[0].contains("manuadd")||tab[0].contains("manuaddsub")||tab[0].contains("manudelsub")) {
            Player player= Bukkit.getServer().getPlayer(tab[1]);
            if(!(player==null)) {
                Bukkit.getScheduler().runTaskLater(this,new  Runnable() {

                    @Override
                    public void run() {
                        onTabPlayerQuit(player);
                        onTabPlayerJoin(player);
                    }
                }, 20);
            }
        }
    }
}

但是我有一个错误。

[13:00:15] [Server thread/WARN]: org.bukkit.plugin.InvalidPluginException: java.lang.NoClassDefFoundError: Could not initialize class fr.criptolabs.Tablist
[13:00:15] [Server thread/WARN]:    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:131)
[13:00:15] [Server thread/WARN]:    at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:329)
[13:00:15] [Server thread/WARN]:    at com.rylinaux.plugman.util.PluginUtil.load(PluginUtil.java:356)
[13:00:15] [Server thread/WARN]:    at com.rylinaux.plugman.command.LoadCommand.execute(LoadCommand.java:114)
[13:00:15] [Server thread/WARN]:    at com.rylinaux.plugman.PlugManCommandHandler.onCommand(PlugManCommandHandler.java:95)
[13:00:15] [Server thread/WARN]:    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
[13:00:15] [Server thread/WARN]:    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:151)
[13:00:15] [Server thread/WARN]:    at org.bukkit.craftbukkit.v1_12_R1.CraftServer.dispatchCommand(CraftServer.java:685)
[13:00:15] [Server thread/WARN]:    at net.minecraft.server.v1_12_R1.PlayerConnection.handleCommand(PlayerConnection.java:1472)
[13:00:15] [Server thread/WARN]:    at net.minecraft.server.v1_12_R1.PlayerConnection.a(PlayerConnection.java:1277)
[13:00:15] [Server thread/WARN]:    at net.minecraft.server.v1_12_R1.PacketPlayInChat.a(PacketPlayInChat.java:45)
[13:00:15] [Server thread/WARN]:    at net.minecraft.server.v1_12_R1.PacketPlayInChat.a(PacketPlayInChat.java:5)
[13:00:15] [Server thread/WARN]:    at net.minecraft.server.v1_12_R1.PlayerConnectionUtils.lambda$ensureMainThread$0(PlayerConnectionUtils.java:14)
[13:00:15] [Server thread/WARN]:    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[13:00:15] [Server thread/WARN]:    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[13:00:15] [Server thread/WARN]:    at net.minecraft.server.v1_12_R1.SystemUtils.a(SourceFile:46)
[13:00:15] [Server thread/WARN]:    at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:843)
[13:00:15] [Server thread/WARN]:    at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:427)
[13:00:15] [Server thread/WARN]:    at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:767)
[13:00:15] [Server thread/WARN]:    at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:665)
[13:00:15] [Server thread/WARN]:    at java.lang.Thread.run(Thread.java:748)
[13:00:15] [Server thread/WARN]: Caused by: java.lang.NoClassDefFoundError: Could not initialize class fr.criptolabs.Tablist
[13:00:15] [Server thread/WARN]:    at java.lang.Class.forName0(Native Method)
[13:00:15] [Server thread/WARN]:    at java.lang.Class.forName(Class.java:348)
[13:00:15] [Server thread/WARN]:    at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:82)
[13:00:15] [Server thread/WARN]:    at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:127)
[13:00:15] [Server thread/WARN]:    ... 20 more

我不知道代码中的问题在哪里。该插件可以在我的测试服务器上使用,但不能在该服务器上使用。 我想我犯了一个错误,但我不知道在哪里以及为什么。

此代码有什么问题?

1 个答案:

答案 0 :(得分:0)

文件文件=新文件(“ plugins / GroupManager / worlds / ressources / users.yml”); 您将资源拼写错误,但这不是错误

问题是Spigot无法找到您的主类,请尝试实际重新启动服务器,可能是Plugman。