Errors in console

Discussion in 'Spigot Plugin Development' started by SnappyCo, May 4, 2017.

  1. When someone uses one of my plugins commands but does not enter all of the arguments it returns "An internal error occurred while attempting to perform this command" in game for them and "org.bukkit.command.CommandException: Unhandled exception executing command..." followed by a lot more errors in console. I'm guessing this is a common error when a certain piece of code is not implemented. If you happen to know what code that is then i would be very thankful. I would simply like to msg the player something like "/donate <player> <amount>" so that they can redo the command properly. Thank you.
  2. Post the full error and the code, then we can tell you what the problem is exactly. You probably don't check the "args" variable's size, so you get a NullPointerException when you try to access the amount argument.
  3. I used

    if (args.length != 2) {
    sender.sendMessage(ChatColor.RED + "/donate <player> <amount>");

    else { (Do the rest of the code) }

    is there a problem with this?
    • Agree Agree x 1
  4. Gaxan


    else should be your error message.
    • Funny Funny x 1
  5. It says if args.length is not 2 then do the error since i WANT 2 args. The plugin works when there are 2 args but when there isnt. It drowns us in errors.
  6. Paste the console errors please. Also, add a return statement after your message when args.length != 2.
  7. Gaxan


    You should check for true then use else for your error. Using != is lazy coding and not recommended.

    Using != is only checking if they enter two args. What if they enter a two strings instead of a string and an integer? You have another error that you are not checking for. If you have the command execute on true, else can cover all errors.

    However we can't see the code block you are working with, so no one can be sure what exactly you are doing.

    Admittedly I'm not fluent in Java, but programmed in C# some years ago. Anyone is welcome to correct me.
    • Like Like x 1
  8. As @Gaxan said, using != isn't the best. Although it would usually get the job done, it's better to use greater than/less than if you're not comparing objects.