Problem with commands

Discussion in 'Plugin Development' started by jekeke123, Aug 5, 2014.

Thread Status:
Not open for further replies.
  1. Hello everyone,

    I'm having a problem with my commands it gives an error instead of the help:
    code:
    Code:
    if (cmd.getName().equalsIgnoreCase("PandoraNews")){
            Player player = (Player) sender; 
                    if (args[0].equalsIgnoreCase("Update")) {
                        if (player.hasPermission("PandoraNews.Update")) {
                            String NewNews = (String) getFinalArg(args, 1);
                            NewNews = NewNews.replace("&" ,"§");
                            if (PandoraNews.UpdateNews(plugin, NewNews) == true) {
                                player.sendMessage("News changed to:" + NewNews);
                            } else {
                                player.sendMessage("Failed to Update the news please try again or update it on the website's admin panel");
                            }
                            return true;
                        } else {
                            player.sendMessage("You are not allowed to execute this command!");
                            return false;
                        }
                    } else {
                        player.sendMessage("§c**********Pandora News Help***********");
                        player.sendMessage("§2/PandoraNews Update to update the news");
                    }
            }
            return false;
    Kind Regards,
    Jasper,
     
  2. Offline

    mine-care

    be sure to do a if sender instanceof player first: Player player = (Player) sender;
    Can we see the error?
     
  3. Offline

    bombom3000

    jekeke123 Please post the stacktrace as mine-care said. How have you defined the word 'plugin' in there please post the whole class and are you using multiple class files? If so then please post your main class's code too as there could be an error there.

    Thanks, Charlie
     
  4. Offline

    mine-care

    Also check your plugin.yml some errors are there by tabs instead of spaced and misstypes in the commands list. Plus what bombom3000 said <3
     
  5. mine-care bombom3000 The code is just working fine except if i use /PandoraNews then it gives error.
    Normally the staff should only use /pandoranews update <message>
    And /PandoraNews should display the help but it just gives error null :/
    plugin.yml:
    Code:
    name: PandoraNews
    main: jasper.PandoraNews
    version: 1.0.0
    description: This plugin is the official News plugin of the Pandora Network Made By Jasper
    authors: [Damaru2]
    website: https://github.com/MrDamaru
    commands:
      PandoraNews:
          description: The PandoraNews commands.
          usage: /PandoraNews
     
    permissions:
        PandoraNews.*:
            description: Gives access to all PandoraNews commands and events
            children:
                PandoraNews.Update: true
        PandoraNews.Update:
            description: Allows you to update the News
            default: op
    The stacktrace:
    Code:
    [15:23:55] [Server thread/ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'pandoranews' in plugin PandoraNews v1.0.0
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot.jar:git-Spigot-1591]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:181) ~[spigot.jar:git-Spigot-1591]
        at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchCommand(CraftServer.java:767) ~[spigot.jar:git-Spigot-1591]
        at net.minecraft.server.v1_7_R4.PlayerConnection.handleCommand(PlayerConnection.java:1013) [spigot.jar:git-Spigot-1591]
        at net.minecraft.server.v1_7_R4.PlayerConnection.a(PlayerConnection.java:850) [spigot.jar:git-Spigot-1591]
        at net.minecraft.server.v1_7_R4.PacketPlayInChat.a(PacketPlayInChat.java:28) [spigot.jar:git-Spigot-1591]
        at net.minecraft.server.v1_7_R4.PacketPlayInChat.handle(PacketPlayInChat.java:65) [spigot.jar:git-Spigot-1591]
        at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:184) [spigot.jar:git-Spigot-1591]
        at net.minecraft.server.v1_7_R4.ServerConnection.c(ServerConnection.java:81) [spigot.jar:git-Spigot-1591]
        at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:731) [spigot.jar:git-Spigot-1591]
        at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:289) [spigot.jar:git-Spigot-1591]
        at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:584) [spigot.jar:git-Spigot-1591]
        at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:490) [spigot.jar:git-Spigot-1591]
        at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [spigot.jar:git-Spigot-1591]
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
        at jasper.NewsCommandHandler.onCommand(NewsCommandHandler.java:32) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot.jar:git-Spigot-1591]
        ... 13 more
     
  6. Offline

    DannyDog

    jekeke123
    What is the error pointing to on line 32?
    Can you post that?
     
  7. DannyDog
    Code:
                    if (args[0].equalsIgnoreCase("Update")) {
     
  8. Offline

    Infuzion

    You're not checking if there is an args[0], Try:
    Code:java
    1. if(args.length > 0){
    2. //Code that checks args[0]
    3. }else{
    4. //Display Help
    5. }

    EDIT: Fixed Code
     
  9. Offline

    fireblast709

    jekeke123 before using an index, check if the array has that many elements. So when you use index 0, check if the array has at least 1 element.
    Infuzion broken code
     
  10. Offline

    Jade

    Locked. We do not support unofficial builds.
     
Thread Status:
Not open for further replies.

Share This Page