Wont let me add a command to the main class?

Discussion in 'Plugin Development' started by Niknea, Dec 26, 2013.

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

    Sagacious_Zed Bukkit Docs

    How does it not work? Are you getting a compile time error? Are you getting a runtime error? Or is it not executing the method you are expecting it to?
     
  2. Offline

    Niknea

    Sagacious_Zed
    When I type the command ingame, it just says it's an Unknown command
     
  3. Offline

    Sagacious_Zed Bukkit Docs

    Then the command is not declared in your plugin.yml
     
  4. Offline

    Niknea

    Sagacious_Zed
    Here is my plugin.yml
    Code:
    name: Enhanced Guns
    version: 1.0
    main: me.niknea.EnhancedGuns.Main
    description: Enhanced Guns!
     
    commands:
      ak47:
          description: This command gives you the Ak47!
      guns:
          description: This command displays a menu with all the guns!
      gdeagles:
          description: This command gives you the Golden Deagles!
     
    
    Nothing seems wrong with it.
     
  5. Offline

    Sagacious_Zed Bukkit Docs

    then you need to delete your jar and try again Niknea
     
  6. Offline

    Niknea

  7. Offline

    Sagacious_Zed Bukkit Docs

    No, delete the jar in your plugin folder, and export it from your development environment again.
     
  8. Offline

    Niknea

    Sagacious_Zed It still doesn't work :(

    Bump!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  9. Offline

    DrJava

    Niknea
    Put the setExecutor() back to the original command you had, but surround it in a try/catch statement. export it even if it gives an error and tell me the result in your onenable at startup.
     
  10. Offline

    Maulss

    Niknea
    Sorry for the late reply.

    Unfortunately if you have corrected all other mistakes that myself, Wehttam664 , Sagacious_Zed and AoH_Ruthless pointed out, there should be nothing wrong with it. I'm 90% positive that you're missing something. Please re-check everything and add some debugging code.
     
  11. Offline

    DrJava

    Niknea
    Please post your whole main class.
     
  12. Perhaps a bit off topic, but using inheritence might be usefull. A superclass weapon for example
     
  13. Offline

    Niknea

    DrJava Maulss Here is my whole main class
    Code:java
    1. package me.niknea.EnhancedGuns;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.event.Listener;
    5. import org.bukkit.plugin.Plugin;
    6. import org.bukkit.plugin.java.JavaPlugin;
    7.  
    8.  
    9. public class Main extends JavaPlugin
    10. {
    11.  
    12. private static Plugin plugin;
    13. @Override
    14. public void onEnable() {
    15. plugin = this;
    16. registerEvents(this, new Ak47(), new myCustomInventory(), new Deagles());
    17. getCommand("ak47").setExecutor(new Ak47());
    18. getCommand("guns").setExecutor(new oMenu());
    19. getCommand("gdeagles").setExecutor(new GoldenGet());
    20. getLogger().info("Enabling Enhanced Guns! Created by Niknea.");
    21.  
    22. }
    23. @Override
    24. public void onDisable() {
    25. getLogger().info("Disabling Enhanced Guns! Created by Niknea.");
    26. }
    27.  
    28. //Much easier then registering events in 10 different methods
    29. public static void registerEvents(org.bukkit.plugin.Plugin plugin, Listener... listeners) {
    30. for (Listener listener : listeners) {
    31. Bukkit.getServer().getPluginManager().registerEvents(listener, plugin);
    32. }
    33. }
    34.  
    35. //To access the plugin variable from other classes
    36. public static Plugin getPlugin() {
    37. return plugin;
    38. }
    39.  
    40.  
    41.  
    42.  
    43. }
    44.  
    45.  
     
  14. Offline

    DrJava

     
Thread Status:
Not open for further replies.

Share This Page