I'm clueless. How do I register events?

Discussion in 'Plugin Development' started by Daniel Heppner, Mar 1, 2011.

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

    Daniel Heppner

    Okay, so I'm making a plugin that will kick someone when they say a defined word(s). How do I register events? I really don't know what I'm doing here, and I really need help.

    Here's my current code:
    Code:
    package danielhep.chatcensor;
    
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class ChatCensor extends JavaPlugin {
    
        public void onDisable() {
    
            System.out.println("ChatCensor has been unloaded.");
    
        }
    
        public void onEnable() {
    
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvent(Event.Type.PLAYER.CHAT, playerListener, Priority.Normal, this);
    
            PluginDescriptionFile pdfFile = this.getDescription();
            System.out.println( pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!" );
    
        }
    
    }
    
    I'm so frustrated with myself, I shouldn't be getting into this, as I know nothing, but what is a better way to learn? :p

    Anyways, PLEASE help me register events and... well... help me write this, as I can think of a dozen other things I'm not going to be able to do. :)

    Thanks,
    Daniel
    --- merged: Mar 2, 2011 7:45 AM ---
    Eclipse doesn't like this part:
    pm.registerEvent(Event.Type.PLAYER.CHAT, playerListener, Priority.Normal, this);
    There are some errors going on there about things not being defined.

    UPDATED CODE:
    Code:
    package danielhep.chatcensor;
    
    import org.bukkit.event.Event.Priority;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import danielhep.chatcensor.listener.player.ChatCensorPlayerListener;
    
    public class ChatCensor extends JavaPlugin {
    
        private static final String Event = null;
        private final ChatCensorPlayerListener playerListener = new ChatCensorPlayerListener(this);
    
    
        public void onDisable() {
    
            System.out.println("ChatCensor has been unloaded.");
    
        }
    
        public void onEnable() {
    
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvent(Event.Type.PLAYERCHAT, playerListener, Priority.Normal, this);
    
            PluginDescriptionFile pdfFile = this.getDescription();
            System.out.println( pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!" );
    
        }
    
    }
    
    I still need help registering events, but I think other things are going pretty well. The only error is in the line
    pm.registerEvent(Event.Type.PLAYERCHAT, playerListener, Priority.Normal, this);
    where is doesn't like "Type".
    What I need to do is listen for the player's chats, then scan it for one of the defined words, if it finds it, it'll kick them.
     
  2. Offline

    lonelydime

    it's Event.Type.PLAYER_CHAT
     
  3. Offline

    mattbot5000

    you need to import org.bukkit.event.Event
     
  4. Offline

    Plague

    But Everything can eclipse do for you if you just read what it says to you.
     
  5. Offline

    Daniel Heppner

    Where's a list of the events? Is it on the Javadocs? I can't seem to find it... could someone please explain why exactly you need to register your events and when to do it?
    --- merged: Mar 3, 2011 4:34 AM ---
    Events for the future, btw. In case I need to make another plugin, I'd like to know how to find the events I could use.

    Oh, and thanks for your help. Almost forgot. :p
    (I'm not mean, just thinking about my homework.)
     
  6. Offline

    cjc343

  7. Offline

    Daniel Heppner

Thread Status:
Not open for further replies.

Share This Page