Unknown Command

Discussion in 'Plugin Development' started by Rmarmorstein, Nov 28, 2012.

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

    Rmarmorstein

    I am making a plugin to change the prefix of a player, using the command /prefix and it will execute the command via the console pex user <Player Sending command or cdsend> preifx &f[<color code or args[0]><prefix or args[1]>&f]

    I am getting the unknown command error. My YAML file does not have tabs and looks correct. Please take a look.

    Main:
    Code:java
    1. package us.rivertech.ezdonor;
    2.  
    3. import org.bukkit.plugin.PluginDescriptionFile;
    4. import org.bukkit.plugin.java.JavaPlugin;
    5.  
    6. public final class ezDonor extends JavaPlugin {
    7.  
    8. PluginDescriptionFile pdfile = getDescription();
    9.  
    10.  
    11.  
    12. @Override
    13. public void onEnable(){
    14.  
    15. getLogger().info("ezDonor Enabled @ Version" + pdfile.getVersion());
    16. getCommand("prefix").setExecutor(new PrefixCommandExecuter());
    17.  
    18. }
    19.  
    20. @Override
    21. public void onDisable(){
    22. getLogger().info("ezDonor Disabled");
    23.  
    24. }
    25.  
    26. }


    PrefixCommandExecurer class:

    Code:java
    1. package us.rivertech.ezdonor;
    2.  
    3.  
    4. import org.bukkit.Bukkit;
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandExecutor;
    8. import org.bukkit.command.CommandSender;
    9.  
    10. public class PrefixCommandExecuter implements CommandExecutor {
    11.  
    12. @Override
    13. public boolean onCommand(CommandSender cdsend, Command cmd, String label,
    14. String[] args) {
    15. if(cmd.getName().equalsIgnoreCase("prefix")) {
    16. if (args.length > 2)
    17. cdsend.sendMessage(ChatColor.RED + "Too Many Arguments!");
    18. if (args.length < 2)
    19. cdsend.sendMessage(ChatColor.RED + "Too Little Arguments!");
    20. if (cdsend.hasPermission("ezdonor.prefix"))
    21. Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(),"pex user " + cdsend + " prefix &f[" + args[0] + args[1] + "&f");
    22. cdsend.sendMessage(ChatColor.AQUA + "Your Prefix Has Been Changed To:" + args[1]);
    23.  
    24. return true;
    25.  
    26. }else{
    27. cdsend.sendMessage(ChatColor.RED + "There Was An Error. Please Contact the System Administrator");
    28. }
    29.  
    30. return false;
    31. }
    32.  
    33.  


    and My plugin.yml, which i checked for errors in notepad++
    Code:
    name: ezDonor
    main: us.rivertech.ezdonor.ezdonor
    version: 0.1
    commands:
      prefix:
          description: Change the Prefix
          usage: /prefix <color> <prefix>
          permission: ezdonor.prefix
          permission-message: You don't have ezdonor.prefix
    permissions:
        ezdonor.*:
            description: All ezDonor Commands
            children:
                ezdonor.prefix: true
        ezdonor.prefix:
            description: Allow Changing Prefix.
            default: op
    Any Help and suggestions are appreciated. i am getting the error on the server i am testing it on where the command is unknown.
     
  2. Offline

    V10lator

    Is this a double post or a different question? Also: What error?
    And double-check your plugin.yml. I only saw two spaces till now but you use two as well as four spaces.
     
  3. Offline

    Rmarmorstein

    This is a Different question. Not a double post. I am not That dumb to double post. haha I will try that now.

    New Plugin.yml... Still not working though

    Code:
    name: ezDonor
    main: us.rivertech.ezdonor.ezdonor
    version: 0.1
    commands:
      prefix:
        description: Change the Prefix
        usage: /prefix <color> <prefix>
        permission: ezdonor.prefix
        permission-message: You don't have ezdonor.prefix
    permissions:
      ezdonor.*:
        description: All ezDonor Commands
        children:
          ezdonor.prefix: true
      ezdonor.prefix:
        description: Allow Changing Prefix.
        default: op
     
  4. Offline

    NinjaW0lf

    @Rmamorstein
    Small Tip for future.
    Replace
    Code:java
    1.  
    2. cmd.getName().equalsIgnoreCase("prefix")
    3.  


    to
    Code:java
    1.  
    2. label.equalsIgnoreCase("prefix")
    3.  


    onCommand gets dispatched with the name included, might as well use it.

    As for the error, ill chekc over ur yml
     
  5. Offline

    V10lator

    An extension to what NinjaW0lf told: IIRC cmd.getName() will always return the commands name like written in the plugin.yml while the label is what the player wrote (so may be a alias, for example).
     
  6. Offline

    Rmarmorstein

    Ok. Changed it. Thanks for the Tip NinjaWolf :D any idea if there is a problem in the yaml, or the code rather?
     
  7. Offline

    V10lator

    Rmarmorstein (und Eisen bricht... just seeing that... xD) please add a System.out.print("Command executed"); right at the beginning (before the if!) of your onCommand method. Then look into the console while executing the command.
     
  8. Offline

    Rmarmorstein

    Nothing.....
     
  9. Offline

    V10lator

    Ehm... Do you have a NPE at this line?
    getLogger().info("ezDonor Enabled @ Version" + pdfile.getVersion());
    Cause you should have (pdfile should be null). This NPE should cause the code below (so the command registration) to fail. For testing please remove this line completely (you shouldn't need it anyway as bukkit prints out a similar line for you).
     
  10. Offline

    Rmarmorstein

    Arrg. This is Still Not working. I dont know what i could have Possibly done wrong to do it either.

    No, I did not make an NPE. I am still pretty new... So... But I removed that line, since bukkit does it.

    The Main File at the moment looks like:

    Code:java
    1. package us.rivertech.ezdonor;
    2.  
    3. import org.bukkit.plugin.PluginDescriptionFile;
    4. import org.bukkit.plugin.java.JavaPlugin;
    5.  
    6. public final class ezDonor extends JavaPlugin {
    7.  
    8. PluginDescriptionFile pdfile = getDescription();
    9.  
    10.  
    11.  
    12. @Override
    13. public void onEnable(){
    14.  
    15. getCommand("prefix").setExecutor(new PrefixCommandExecuter());
    16.  
    17. }
    18.  
    19. @Override
    20. public void onDisable(){
    21. getLogger().info("ezDonor Disabled");
    22.  
    23. }
    24.  
    25. }


    The Command Executor Class:
    Code:java
    1. package us.rivertech.ezdonor;
    2.  
    3. import org.bukkit.plugin.PluginDescriptionFile;
    4. import org.bukkit.plugin.java.JavaPlugin;
    5.  
    6. public final class ezDonor extends JavaPlugin {
    7.  
    8. PluginDescriptionFile pdfile = getDescription();
    9.  
    10.  
    11.  
    12. @Override
    13. public void onEnable(){
    14.  
    15. getCommand("prefix").setExecutor(new PrefixCommandExecuter());
    16.  
    17. }
    18.  
    19. @Override
    20. public void onDisable(){
    21. getLogger().info("ezDonor Disabled");
    22.  
    23. }
    24.  
    25. }


    And the Plugin.yml like this:

    Code:
    name: ezDonor
    main: us.rivertech.ezdonor.ezdonor
    version: 0.1
    commands:
      prefix:
        description: Change the Prefix
        usage: /prefix <color> <prefix>
        permission: ezdonor.prefix
        permission-message: You don't have ezdonor.prefix
    permissions:
      ezdonor.*:
        description: All ezDonor Commands
        children:
            ezdonor.prefix: true
      ezdonor.prefix:
        description: Allow Changing Prefix.
        default: op
     
  11. Offline

    NinjaW0lf

    Try That, i made all the spacing perfect(4 spaces). Not sure if it will make a diffrence. if it doesnt, see if removing the permission: ezdonor.prefix part fixes it.
    Code:
    name: ezDonor
    main: us.rivertech.ezdonor.ezdonor
    version: 0.1
    commands:
        prefix:
            description: Change the Prefix
            usage: /prefix <color> <prefix>
            permission: ezdonor.prefix
            permission-message: You don't have ezdonor.prefix
    permissions:
        ezdonor.*:
            description: All ezDonor Commands
            children:
                ezdonor.prefix: true
        ezdonor.prefix:
            description: Allow Changing Prefix.
            default: op
     
  12. Offline

    Rmarmorstein

    I just did /pl and it is NOT In the List. So therefore, it wont work anyway, correct?

    NinjaWolf i Tried it both ways to, and did a /pl for both ways.
     
  13. Offline

    NinjaW0lf

    is it loadign up in console?
     
  14. Offline

    Rmarmorstein

    No. It is not.
     
  15. Offline

    V10lator

    Check your console log, there should be either a message that it has been loaded and later on enabled (which doesn't seem to be the case, I'm guessing loading fails) or why it didn't.
     
  16. Offline

    Rmarmorstein

    Oh My Derp. How did i not think of that. Right at the Top i had....
    Code:
    2012-11-29 03:27:01 [SEVERE] Could not load 'plugins/ezdonor.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.ClassNotFoundException: us.rivertech.ezdonor.ezdonor
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:154)
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:305)
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:230)
        at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:227)
        at org.bukkit.craftbukkit.CraftServer.<init>(CraftServer.java:205)
        at net.minecraft.server.ServerConfigurationManagerAbstract.<init>(ServerConfigurationManagerAbstract.java:51)
        at net.minecraft.server.ServerConfigurationManager.<init>(SourceFile:11)
        at net.minecraft.server.DedicatedServer.init(DedicatedServer.java:111)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:398)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:856)
    Caused by: java.lang.ClassNotFoundException: us.rivertech.ezdonor.ezdonor
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:44)
        at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:29)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:143)
        ... 9 more
    I Kind Of Recognize what is going on...
    But i have no idea how to fix it...
     
  17. Offline

    V10lator

    Important part:
    ClassNotFoundException: us.rivertech.ezdonor.ezdonor
    If I check I see that your class is called ezDonor, so in your plugin.yml change the main: line to:
    main: us.rivertech.ezdonor.ezDonor
     
  18. Offline

    Rmarmorstein

    Java is Case Sensitive. Wow. Now i feel Dumb.

    Well, Now the plugin is loading, but half working. I can get the prints, but i am getting an error. It is Printing that the prefix has changed, but it is not changing the prefix. and it looks like the error is something to do with that.

    Error:
    Code:
    29.11 04:36:05 [Server] INFO ... 15 more
    29.11 04:36:05 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
    29.11 04:36:05 [Server] INFO at us.rivertech.ezdonor.PrefixCommandExecuter.onCommand(PrefixCommandExecuter.java:22)
    29.11 04:36:05 [Server] INFO Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
    29.11 04:36:05 [Server] INFO at net.minecraft.server.ThreadServerApplication.run(SourceFile:856)
    29.11 04:36:05 [Server] INFO at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:426)
    29.11 04:36:05 [Server] INFO at net.minecraft.server.MinecraftServer.q(MinecraftServer.java:493)
    29.11 04:36:05 [Server] INFO at net.minecraft.server.DedicatedServer.r(DedicatedServer.java:222)
    29.11 04:36:05 [Server] INFO at net.minecraft.server.MinecraftServer.r(MinecraftServer.java:595)
    29.11 04:36:05 [Server] INFO at net.minecraft.server.DedicatedServerConnection.b(SourceFile:30)
    29.11 04:36:05 [Server] INFO at net.minecraft.server.ServerConnection.b(SourceFile:39)
    29.11 04:36:05 [Server] INFO at net.minecraft.server.NetServerHandler.d(NetServerHandler.java:113)
    29.11 04:36:05 [Server] INFO at net.minecraft.server.NetworkManager.b(NetworkManager.java:290)
    29.11 04:36:05 [Server] INFO at net.minecraft.server.Packet3Chat.handle(Packet3Chat.java:44)
    29.11 04:36:05 [Server] INFO at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:858)
    29.11 04:36:05 [Server] INFO at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:903)
    29.11 04:36:05 [Server] INFO at net.minecraft.server.NetServerHandler.handleCommand(NetServerHandler.java:985)
    29.11 04:36:05 [Server] INFO at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:502)
    29.11 04:36:05 [Server] INFO at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:186)
    29.11 04:36:05 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
    29.11 04:36:05 [Server] INFO org.bukkit.command.CommandException: Unhandled exception executing command 'prefix' in plugin ezDonor v0.1
    29.11 04:36:05 [Server] SEVERE null
    29.11 04:36:05 [Server] INFO Command Executed
    I am also only getting this when i do the command without any args. And it is printing the Too Little Args! message
     
  19. Offline

    V10lator

    Can't map the line numbers atm but try adding a else before
    if (args.length < 2)
    as well as before
    if (cdsend.hasPermission("ezdonor.prefix"))
    also add a { after this if (the second one) and a } before return true.
     
  20. Offline

    Rmarmorstein

    Nope. The Prefix is still not changing. Is the Code right to execute the PermissionsEx command it does not need a slash right? also, would it be easier to go to the permissions.yml for pex and change the file directly, if so how would that be done?
     
  21. Offline

    V10lator

    But the error is gone? Else no need to check any future...
    Command looks good, yes. Do you get any reply at the console?
    Not sure if PEX will notice that changes without a reload, which you would have to trigger by command (or by hooking directly into PEX, which you could also do instead of sending the prefix command).
     
  22. Offline

    NinjaW0lf

    I reccomend hooking into Vault instead of Pex directly, allows your plugin to support other permission plugins. Otherwise waht V10 said.
     
Thread Status:
Not open for further replies.

Share This Page