Solved Command args

Discussion in 'Plugin Help/Development/Requests' started by TheLovelySlothMan, May 25, 2015.

Thread Status:
Not open for further replies.
  1. I've been sort of having troubles with this.
    This base command works, but when I type the args it just create errors

    BountyCommand:
    Code:
    public boolean onCommand(CommandSender sender, Command command, String alias, String[] args) {
            Player p = (Player) sender;
            if (alias.equalsIgnoreCase("bounty")) {
                if (args.length == 0) {
                    p.sendMessage(StringUtil.eo + "Please specify instead of only typing bounty.");
                }
                else if (args.length == 1) {
                    Player target = Bukkit.getPlayer(args[1]);
                    if (!(target == null)) {
                    p.sendMessage(StringUtil.eo + "Please type how much money you want to set on " + target.getName());
                    }
                }
                else if (args.length == 2) {
                    double amount = Double.parseDouble(args[2]);
                    MoneyAPI money = MoneyAPI.getInstance();
                    double playermoney = money.getMoney(p);
                    if (!(playermoney >= amount)) {
                        p.sendMessage(StringUtil.eo + "You don't have enough money for that!");
                        return true;
                    }
                    Player target = Bukkit.getPlayer(args[1]);
                    p.sendMessage(StringUtil.eo + "You set a bounty on " + target.getName());
                    money.removeMoney(p, amount);
                   
                    target.sendMessage(StringUtil.eo + "A bounty of " + amount + " yang, has been set on you");
                   
                    FileConfiguration config = plugin.getConfig();
                    config.set(target.getName()+".Info.Bounty", amount);
                    plugin.saveConfig();
                   
                    if (amount > 10000) {
                        Bukkit.broadcastMessage(StringUtil.eo + "Holy, a bounty has been set on " + target.getName() + " with the value of " + amount + " Yang!");
                    }
                }
                else
                {
                    p.sendMessage("That's invalid");
                }
            }
            return false;
        }
    Error:
    Code:
    13:28:45 [javastacktrace]     at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot_server.jar:git-Spigot-c3c767f-33d5de3]
    13:28:45 [javastacktrace]     at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot_server.jar:git-Spigot-c3c767f-33d5de3]
    13:28:45 [javastacktrace]     at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCommand(CraftServer.java:646) ~[spigot_server.jar:git-Spigot-c3c767f-33d5de3]
    13:28:45 [javastacktrace]     at net.minecraft.server.v1_8_R1.PlayerConnection.handleCommand(PlayerConnection.java:1115) [spigot_server.jar:git-Spigot-c3c767f-33d5de3]
    13:28:45 [javastacktrace]     at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java:950) [spigot_server.jar:git-Spigot-c3c767f-33d5de3]
    13:28:45 [javastacktrace]     at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(PacketPlayInChat.java:26) [spigot_server.jar:git-Spigot-c3c767f-33d5de3]
    13:28:45 [javastacktrace]     at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(PacketPlayInChat.java:53) [spigot_server.jar:git-Spigot-c3c767f-33d5de3]
    13:28:45 [javastacktrace]     at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_40]
    13:28:45 [javastacktrace]     at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_40]
    13:28:45 [javastacktrace]     at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:696) [spigot_server.jar:git-Spigot-c3c767f-33d5de3]
    13:28:45 [javastacktrace]     at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:316) [spigot_server.jar:git-Spigot-c3c767f-33d5de3]
    13:28:45 [javastacktrace]     at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:634) [spigot_server.jar:git-Spigot-c3c767f-33d5de3]
    13:28:45 [javastacktrace]     at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:537) [spigot_server.jar:git-Spigot-c3c767f-33d5de3]
    13:28:45 [javastacktrace]     at java.lang.Thread.run(Unknown Source) [?:1.8.0_40]
    13:28:45 [javastacktrace] Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
    13:28:45 [javastacktrace]     at me.com.MunchMallow.Commands.BountyCommand.onCommand(BountyCommand.java:29) ~[?:?]
    13:28:45 [javastacktrace]     at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot_server.jar:git-Spigot-c3c767f-33d5de3]
    
     
  2. Offline

    bwfcwalshy Retired Staff

    Moved to alternates of Bukkit, Bukkit Alternates.
     
  3. Never mind, I fixed it! xD It was that damn Java odd count system lol
     
  4. Invisible

    nverdier

     
    TheLovelySlothMan likes this.
Thread Status:
Not open for further replies.

Share This Page