Error report after command usage

Discussion in 'Plugin Development' started by Tejedu, Jul 22, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    Tejedu

    After issuing the command /mhstart for my Man Hunt plugin I get the following errors:
    EDIT: I should note that I can run this completely flawlessly on localhost, but when I gave it to my server admin to run we got these errors.

    Error Log
    Code:
    21.07 20:39:23 [Server] INFO ... 15 more
    21.07 20:39:23 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot_1.8.6_c5146ba-01930e2.jar:git-Spigot-c5146ba-01930e2]
    21.07 20:39:23 [Server] INFO at io.github.tejedu.manhunt.ManHunt.onCommand(ManHunt.java:55) ~[?:?]
    21.07 20:39:23 [Server] INFO at java.lang.Integer.parseInt(Unknown Source) ~[?:1.7.0_51]
    21.07 20:39:23 [Server] INFO at java.lang.Integer.parseInt(Unknown Source) ~[?:1.7.0_51]
    21.07 20:39:23 [Server] INFO at java.lang.NumberFormatException.forInputString(Unknown Source) ~[?:1.7.0_51]
    21.07 20:39:23 [Server] INFO Caused by: java.lang.NumberFormatException: For input string: "aeae"
    21.07 20:39:23 [Server] INFO at java.lang.Thread.run(Unknown Source) [?:1.7.0_51]
    21.07 20:39:23 [Server] INFO at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:560) [spigot_1.8.6_c5146ba-01930e2.jar:git-Spigot-c5146ba-01930e2]
    21.07 20:39:23 [Server] INFO at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:657) [spigot_1.8.6_c5146ba-01930e2.jar:git-Spigot-c5146ba-01930e2]
    21.07 20:39:23 [Server] INFO at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:367) [spigot_1.8.6_c5146ba-01930e2.jar:git-Spigot-c5146ba-01930e2]
    21.07 20:39:23 [Server] INFO at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:718) [spigot_1.8.6_c5146ba-01930e2.jar:git-Spigot-c5146ba-01930e2]
    21.07 20:39:23 [Server] INFO at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:60) [spigot_1.8.6_c5146ba-01930e2.jar:git-Spigot-c5146ba-01930e2]
    21.07 20:39:23 [Server] INFO at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.7.0_51]
    21.07 20:39:23 [Server] INFO at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.7.0_51]
    21.07 20:39:23 [Server] INFO at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [spigot_1.8.6_c5146ba-01930e2.jar:git-Spigot-c5146ba-01930e2]
    21.07 20:39:23 [Server] INFO at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot_1.8.6_c5146ba-01930e2.jar:git-Spigot-c5146ba-01930e2]
    21.07 20:39:23 [Server] INFO at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot_1.8.6_c5146ba-01930e2.jar:git-Spigot-c5146ba-01930e2]
    21.07 20:39:23 [Server] INFO at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:970) [spigot_1.8.6_c5146ba-01930e2.jar:git-Spigot-c5146ba-01930e2]
    21.07 20:39:23 [Server] INFO at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerConnection.java:1135) [spigot_1.8.6_c5146ba-01930e2.jar:git-Spigot-c5146ba-01930e2]
    21.07 20:39:23 [Server] INFO at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:646) ~[spigot_1.8.6_c5146ba-01930e2.jar:git-Spigot-c5146ba-01930e2]
    21.07 20:39:23 [Server] INFO at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot_1.8.6_c5146ba-01930e2.jar:git-Spigot-c5146ba-01930e2]
    21.07 20:39:23 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot_1.8.6_c5146ba-01930e2.jar:git-Spigot-c5146ba-01930e2]
    21.07 20:39:23 [Server] INFO org.bukkit.command.CommandException: Unhandled exception executing command 'mhstart' in plugin ManHunt v0.1
    Code
    Code:
    public class ManHunt extends JavaPlugin {
    ...
    @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (cmd.getName().equalsIgnoreCase("mhtarget")) {
                if (game != null)
                {
                sender.sendMessage("The target is" + ChatColor.LIGHT_PURPLE + ChatColor.ITALIC + game.it.getDisplayName() + ChatColor.RESET + "!");
                }
                else
                {
                    sender.sendMessage("There is no target.");
                }
                return true;
            }
            if (cmd.getName().equalsIgnoreCase("mhstart")) {
                if (sender instanceof Player)
                {
                    if (args.length == 0)
                    {
                        startGameAfterDelay(0);
                        return true;
                    }
                    else if (args.length == 1)
                    {
                        startGameAfterDelay(Integer.parseInt(args[0]));
                        return true;
                    }
                    return false;
                }
                return true;
            }
            return false;
        }
    
    (The /mhtarget command works.)

    plugin.yml commands
    Code:
    commands:
      mhtarget:
        description: Returns the target of the current round of ManHunt
        usage: "Usage: /mhtarget"
        permission: manhunt.basic
      mhstart:
        description: Starts the game after a delay
        usage: "Usage: /mhstart (instant) or /mhstart <seconds> (start after time)"
        permission: manhunt.admin
    My username is aeae.
    The command is supposed to start a game of Man Hunt in my plugin.
    If you need any more information I'll give it to you guys.
    Thanks for helping!
     
  2. Offline

    Zombie_Striker

  3. Offline

    Tejedu

    I appreciate that you put the effort into finding my bug, however the way you responded to me is very rude. You aren't obligated to debug my code, and if you were not planning on it, then you shouldn't have posted. What I see is that you found my issue, and took the time to tell me you weren't going to tell me what it is. I will be sure to read the page that you posted, and continue looking for my bug.

    Thanks.
     
  4. Offline

    Zombie_Striker

    @Tejedu
    But the thing is I can tell you what this basic bug is, but that will not teach you how to solve this problem. The mistake you made can be created two ways: A) You know what you're doing, You read your error message to find the line that is causing the error, but you're looking over it and not actually seeing/reading what each segment does, or B) You don't know/ are not looking at the debug message in order to find your problem.

    Either way, you are not doing the thing you should and you are currently asking for someone else to do your work. I'm sorry that you thought I was being rude, but this forum is supposed to be, and should be for bugs or errors that are not caused by a singe character on one line, as in this case.
     
  5. Offline

    Tejedu

    @Zombie_Striker
    I understand.

    I am definitely looking at my debug messages, and definitely looking at my code. When posting this I didn't have the intention to ask someone to do my work for me. The purpose of this forum is to help people solve their issues, there is no rule dictating how complex or non-complex that issue must be.

    I am confident in my code, which is why I was probably overlooking the error. By posting here, skeptical eyes can look over the code quickly to find it. If you are too busy to help people, you should consider another forum.

    As far as I know now, the Integer.parseInt() method is creating an error because of the possibility someone puts a non-integer in as args[0]. I will add a try/catch to solve this. If this is the case then this error was not caused by a single character on one line.

    If somehow you are going to respond to me again, please understand that I am looking over my error and trying to solve the problem myself. If you know of another problem in addition to mine that I have not yet found, please include that.
     
  6. Offline

    eyamaz

    As far as I'm concerned, if you are not going to post something helpful, don't post it at all. Your posts here are not helpful and are berating.

    I have to constantly remind people to do silly things like use .equals instead of ==.
     
  7. Offline

    567legodude

    @Tejedu Well I can actually be helpful.
    Your console tells you what the error is
    Code:
    INFO Caused by: java.lang.NumberFormatException: For input string: "aeae"
    And it is saying that you are getting a NumberFormatException when you use Integer.parseInt in your code.
    That is because you are running the command "/mhstart aeae" and you are trying to get a number from "aeae" and since that is not a number, that is why you are getting the error.

    EDIT: Sometimes what I like to do when an argument is number only, is to do
    String.replaceAll("[^0-9]", ""); and then check !(String.isEmpty())
     
    Last edited: Jul 22, 2015
  8. Offline

    Tejedu

    @567legodude
    Aha! The input string "aeae" makes sense now! It was not me issuing that command, my server admin put it in and thought that by putting my name in as the argument it would make me the next "target" for Man Hunt.

    Thanks for your useful input. I will definitely use the EDIT you made.
     
  9. Offline

    567legodude

    @Tejedu Just to explain what happens there. String.replaceAll("[^0-9]", ""); uses a regex that will remove anything that's not a number from the string, which means if it's not a number, it removes it. So after removing all the non-numbers, you just check .isEmpty(). If that's true, that means there are no numbers left, and that they didn't put in a number. Otherwise that means there is a number left and you can use that in the string.
     
Thread Status:
Not open for further replies.

Share This Page