Can somebody tell me what's wrong with this code?

Discussion in 'Plugin Development' started by Cystalize, Aug 6, 2012.

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

    Cystalize

    Code:
      public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        boolean op = false;
        if ((sender instanceof Player)) {
          Player player = (Player)sender;
          op = player.isOp();
        }
        if ((label.equalsIgnoreCase("spam")) &&
          ((op) || ((sender instanceof ConsoleCommandSender))) &&
          (args.length == 1) && (args[0].equalsIgnoreCase("reload"))) {
          load();
          reloadConfig();
          log.info("Spamicide:  Configuration reloaded");
          if (op) {
            sender.sendMessage(ChatColor.GREEN + "Spamicide:  Configuration reloaded");
          }
          return true;
     
  2. Offline

    WarmakerT

    What's the error?
    Edit.: You didn't close onCommand()
     
  3. Offline

    hawkfalcon

    Change label to cmd
     
    WarmakerT likes this.
  4. Offline

    Cystalize

    I didn't close it because I started a new body from it. I'm not sure what the error is. When I try to reload the plugin, it gives me error messages regarding a command. And this is the only command in this plugin soooo :3


    Heres the error it gives me:
    Code:
    >spam reload
    23:09:10 [SEVERE] org.bukkit.command.CommandException: Unhandled exception executing command 'spam' in plugin Spamicide v0.1
    23:09:10 [SEVERE]    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:42)
    23:09:10 [SEVERE]    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:168)
    23:09:10 [SEVERE]    at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:490)
    23:09:10 [SEVERE]    at org.bukkit.craftbukkit.CraftServer.dispatchServerCommand(CraftServer.java:486)
    23:09:10 [SEVERE]    at net.minecraft.server.DedicatedServer.ah(DedicatedServer.java:248)
    23:09:10 [SEVERE]    at net.minecraft.server.DedicatedServer.q(DedicatedServer.java:213)
    23:09:10 [SEVERE]    at net.minecraft.server.MinecraftServer.p(MinecraftServer.java:476)
    23:09:10 [SEVERE]    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:408)
    23:09:10 [SEVERE]    at net.minecraft.server.ThreadServerApplication.run(SourceFile:539)
    23:09:10 [SEVERE] Caused by: java.lang.NullPointerException
    23:09:10 [SEVERE]    at me.arsinia.spamicide.Spamicide.parseArray(Spamicide.java:51)
    23:09:10 [SEVERE]    at me.arsinia.spamicide.Spamicide.load(Spamicide.java:85)
    23:09:10 [SEVERE]    at me.arsinia.spamicide.Spamicide.onCommand(Spamicide.java:106)
    23:09:10 [SEVERE]    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:40)
    23:09:11 [SEVERE]    ... 8 more
    23:09:11 [SEVERE] Encountered an unexpected exception CommandException
    org.bukkit.command.CommandException: Unhandled exception executing command 'spam' in plugin Spamicide v0.1
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:42)
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:168)
        at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:490)
        at org.bukkit.craftbukkit.CraftServer.dispatchServerCommand(CraftServer.java:486)
        at net.minecraft.server.DedicatedServer.ah(DedicatedServer.java:248)
        at net.minecraft.server.DedicatedServer.q(DedicatedServer.java:213)
        at net.minecraft.server.MinecraftServer.p(MinecraftServer.java:476)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:408)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:539)
    Caused by: java.lang.NullPointerException
        at me.arsinia.spamicide.Spamicide.parseArray(Spamicide.java:51)
        at me.arsinia.spamicide.Spamicide.load(Spamicide.java:85)
        at me.arsinia.spamicide.Spamicide.onCommand(Spamicide.java:106)
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:40)
        ... 8 more
    
    That brought up this error message in Eclipse:

    'The method equalsIgnoreCase(String) is undefined for the type Command.'

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  5. Offline

    p1rat33r

    try this:

    Code:
    String name = cmd.getName();
    if(name.equalsIgnoreCase("spam"){
     //...
    }
    
     
  6. Offline

    NSArray

    Looking at your error log, your error isn't even in the code you pasted... It is found in your load() function on line 51 in Spamicide.java.
     
Thread Status:
Not open for further replies.

Share This Page