CommandException Issue

Discussion in 'Plugin Development' started by FrankTC, Jul 17, 2016.

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

    FrankTC

    I just created a plugin that enables donors to vote on weather and time, there were no errors showing up in my IDE (Eclipse), but when I try to run it on my plugin test server, it gives CommandException, and I can't figure out what its problem is.

    Here is my code:

    http://pastebin.com/dqKfcaZ4

    Here is the Exception:

    http://pastebin.com/fiKb4Vz3

    I do need to hurry, because I am doing this for VoxelMC, and it needs to be done quick.
     
  2. Offline

    thapengwin

    Check for args length before checking for the arg itself.
     
  3. Offline

    I Al Istannen

    @FrankTC
    Wrong section. Post it in "Plugin Development" and not in a subforum.

    Now, not trying to be mean or offensive, but trying to help.

    "if (args[1] == "weather") {"
    You need to check if the command has two arguments, before you get it. And remember, counting starts at 0, not 1.
    So in this case the user would need to write "/<command> args1 weather" for your command to work.
    If the user writes "/<command>" without two arguments, it will try to get the second one, but there is none ==> ArrayIndexOutOfBoundsException.
    Check if "args.length" is 2 or more before accessing the second element.

    Then, don't use "§" in your file, it can be screwed up between file encodings (unicode char) and may change in the future. Use ChatColor#<COLOR> or make a function using ChatColor#translateAlternateColorCodes('&', <String>) and use that and "&" as color char.

    "this.getConfig().addDefault("players", Arrays.asList(players));"
    Just use "Collections.<String> emtpyList()" instead of the list of an array. Or use "new ArrayList<String>()"

    Code:
    try {
        Thread.sleep(60000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    Don't sleep the main thread! (See the emphasis? xD) Use a Scheduler.

    I didn't look at the rest.

    But you should probably learn some more Java, the error is a quite basic one.
     
    bwfcwalshy and thapengwin like this.
  4. No idea what that server is and don't really care but you shouldn't be developing for others when you don't know how to actually use the API. Not being offensive I'm being truthful. As @I Al Istannen has pointed out your mistakes are basic Java mistakes and one will crash the entire server. Learn Java, then learn the API then once you know it well help other servers.
     
  5. Offline

    Firestar311

    @I Al Istannen There is nothing wrong with using § in your code, it is much easier to type then ChatColor.COLOR. And if it is changed, use use Find and Replace all.

    And sleeping the main thread is a VERY bad idea.

    Code:java
    1. this.getConfig().addDefault(type, "weather");
    2. this.getConfig().addDefault("sun", 0);
    3. this.getConfig().addDefault("rain", 0);
    4. this.getConfig().addDefault("players", Arrays.asList(players));

    These should belong in your onEnable method. Or you can supply a default config.yml in your Jar file and then you do not need your loadConfiguration method or these methods and just use
    Code:java
    1. saveDefaultConfig();

    In your onEnable() method

    I found this line, you should check with instanceof before casting sender to Player
    Code:java
    1. World w = ((Player) sender).getWorld();


    And above all, as it has been mentioned, check to see if the args.length is greater than or equal to the amount that you want.
     
  6. Ok, run a server with 30/40+ plugins and mc decide to change ChatColor, you going to edit every single plugin? I doubt it even though you are a developer. Most server owners are not developers and will not know how to decompile, edit and recompile plugins and they will not want to do that for 30/40 plugins just because someone didn't type a few more characters. Even using & and having ChatColor translate it to make it even easier on them.

    Changing the colour code would break every single plugin using the old hard coded one, look how many plugins are no longer developed but still work, and imagine them all broken just because they used the char.

    It isn't as simple as "Just use find and replace"
     
    I Al Istannen likes this.
Thread Status:
Not open for further replies.

Share This Page