Need Help! Fly Errors!

Discussion in 'Plugin Development' started by Chibbey, Dec 23, 2013.

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

    Chibbey

    Hello, ok so I am trying to make a heal plugin that lets donators fly in the hub. But it works it just sends too many messages and errors so if you could help me. Heres my code.

    Code:java
    1. package me.chibbey.fly;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.command.Command;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9.  
    10. public class Fly extends JavaPlugin {
    11.  
    12. public void onEnable() {
    13. Bukkit.getServer().getLogger().info("Fly Plugin Has Been Enabled!");
    14. }
    15.  
    16. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    17.  
    18. if (!(sender instanceof Player)) {
    19. sender.sendMessage(ChatColor.RED + "Only players may fly! Sorry!");
    20. return true;
    21. }
    22. Player p = (Player) sender;
    23.  
    24. if (label.equalsIgnoreCase("fly")) {
    25. p.sendMessage(ChatColor.GREEN + "/fly on - Turn fly mode on!");
    26. p.sendMessage(ChatColor.GREEN + "/fly off - Turn fly mode off!");
    27. }
    28. if (args[0].equalsIgnoreCase("on")) {
    29. p.setAllowFlight(true);
    30. return true;
    31. }
    32. if (args[0].equalsIgnoreCase("off")) {
    33. p.setAllowFlight(false);
    34. return true;
    35. }
    36. return true;
    37. }
    38. }

    What happens is when people type /fly it sends them the messages then one extra message in red saying "An internal error occurred while attempting to perform this command" . And in the console it says
    Code:general
    1. [SEVERE] null
    2. org.bukkit.command.CommandException: Unhandled exception executing command 'fly' in plugin Fly v1.0
    3. at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
    4. at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:192)
    5. at org.bukkit.craftbukkit.v1_6_R3.CraftServer.dispatchCommand(CraftServer.java:532)
    6. at net.minecraft.server.v1_6_R3.PlayerConnection.handleCommand(PlayerConnection.java:986)
    7. at net.minecraft.server.v1_6_R3.PlayerConnection.chat(PlayerConnection.java:897)
    8. at net.minecraft.server.v1_6_R3.PlayerConnection.a(PlayerConnection.java:838)
    9. at net.minecraft.server.v1_6_R3.Packet3Chat.handle(Packet3Chat.java:47)
    10. at org.spigotmc.netty.NettyNetworkManager.b(NettyNetworkManager.java:237)
    11. at net.minecraft.server.v1_6_R3.PlayerConnection.e(PlayerConnection.java:117)
    12. at net.minecraft.server.v1_6_R3.ServerConnection.b(SourceFile:37)
    13. at org.spigotmc.netty.NettyServerConnection.b(NettyServerConnection.java:131)
    14. at net.minecraft.server.v1_6_R3.MinecraftServer.t(MinecraftServer.java:604)
    15. at net.minecraft.server.v1_6_R3.DedicatedServer.t(DedicatedServer.java:240)
    16. at net.minecraft.server.v1_6_R3.MinecraftServer.s(MinecraftServer.java:493)
    17. at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java:425)
    18. at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:583)
    19. Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
    20. at me.chibbey.fly.Fly.onCommand(Fly.java:31)
    21. at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
    22. ... 15 more

    PLEASE HELP ME! also one more problem is when I type /fly on|off it will send them the same messages as if you were typing /fly but not the internal error just the two specified one but it does allow me to fly but im guessing if I fix the /fly one that will fix.
     
  2. Offline

    thepaperboy99

    You have if(label.equalsIgnoreCase(..){

    When it should be if(cmd.equalsIgnoreCase(..){
     
  3. Offline

    Chibbey

    thepaperboy99
    Lol, no it would have to be if(cmd.getName().equalsIgnoreCase(..){
    and its label because if you look at the public Boolean onCommand it says String label, not commandLabel, so I would use label.equals but anyways that isn't a problem I use label for most my plugins and don't have issues.
     
  4. Offline

    Developing

    Chibbey thepaperboy99 The proper usage is
    Code:
    if(cmd.getName().equalsIgnoreCase("")){
    Also , the plugin failed to get the argument in the args list at position 0. That means there isnt actually an argument provided. You should always use if checks to check the length of the arguments before you assume there is such an argument.
    Code:
    if(args.length == 1){
    if (args[0].equalsIgnoreCase("on")) {
                    p.setAllowFlight(true);
                    return true;
                    }
                    if (args[0].equalsIgnoreCase("off")) {
                        p.setAllowFlight(false);
                        return true;
                    }
     
    }
     
  5. Offline

    Chibbey

    Developing
    Thank you that helped but now could you help me when I type /fly on|off it sends the messages as if you were typing /fly itself. so when u type /fly on it will turn on flight and send messages "/fly on - Turn fly mode on!" and "/fly off - Turn fly mode off!"
     
  6. Offline

    Developing

    Chibbey You mean using /fly as a toggle to on or off?
     
Thread Status:
Not open for further replies.

Share This Page