Command failure.

Discussion in 'Plugin Development' started by Xemiru, Oct 18, 2012.

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

    Xemiru

    Java's been pissing me off lately. Here's the thing; It's giving me a stack trace without giving me the exact location of the error, only which line it's coming from. Said line relates to execution of another class, being a CommandExecutor. I've tried to work with what it's given me, but all attempts lead to the same outcome; the exact same trace.
    Show Spoiler
    [​IMG]

    • Command is in plugin.yml.
    • It has a description, usage, and permission variable.
    • It implements the CommandExecutor interface.
    • It uses files.
    • It only returns true.
    • To grab a player, it uses main.getServer().getPlayerExact(playername), main being a pinpoint to the main class.
    • The plugin uses vault.
    • For permissions, it uses cs.hasPermission instead of Vault's has() method.
    • Annotated by @Override.
    I'm listing because I do not want to put this code in cyberspace outside my computer.
    If you need more information; just ask.
     
  2. Offline

    Karl Marx

    Not to be obvious, but the problem is caused by the line mentioned in the trace. Something left of a "." is null, but we can't tell what or why without seeing the line. One simple technique for figuring out what is null is to break the line up into single statements. For example, turn something like:
    Code:
    Chunk chunk = getServer().getWorld("world").getChunk(0, 0);
    
    into this:
    Code:
    Server server = getServer();
    World world = server.getWorld("world");
    Chunk chunk = world.getChunk(0, 0);
    
    In the second version, there is only one object reference per line, so it should be real obvious where the NullPointerException is coming from. Once you solve the problem, you can switch back to the normal version. If that isn't enough for you to solve the error, however, you're going to have to post the line to get any help- nobody's going to steal your idea from a single line.
     
  3. Offline

    Xemiru

    getCommand("info").setExecutor(new cmdInfo(this));
    This is it.
    This tells me nothing.
    fml.
     
  4. Offline

    chaseoes

    It tells you everything - something is null on that line.

    The command (is it registered, proper yml?).
    The instance of cmdInfo?
    this?

    We can't help without seeing the full class.
     
  5. Offline

    Karl Marx

    No need to see the full class, it's all right there. As I mentioned before, a NPE is thrown when something to the left of a "." is null, and I only see one "." there, meaning that getCommand("info") must be it. Diging around a bit through the CraftBukkit source, I see that this is how it is supposed to behave - if the command has not already been registered by your plugin.

    You need to add the command definition to your plugin.yml, so that bukkit can register the command for you when the plugin loads. After that you can use getCommand() to set your new executor.

    Here's the reference to get you started:
    http://wiki.bukkit.org/Plugin_YAML

    EDIT: just re-read your initial post and noticed you say that you already have the command in there. If that is the case, then either you declared the command wrong, or there's more to that error than what you posted, and the exception is occurring somewhere in the cmdInfo constructor (it should be "CmdInfo", btw.) If you are certain that there isn't more to the stack trace, and you can't figure out what's wrong with your plugin.yml, post it here for review; as the error is certainly in that file. You might want to check your indentation too- bukkit is very picky about how many spaces you use / not using tabs.
     
  6. Offline

    Xemiru

    Code:
    name: BloxacurityTEST
    main: me.scarlet.bukkit.Bloxacurity.Bloxacurity
    version: 0.1
    author: Xemiru
    depend: [Vault]
    commands:
      bloxhelp:
        description: Lists all the possible commands from Bloxacurity.
        usage: /<command> [page]
        permission: bloxacurity.general.access
      info:
        description: View the information of a player.
        usage: /<command> [player]
        permission: bloxacurity.data.view.player
    permissions:
      bloxacurity.main.*:
        description: Gives access to ALL of Bloxacurity's normal commands.
        children:
          bloxacurity.general.access: true
          bloxacurity.data.view.player: true
        default: op
      bloxacurity.data.view.player:
        description: Allows the permission holder to view a player's data.
        default: op
      bloxacurity.general.access:
        description: Allows the permission holder to access all commands considered general.
        default: op
    Well.
    There's the yml.
    I've checked the file before this topic, there's nothing wrong that I can figure out. That means spaces/tab checks.
     
  7. Offline

    Karl Marx

    I'm not too familiar with yml, but that seems fine to me. Regardless, all signs point to it being the problem.

    Some ideas:
    Some of the symbols in your usage sections have special meaning in yml. Try simplifying those lines temporarily.
    In my own plugin.yml files, I use 4 spaces to indent; but I'm not sure if that matters.
    Is it possible that this file somehow isn't making it into your plugin? Unzip the plugin jar and open up the plugin.yml file in it to see if it matches.

    Also, if you comment out the lines related to the broken command, does your other command work?
     
Thread Status:
Not open for further replies.

Share This Page