Need help event system!

Discussion in 'Plugin Development' started by Dr Danco, May 19, 2012.

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

    Dr Danco

    I am a little new to java and really new to making Bukkit plugins. I am trying to follow GTOTech's tutorials to get started (episode 4 specifically is where I'm having the problem ) Anyway I've followed all the steps here ( http://forums.bukkit.org/threads/event-type-player_chat-need-help-with-new-event-system.63405/ ) to try and deal with some of the problems due to the changes in the event system. I've manged to fix every bug here except this one where it wont recognize the player chat event in this line:
    pm.registerEvent(Event.Type.PLAYER_CHAT, this.playerListener, EventPriority.NORMAL, this);

    Here are the files:
    http://pastebin.com/wp31qZM6 -- TestPlugin.java(which is HelloWorld.java in the tutorial)
    http://pastebin.com/my5diAUh -- ServerChatPlayerListener.java

    Anyway, hope some can help...
    Thanks!
     
  2. Offline

    Njol

  3. Offline

    Dr Danco

    Yea... I've seen that and as I said I managed to find and fix the issue with EventPriority but I can't figure out what I need to do to fix this certain error:
    in TestPlugin.java
    [​IMG]
     
  4. Offline

    Njol

  5. Offline

    Dr Danco

    I'm sorry I'm still pretty new to Java :confused: ...could you be a little more specific on what I have to do to make it recognize the event?
     
  6. Offline

    Njol

    The point is that it doesn't work that way anymore - you only have to specify the listener and Bukkit will figure out which events to listen to by looking at the methods of the listener.
    Code:
    getServer().getPluginManager().registerEvents(listener, plugin)
     
  7. Offline

    Tempelchat

    This makes no sense (TestPlugin:14):
    Code:
    public final ServerChatPlayerListener playerListener = new ServerChatPlayerListener(null);
    You want to give the listener a reference to your plugin. If you give null to it, ther is no point.
    Only initialize the variable here, a object will be stored, when your plugin is enabled
    (Solution: replace with)
    Code:
    public ServerChatPlayerListener playerListener;

    The first line in onEnable is right, simply save it in the variable that cou created above to be able to access methods and fields if you need any.
    Code:
    playerListener = new ServerChatPlayerListener(this);

    You are already registering the listener at ServerChatPlayerListener:12
    Therefore you can simply delete this line in TestPlugin:27
    Code:
    pm.registerEvent(Event.Type.PLAYER_CHAT, this.playerListener, EventPriority.NORMAL, this);

    Hope you are understanding what I mean. I'm bad at expressing someting :/
    If you want, I'll tell you why you should change this lines if you can't think of the reasons.
     
Thread Status:
Not open for further replies.

Share This Page