Solved Unhandled exception executing command

Discussion in 'Spigot Plugin Development' started by Pierre26, Jun 18, 2021.

  1. Hello, I have a problem when I run this command, I have this error: "Unhandled exception executing command". Thank you for your help !

    Code (Text):
    package fr.falkanox.bingo.commands;

    import dev.jcsoftware.jscoreboards.JPerPlayerMethodBasedScoreboard;
    import fr.falkanox.bingo.Bingo;
    import fr.falkanox.bingo.states.GState;
    import org.bukkit.Bukkit;
    import org.bukkit.Sound;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.scheduler.BukkitRunnable;

    public class BingoCommands implements CommandExecutor  {

        private Bingo main;
        private JPerPlayerMethodBasedScoreboard scoreboard;
        public BingoCommands(JPerPlayerMethodBasedScoreboard scoreboard, Bingo main){
            this.main = main;
            this.scoreboard = scoreboard;
        }

        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {

            if(label.equalsIgnoreCase("bingo")){

                if(sender instanceof Player){

                    Player p = (Player) sender;

                    if(p.isOp()){

                        if(args.length == 1){

                            if(args[0].equalsIgnoreCase("start")){

                                if(main.isState(GState.WAITING)){

                                    if(scoreboard.findTeam("Rouge").get().getEntities().size() == 1 && scoreboard.findTeam("Bleue").get().getEntities().size() == 1 && scoreboard.findTeam("Neutre").get().getEntities().size() == 0){

                                        p.closeInventory();
                                        main.setState(GState.STARTING);
                                        main.getStartingTask().run();

                                    } else {

                                        p.sendMessage(main.getError() + "Il y a : " + scoreboard.findTeam("Rouge").get().getEntities().size() + " joueur(s) dans l'équipe rouge, " + scoreboard.findTeam("Bleue").get().getEntities().size() + " joueur(s) dans l'équipe bleue et " + scoreboard.findTeam("Neutre").get().getEntities().size() + " joueur(s) dans aucune des deux équipes !");
                                        p.playSound(p.getLocation(), Sound.ENTITY_ENDERMAN_TELEPORT, 3, 3);

                                    }

                                } else {

                                    p.sendMessage(main.getError() + "La partie a déjà commencé !");
                                    p.playSound(p.getLocation(), Sound.ENTITY_ENDERMAN_TELEPORT, 3, 3);

                                }

                            } else if(args[0].equalsIgnoreCase("help")){

                                helpMessage(p);

                            }

                        } else helpMessage(p);

                    } else {

                        p.sendMessage(main.getError() + "Vous devez être administrateur pour effectuer cette commande !");
                        p.playSound(p.getLocation(), Sound.ENTITY_ENDERMAN_TELEPORT, 3, 3);

                    }


            } else sender.sendMessage(main.getError() + "Vous devez etre un joueur pour faire cette commande !");

            }

            return false;
        }

        private void helpMessage(Player p) {

            p.sendMessage("§e--------------------------------------------------");
            p.sendMessage("");
            p.sendMessage("§b/bingo start§7: - §eCommencez la partie de bingo, requis 1 joueur dans chaque équipe");
            p.sendMessage("");
            p.sendMessage("");
            p.sendMessage("§e--------------------------------------------------");

            p.playSound(p.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 5, 5);

        }

    }
     
    Code (Text):
    package fr.falkanox.bingo.tasks;

    import fr.falkanox.bingo.Bingo;
    import org.bukkit.Bukkit;
    import org.bukkit.Sound;
    import org.bukkit.entity.Player;
    import org.bukkit.scheduler.BukkitRunnable;

    public class StartingTask extends BukkitRunnable {

        private int timer = 15;

        private Bingo main;
        public StartingTask(Bingo main){this.main = main;}

        @Override
        public void run() {

            for(Player pls : Bukkit.getOnlinePlayers()){

                if(timer == 15 || timer == 10 || timer == 5 || timer == 4 || timer == 3 || timer == 2 || timer == 1){

                    main.getTitle().send(pls, 1, 1, 1, "§eDébut dans la partie dans", "§e" + timer + " secondes");
                    pls.playSound(pls.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 3, 3);

                } else if(timer == 0){

                    cancel();

                }

                timer--;

            }


        }

    }
     
     
  2. could you please send the stack trace?
     
  3. Oh yes sorry I forgot,
    Code (Text):
    org.bukkit.command.CommandException: Unhandled exception executing command 'bingo' in plugin Bingo v1.0
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:47) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:149) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at org.bukkit.craftbukkit.v1_16_R3.CraftServer.dispatchCommand(CraftServer.java:763) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at net.minecraft.server.v1_16_R3.PlayerConnection.handleCommand(PlayerConnection.java:1788) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at net.minecraft.server.v1_16_R3.PlayerConnection.c(PlayerConnection.java:1631) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at net.minecraft.server.v1_16_R3.PlayerConnection.a(PlayerConnection.java:1584) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at net.minecraft.server.v1_16_R3.PacketPlayInChat.a(PacketPlayInChat.java:47) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at net.minecraft.server.v1_16_R3.PacketPlayInChat.a(PacketPlayInChat.java:1) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at net.minecraft.server.v1_16_R3.PlayerConnectionUtils.lambda$0(PlayerConnectionUtils.java:19) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at net.minecraft.server.v1_16_R3.TickTask.run(SourceFile:18) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at net.minecraft.server.v1_16_R3.IAsyncTaskHandler.executeTask(SourceFile:144) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at net.minecraft.server.v1_16_R3.IAsyncTaskHandlerReentrant.executeTask(SourceFile:23) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at net.minecraft.server.v1_16_R3.IAsyncTaskHandler.executeNext(SourceFile:118) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at net.minecraft.server.v1_16_R3.MinecraftServer.bb(MinecraftServer.java:942) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at net.minecraft.server.v1_16_R3.MinecraftServer.executeNext(MinecraftServer.java:935) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at net.minecraft.server.v1_16_R3.IAsyncTaskHandler.awaitTasks(SourceFile:127) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at net.minecraft.server.v1_16_R3.MinecraftServer.sleepForTick(MinecraftServer.java:919) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at net.minecraft.server.v1_16_R3.MinecraftServer.w(MinecraftServer.java:851) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at net.minecraft.server.v1_16_R3.MinecraftServer.lambda$0(MinecraftServer.java:164) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        at java.lang.Thread.run(Thread.java:834) [?:?]
    Caused by: java.lang.NullPointerException
        at fr.falkanox.bingo.commands.BingoCommands.onCommand(BingoCommands.java:45) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[spigot-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
        ... 19 more
     
  4. Which line is number 45 in your BingoCommands class?
     
  5. main.getStartingTask().run();
     
  6. There’s some code missing Im guessing? Where is getStartingTask()? Its value is null
     
  7. getStartingTask() is in my main class :
    Code (Text):
    package fr.falkanox.bingo;

    import dev.jcsoftware.jscoreboards.JPerPlayerMethodBasedScoreboard;
    import dev.jcsoftware.jscoreboards.JScoreboardTeam;
    import fr.falkanox.bingo.inventorys.TeamInventory;
    import fr.falkanox.bingo.registers.RegisterCommands;
    import fr.falkanox.bingo.registers.RegisterEvents;
    import fr.falkanox.bingo.states.GState;
    import fr.falkanox.bingo.tasks.StartingTask;
    import fr.falkanox.bingo.teams.BlueTeam;
    import fr.falkanox.bingo.teams.NoTeam;
    import fr.falkanox.bingo.teams.RedTeam;
    import fr.falkanox.bingo.utils.Title;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;

    public class Bingo extends JavaPlugin {

        private RegisterEvents rv = new RegisterEvents(this);
        private RegisterCommands rm = new RegisterCommands(this);

        private GState state;
        private Title title;
        private StartingTask startingTask;

        public JScoreboardTeam blueTeam;
        public JScoreboardTeam redTeam;
        public JScoreboardTeam noTeam;
        private NoTeam noTeamClass;
        private RedTeam redTeamClass;
        private BlueTeam blueTeamClass;
        private final JPerPlayerMethodBasedScoreboard scoreboard = new JPerPlayerMethodBasedScoreboard();

        private String prefix = "§7[§eBingo§7] §e";
        private String error = "§7[§eBingo§7] §c";

        public TeamInventory teamInventory = new TeamInventory(scoreboard);

        public void onEnable(){

            getServer().getWorld("world").setTime(1000);
            getServer().getWorld("world").setStorm(false);

            rv.registerEvents();
            rm.registerCommands();

            setState(GState.WAITING);

            getServer().getLogger().info("[Bingo] Plugin actif !");

            noTeamClass = new NoTeam(scoreboard, this);
            redTeamClass = new RedTeam(scoreboard, this);
            blueTeamClass = new BlueTeam(scoreboard, this);

            blueTeam = scoreboard.createTeam("Bleue", "§bBleue ", ChatColor.AQUA);
            redTeam = scoreboard.createTeam("Rouge", "§cRouge ", ChatColor.RED);
            noTeam = scoreboard.createTeam("Neutre", "§7", ChatColor.GRAY);

        }

        public void onDisable(){

            getServer().getLogger().info("[Bingo] Plugin inactif !");

        }

        public void setState(GState state) {
            this.state = state;
        }

        public boolean isState(GState state){
            return this.state == state;
        }

        public JPerPlayerMethodBasedScoreboard getScoreboard() {
            return scoreboard;
        }

        public String getPrefix() {
            return prefix;
        }

        public String getError() {
            return error;
        }

        public Title getTitle() {
            return title;
        }

        public StartingTask getStartingTask() {
            return startingTask;
        }
    }
     
     
  8. Looks like you never initialize startingTask
     
  9. Ok thank you it works !
     
    • Like Like x 1