Solved Commands Don't Work

Discussion in 'Plugin Development' started by Higgsboson728, Oct 20, 2015.

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

    Higgsboson728

    I just started coding my own plugins and the commands I implemented don't seem to work.


    Console error:

    1. 21.10 05:35:48 [Multicraft] Skipped 22 lines due to rate limit (30/s)
    2. 21.10 05:35:44 [Server] INFO at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333) [craftbukkit-BT45_1.8.8_09.9.jar:git-Bukkit-9cd1111]
    3. 21.10 05:35:44 [Server] INFO at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:163) [craftbukkit-BT45_1.8.8_09.9.jar:git-Bukkit-9cd1111]
    4. 21.10 05:35:44 [Server] INFO at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319) [craftbukkit-BT45_1.8.8_09.9.jar:git-Bukkit-9cd1111]
    5. 21.10 05:35:44 [Server] INFO at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333) [craftbukkit-BT45_1.8.8_09.9.jar:git-Bukkit-9cd1111]
    6. 21.10 05:35:44 [Server] INFO at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:163) [craftbukkit-BT45_1.8.8_09.9.jar:git-Bukkit-9cd1111]
    7. 21.10 05:35:44 [Server] INFO at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319) [craftbukkit-BT45_1.8.8_09.9.jar:git-Bukkit-9cd1111]
    8. 21.10 05:35:44 [Server] INFO at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333) [craftbukkit-BT45_1.8.8_09.9.jar:git-Bukkit-9cd1111]
    9. 21.10 05:35:44 [Server] INFO at com.comphenix.protocol.injector.netty.ChannelInjector$4.channelRead(ChannelInjector.java:258) [ProtocolLib-3.6.3-SNAPSHOT.jar:?]
    10. 21.10 05:35:44 [Server] INFO at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319) [craftbukkit-BT45_1.8.8_09.9.jar:git-Bukkit-9cd1111]
    11. 21.10 05:35:44 [Server] INFO at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333) [craftbukkit-BT45_1.8.8_09.9.jar:git-Bukkit-9cd1111]
    12. 21.10 05:35:44 [Server] INFO at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:163) [craftbukkit-BT45_1.8.8_09.9.jar:git-Bukkit-9cd1111]
    13. 21.10 05:35:44 [Server] INFO at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319) [craftbukkit-BT45_1.8.8_09.9.jar:git-Bukkit-9cd1111]
    14. 21.10 05:35:44 [Server] INFO at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333) [craftbukkit-BT45_1.8.8_09.9.jar:git-Bukkit-9cd1111]
    15. 21.10 05:35:44 [Server] INFO at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:168) [craftbukkit-BT45_1.8.8_09.9.jar:git-Bukkit-9cd1111]
    16. 21.10 05:35:44 [Server] INFO at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:319) [craftbukkit-BT45_1.8.8_09.9.jar:git-Bukkit-9cd1111]
    17. 21.10 05:35:44 [Server] INFO at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:333) [craftbukkit-BT45_1.8.8_09.9.jar:git-Bukkit-9cd1111]
    18. 21.10 05:35:44 [Server] INFO at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) [craftbukkit-BT45_1.8.8_09.9.jar:git-Bukkit-9cd1111]
    19. 21.10 05:35:44 [Server] INFO at net.minecraft.server.v1_8_R3.NetworkManager.channelRead0(NetworkManager.java:1) [craftbukkit-BT45_1.8.8_09.9.jar:git-Bukkit-9cd1111]
    20. 21.10 05:35:44 [Server] INFO at net.minecraft.server.v1_8_R3.NetworkManager.channelRead0(NetworkManager.java:312) [craftbukkit-BT45_1.8.8_09.9.jar:git-Bukkit-9cd1111]
    21. 21.10 05:35:44 [Server] INFO at net.minecraft.server.v1_8_R3.NetworkManager.a(NetworkManager.java:115) [craftbukkit-BT45_1.8.8_09.9.jar:git-Bukkit-9cd1111]
    22. 21.10 05:35:44 [Server] INFO at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(SourceFile:9) [craftbukkit-BT45_1.8.8_09.9.jar:git-Bukkit-9cd1111]
    23. 21.10 05:35:44 [Server] INFO at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(SourceFile:37) [craftbukkit-BT45_1.8.8_09.9.jar:git-Bukkit-9cd1111]
    24. 21.10 05:35:44 [Server] INFO at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:980) [craftbukkit-BT45_1.8.8_09.9.jar:git-Bukkit-9cd1111]
    25. 21.10 05:35:44 [Server] INFO at net.minecraft.server.v1_8_R3.PlayerConnection.chat(PlayerConnection.java:1031) [craftbukkit-BT45_1.8.8_09.9.jar:git-Bukkit-9cd1111]
    26. 21.10 05:35:44 [Server] INFO at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:483) [craftbukkit-BT45_1.8.8_09.9.jar:git-Bukkit-9cd1111]
    27. 21.10 05:35:44 [Server] INFO at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:501) [craftbukkit-BT45_1.8.8_09.9.jar:git-Bukkit-9cd1111]
    28. 21.10 05:35:44 [Server] INFO at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit-BT45_1.8.8_09.9.jar:git-Bukkit-9cd1111]
    29. 21.10 05:35:44 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[craftbukkit-BT45_1.8.8_09.9.jar:git-Bukkit-9cd1111]
    30. 21.10 05:35:44 [Server] INFO org.bukkit.event.EventException


    This only happens when I add an argument to my command.

    Code:

    Code:
    package higgsboson728.bukkit.org;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffectType;
    
    public class MainClass extends JavaPlugin {
        @Override
        public void onEnable() {
            getLogger().info("This plugin is running version 1.0.0.");
           
        }
        @Override
        public void onDisable() {
            getLogger().info("Disabled.");
        }
       
        public boolean pluginHelp(CommandSender sender, Command cmd, String label, String[] args) {
            if (cmd.getName().equalsIgnoreCase("iCommands+") || cmd.getName().equalsIgnoreCase("Ic")) {
                sender.sendMessage(ChatColor.GOLD.BOLD.STRIKETHROUGH + "=================================");
                sender.sendMessage(ChatColor.YELLOW + "Plugin Info:");
                sender.sendMessage(ChatColor.YELLOW + "Author: Higgsboson728");
                sender.sendMessage(ChatColor.YELLOW + "Version: 1.0.0");
                sender.sendMessage(ChatColor.GREEN + "Commands:");
                sender.sendMessage(ChatColor.GREEN + "/setfire <Player> <Duration>");
                sender.sendMessage(ChatColor.GREEN + "/strike <Player>");
                sender.sendMessage(ChatColor.GREEN + "/execute <Player>");
                sender.sendMessage(ChatColor.GREEN + "/freeze <Player> <Duration>");
                sender.sendMessage(ChatColor.WHITE.ITALIC + "More commands coming soon!");
                sender.sendMessage(ChatColor.GOLD.BOLD.STRIKETHROUGH + "=================================");
               
               
                return true;
            }
            return false;
        }
       
       
        public boolean setfire(CommandSender sender, Command cmd, String label, String[] args) {
            if (cmd.getName().equalsIgnoreCase("setfire") && sender.hasPermission("icommands.setfire")) {
                if (args.length != 2) {
                    sender.sendMessage(ChatColor.RED + "Usage: /setfire <Player> <Duration>");
                    return false;
                }
               
                if (!(sender instanceof Player)) {
                    sender.sendMessage(ChatColor.RED + "This command is not supported for the console.");
                    return true;
                   
                }
               
                @SuppressWarnings("deprecation")
                Player target = Bukkit.getServer().getPlayerExact(args[0]);
                if (target == null) {
                    sender.sendMessage(ChatColor.RED + args[0] + " is offline or does not exist.");
                    return true;
                }
                int ticks = Integer.parseInt(args[1]);
                target.setFireTicks(ticks);
                return true;
            }
            return false;
        }
       
        public boolean strike(CommandSender sender, Command cmd, String label, String[] args) {
            if (cmd.getName().equalsIgnoreCase("Strike") && sender.hasPermission("icommands.strike")) {
                if (args.length != 1) {
                    sender.sendMessage(ChatColor.RED + "Usage: /strike <Player>");
                    return false;
                }   
               
                if (!(sender instanceof Player)) {
                    sender.sendMessage(ChatColor.RED + "This command is not supported for the console.");
                    return true;
                }
               
                @SuppressWarnings("deprecation")
                Player strikeTarget = Bukkit.getServer().getPlayerExact(args[0]);
                if (strikeTarget == null) {
                    sender.sendMessage(ChatColor.RED + args[0] + " is offline or does not exist.");
                    return true;
               
            }
                strikeTarget.getWorld().strikeLightning(strikeTarget.getLocation());
                       
        }
            return false;
    }
       
        public boolean execute(CommandSender sender, Command cmd, String label, String[] args) {
            if (cmd.getName().equalsIgnoreCase("Execute") && sender.hasPermission("icommands.execute")) {
                if (args.length != 1) {
                    sender.sendMessage(ChatColor.RED + "Usage: /execute <Player>");
                    return false;
                }
               
                if (!(sender instanceof Player)) {
                    sender.sendMessage(ChatColor.RED + "This command is not supported from the console.");
                    return true;
                }
               
                @SuppressWarnings("deprecation")
                Player executeTarget = Bukkit.getServer().getPlayerExact(args[0]);
                if (executeTarget == null) {
                    sender.sendMessage(ChatColor.RED + args[0] + " is offline or does not exist.");
                    return true;
                }
               
                executeTarget.setHealth(0.0D);
           
               
            }
            return false;
        }
       
        public boolean freeze(CommandSender sender, Command cmd, String label, String[] args) {
            if (cmd.getName().equalsIgnoreCase("Freeze") && sender.hasPermission("icommands.freeze")) {
                if (args.length != 2) {
                    sender.sendMessage(ChatColor.RED + "Usage: /freeze <Player> <Duration>");
                    return false;
                }
               
                if (!(sender instanceof Player)) {
                    sender.sendMessage(ChatColor.RED + "This command is not supported from the console.");
                    return true;
                }
               
                @SuppressWarnings("deprecation")
                Player freezeTarget = Bukkit.getServer().getPlayerExact(args[0]);
                if (freezeTarget == null) {
                    sender.sendMessage(ChatColor.RED + args[0] + " is offline or does not exist");
                    return true;
                }
               
                PotionEffectType effect = PotionEffectType.SLOW;
                int slowDuration = Integer.parseInt(args[1]);
                freezeTarget.addPotionEffect(effect.createEffect(slowDuration, 125));
               
            }
            return false;
        }
       
    }
    
     
  2. Offline

    Scimiguy

    @Higgsboson728
    Why didn't you put your error in codetags when you clearly know how to use them?

    Also, change your package name. You do not own the bukkit.org domain.
    And name your Main class something less generic

    thirdly, your error doesn't even show the actual error -- due to the "lines skipped due to rate limit" thing
     
  3. Offline

    matcracker

    Why you create more functions for each commands? You should create only a function that manage more commands.
     
  4. Offline

    Higgsboson728

    @matcracker
    So do I need to rewrite the entire thing?
     
  5. Offline

    mcdorli

    Read my signature.

    Please post the error again, and in the code tags or on pastebin.com, so it's more readable.

    *a real big facepalm* Did you ever learn java? You overwrite the onCommand method, you can't just name it as you want. None of them gets fired after a command. You didn't even implement (or extend, I don't know) the commandExecutor interface. Learn this a bit more.

    And you don't need to send the player a usage message. That's why the "usage" section in the plugin.yml exists.
     
    Last edited: Oct 20, 2015
  6. Offline

    Higgsboson728

  7. Offline

    teej107

    You don't need to implement CommandExecutor because JavaPlugin already does.

    @Higgsboson728 I don't know where to start so I'll just start here:
    1. https://docs.oracle.com/javase/tutorial/java/IandI/override.html
    2. http://wiki.bukkit.org/Plugin_Tutorial#Commands
     
  8. Offline

    Higgsboson728

  9. Offline

    mcdorli

    Please, disable multicraft, and recreate the problem. It hides the essential part of the error.
     
  10. Offline

    Higgsboson728

    How do I do that? @mcdorli
    (Sorry for being a noob)
     
  11. Online

    timtower Administrator Administrator Moderator

    @Higgsboson728 Local test server, or get the content of the latest.log
     
  12. Offline

    mcdorli

    Delete it or move it from the plugins folder
     
  13. Online

    timtower Administrator Administrator Moderator

    Multicraft is slightly more than a plugin though as it is the new console, the rate limit is also just in that console, not in the regular server logs.
     
  14. Offline

    mcdorli

    Yes, it's a hosting, you peobably can't delete that. Please post then the text from the log.txt file. @Higgsboson728
     
  15. Offline

    Higgsboson728

    This is the only thing that is said about my plugin in the console:

    [15:43:00] [Server thread/INFO]: [iCommands] Enabling iCommands v1.0.0
    [15:43:00] [Server thread/INFO]: [iCommands] This plugin is running version 1.0.0

    For example when I do /freeze higgsboson728 500

    I just get this:

    /freeze <Player> <Duration>

    Same for all commands :/ @timtower @mcdorli
     
  16. Offline

    mcdorli

    Because you never made an onCommandmethod.
     
  17. Offline

    Higgsboson728

    I've been told that I only need one public boolean.
    So the boolean needs to be

    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {

    }

    @mcdorli
     
  18. Online

    timtower Administrator Administrator Moderator

    Yes, and you need to do something in it.
     
  19. Offline

    Higgsboson728

  20. @Higgsboson728
    You have a bunch of commands but they aren't called onCommand. Bukkit runs the onCommand method when that command is done, it won't detect all them other methods,
     
  21. Offline

    Higgsboson728

    So literally only the first command will work,

    @bwfcwalshy

    EDIT: I mean none of the commands will work since they are all not called by the onCommand() method
     
  22. @Higgsboson728 Correct, you need to merge them into one method or seperate classes or however you want to do it.
     
    mcdorli likes this.
  23. Offline

    Higgsboson728

    @bwfcwalshy
    @timtower

    Edit:

    So do I just put all the "if" statements in the main boolean? If so, how do I do that? Do I just copy and paste everything inside the boolean? Because when I tried that it created a big mess
     
    Last edited: Oct 21, 2015
  24. Offline

    mcdorli

    It isn't a boolean, it jusf returns one. But yes, pretty much that. Please mark the thread solved if solved.
     
  25. Offline

    Higgsboson728

    @mcdorli I didn't mark it solved because it wasn't. Now it is
     
Thread Status:
Not open for further replies.

Share This Page