Help implementing CommandExecutor

Discussion in 'Plugin Development' started by Warren2497, Jan 20, 2015.

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

    Warren2497

    Can someone help me crack down what i did wrong with the Command executor. Were trying to make it where you can type /points to view your points.

    Thanks!

    Links: http://pastebin.com/ZQ2JQAma

    I have the classes seperated by the long space. And again thanks you to anyone who can help
     
  2. Offline

    Avery246813579

    @Warren2497 Well first of all, you said that the command points was inside your main class? Since you have the command "points" inside a different class, where you state the executor, instead of this, the executor should be the class that has the command.

    The final code inside your on enable should be:
    Code:
    this.getCommand("points").setExecutor(new PlayerListener(this));
    You also are not enabling your listener. You should do this inside the constructor of your PlayerListener class by adding the following code to it:
    Code:
            public PlayerListener(ScoreKeeper plugin){
               Bukkit.getPluginManager().registerEvents(this, plugin);
            }
     
    Warren2497 likes this.
  3. Offline

    teej107

    @Warren2497 Well you never said what is not happening and what is supposed to be happening. But from looking at your code, I can see fairly easily what your problem is.
    1. You are not registering the CommandExecutor, you are registering your JavaPlugin object as a CommandExecutor (which is not needed at all) rather than the PlayerListener object.
    2. You are not registering your Listener either. You are just creating it.
     
  4. Offline

    Warren2497

    Thanks, ill try it out soon

    Thanks it worked! Im eternally grateful :p also just 1 more question when players log out and back in there "points" reset back to zero. Either one of you know why off top of your head?

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

    SuperOriginal

    Store something other than the player object in the arraylist. (Their name or uuid)
    When players logout it can cause memory leaks if you're storing its object.
     
Thread Status:
Not open for further replies.

Share This Page