Method not being called need help

Discussion in 'Plugin Development' started by aPandaification, Jun 13, 2012.

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

    aPandaification

    So the situation is this. In my main class(Panda) There is the onCommand and in there at the bottom it has this.enchant.execute(args); where enchant is the instance of the class and execute is the method. Yet when I get to the point I added a debug method to make sure I was getting there. And I was. But I was not executing the method correctly. I am not sure if there is a problem with my syntax or with the method if someone could tell me where I went dumb I would love you long time.

    Main(the issue is at the "oncommand" where it says I am here and I'm trying to call execute):http://pastebin.com/A8L3NA90

    Enchant Class: http://pastebin.com/jBYJ9cpX

    InvHelper class: http://pastebin.com/DP9rCTv4

    Util class: http://pastebin.com/jBQ5jEgS
     
  2. Offline

    Jogy34

    try adding debug statements in the execute method to see where it is going wrong
     
  3. Offline

    r0306

    aPandaification
    You have to create an instance of your class.
    Code:
    else
                  {
                  player.sendMessage(ChatColor.RED + "I am here.");
                  enchant = new Enchant();
                  this.enchant.execute(args);
                  }
     
  4. He has, see the variable declaration at the top of the class and the allocation in the onEnable.
     
  5. Offline

    aPandaification

    So other than the debug any other ideas?
     
  6. Offline

    r0306

    aPandaification
    Try adding the override annotation in front of the onCommand method.
     
  7. Offline

    aPandaification

    which override method

    anyone else have any ideas I really need this to work :/
    EDIT: tried the overide didnt work

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  8. Offline

    Sagacious_Zed Bukkit Docs

    Did you declare the command in your plugin.yml?
     
  9. Offline

    aPandaification

    yes

    Code:
    name: PandaTheEnchanter
    main: me.aPanda.PandaTheEnchanter.Panda
    version: 1.0
    Author: aPanda
    Website: http://fallencraft.com
     
    commands:
      ea:
          description: The main command.
          usage: |
          /ea
         
    permissions:
        PandaTheEnchanter.admin:
            default: op
            description: Gives access to all commands and abilities
            command: "/ea give <playername> <itemID> <package>"
            
    does anyone know why my execute method is not working correctly

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  10. Offline

    ZeusAllMighty11

    Did you register the event in the main class? (not the plugin.yml)
     
  11. Offline

    bartboy8

    @EventHandler
     
  12. Offline

    aPandaification

    Sorry new to this but by registering the event do you mean creating an instance?
     
  13. Offline

    bartboy8

    No, register your class, put this in your onEnable method in your main class:
    Code:
    getServer().getPluginManager().registerEvents(new Enchant(), this);
     
  14. Offline

    aPandaification

    bartboy8
    the enchant class isn't a listener should I cast it to a listener or let enchant implement listener?
     
  15. Well, I don't see any events in your classes, so I don't see the reason why should register the non existing events nor cast it to a listener / implementing listener.
     
  16. Offline

    aPandaification

    kumpelblase2 So is there anything I can do to make it work?
     
  17. Offline

    bartboy8

    Put @EventHandler about your methods... it will activate them.
     
  18. Offline

    aPandaification

    bartboy8 So if i just put that above the execute method it will activate it and it will work?
     
  19. Offline

    bartboy8

    No, above your methods in your Enchant class.

    aPandaification Sorry, read your code wrong, no events. I'll take a closer look.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  20. Offline

    aPandaification

    thanks T.T because I am totally stuck and need this for my server to work...
     
  21. Offline

    bartboy8

    You could try this:
    Code:
    me.aPanda.PandaTheEnchanter.Enchant.execute(args);
     
  22. Offline

    aPandaification

    Okay I'll try that now

    bartboy8 It is giving me the 'Cannot make a static reference to the non-static method execute(string[]) from the type enchant. Would you suggest making the methods static?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  23. Offline

    bartboy8

    Sorry, actually that won't work... i dont know what i was thinking.
    just try:
    Code:
    this.enchant.execute;
    don't put the args part.
     
  24. Offline

    aPandaification

    it says that it can't be resolved and something about the field- should I make it this.enchant.execute();

    bartboy8 The exact error is: execute cannot be resolved or is not a field

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  25. Offline

    Korvacs

    Since the Enchant class doesnt need to be an instance (doesnt store any local information, purely methods) you might aswell convert it to a static class with static methods and call it directly.
     
  26. Offline

    HON95

    You need the (args) at the end. Are you sure label.equalsIgnoreCase("ea") is returning true? I would suggest using command.getName() instead of .getLabel().
     
  27. Offline

    aPandaification

    Korvacs When I call it directly do I still have to make an instance of the enchant class?

    EDIT: HON95 Ya it is reaching the statement because I put in the "debug" chat and it is being reached the method just isnt being executed properly for some reason...
     
  28. Offline

    Korvacs

    No, by making it static its always available by just doing Enchant.execute(args); you should remove the instance declaration and everything related to it and change over to direct calls.
     
  29. Offline

    aPandaification

    Korvacs I would have to make my inventoryhelper and Util classes static as well I'm assuming this wouldn't make a difference right.
     
  30. Offline

    Korvacs

    That wouldnt make any difference as they already only contain static methods, so making them static classes should also be perfectly fine.
     
Thread Status:
Not open for further replies.

Share This Page