error in my plugin

Discussion in 'Spigot Plugin Development' started by CriptoLabs, Jul 17, 2018.

  1. hello,
    I'm have create a plugin to sorter player in the tablist.
    Code (Java):
    package fr.criptolabs;

    import java.io.File;
    import java.util.Arrays;
    import java.util.Collections;
    import java.util.List;
    import java.util.UUID;

    import org.bukkit.Bukkit;
    import org.bukkit.OfflinePlayer;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerCommandPreprocessEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerQuitEvent;
    import org.bukkit.event.server.ServerCommandEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scoreboard.Scoreboard;
    import org.bukkit.scoreboard.Team;

    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"}));
            Scoreboardbd =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);
                }
         
            }
        }

    }
    but this code give me an error:

    Code (Text):
    [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
    Do you have a answer for this problem or do you have some answer to upgrape my code ?

    Thanks you and have a good day!
     
  2. Try to rebuild the project, and post please your plugin.yml