Help with my frist plugin

Discussion in 'Plugin Development' started by deregudegu, Jan 30, 2012.

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

    deregudegu

    Hello,

    I'm brazilian and I'm studying Java and Bukkit API for develop plugins. I started with editing a plugin called EnderPearlDisable for up date it.
    But the Bukkit API changed the events system and I'm lost :(
    Could anyone help me?

    This is the code:

    Code:
    public void onEnable() {
            SimplePluginManager.registerEvent(Event.Type.PLAYER_INTERACT_ENTITY,
                    new Listener() {
     
                        public void onPlayerInteract(PlayerInteractEvent event) {
                            if (event.getItem() != null && event.getItem().getType() == Material.ENDER_PEARL) {
                                event.getPlayer().sendMessage(ChatColor.RED+"Ender Pearl não funciona.");
                                event.setCancelled(true);
                            }
                        }
                    },
                    EventPriority.NORMAL, this);
       
            System.out.println("Ender Pearl TP blocking enabled.");
       
        }
    The Eclipse say the method of 'SimplePluginManager.registerEvent' is wrong.

    Other questions:

    • How I use a event type like 'Event.Type.PLAYER_INTERACT_ENTITY' in Bukkit API 1.1 R3?
    • Could anyone inform a tutorial about create config files? [SOLVED]
    Thanks for read :D
     
  2. Offline

    EllBristow

    Events were changed to make them simpler.

    The easiest way to implement the new system without creating a new class is like this:

    Code:
    public void onEnable() {
        SimplePluginManager.registerEvents(this, this);
        System.out.println("Ender Pearl TP blocking enabled.");
    }
     
    @EventHandler (priority = EventPriority.NORMAL)
    public void onPlayerInteract(PlayerInteractEvent event) {
        if (event.getItem() != null && event.getItem().getType() == Material.ENDER_PEARL) {
            event.getPlayer().sendMessage(ChatColor.RED+"Ender Pearl não funciona.");
            event.setCancelled(true);
        }
    }
    
     
  3. Offline

    deregudegu

    \o/!
    Thaks! :D

    @BEllBristow
    Hi :D
    I have error with:
    SimplePluginManager.registerEvents(this, this);

    Eclipse said:
    Cannot make a static reference to the non-static method registerEvents(Listener, Plugin) from the type SimplePluginManager

    Could you help me?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 23, 2016
  4. Code:
    Bukkit.getServer().getPluginManager().registerEvents(this, this);
    should work.
     
  5. Offline

    MrMag518

    He doesn't have to sepcify the priority, it's defaulting to Normal.

    Or simply
    Code:java
    1. getServer().getPluginManager().registerEvents(this, this);
    :)
    Remember to to code it in onEnable().
     
  6. it's possible sure, but for the sake of making it clear where the function is defined, or where to search it in the docs for example, it's better to access it from the class. Also your code does only work in the main class of the plugin, mine works everywhere in the plugin, because otherwise the compiler thinks it's a method from the current class and wouldn't find it.
     
  7. Offline

    MrMag518

    I also said code it in "onEnable" never said anywhere else.
    And in other classes its mor easy to use "plugin.getServer()"
     
  8. Offline

    deregudegu

    Thanks for help :p

    But how I convert old register events to new register events?

    For example:

    This is a old register events:

    Code:
    getServer().getPluginManager().registerEvent(Type.PLAYER_TOGGLE_SNEAK, playerListener, Priority.Monitor, this);
            getServer().getPluginManager().registerEvent(Type.PLAYER_MOVE, playerListener, Priority.Monitor, this);
            getServer().getPluginManager().registerEvent(Type.PLAYER_INTERACT_ENTITY, playerListener, Priority.Monitor, this);
            getServer().getPluginManager().registerEvent(Type.PLAYER_INTERACT, playerListener, Priority.Monitor, this);
     
            getServer().getPluginManager().registerEvent(Type.PLAYER_KICK, playerListener, Priority.Normal, this);
            getServer().getPluginManager().registerEvent(Type.ENTITY_DAMAGE, entityListener, Priority.Normal, this);
    What is new register events?

    Thanks
     
  9. Offline

    EllBristow

    Code:
    getServer().getPluginManager().registerEvents(playerListener, this);
    getServer().getPluginManager().registerEvents(entityListener, this);
    
     
  10. Offline

    MrMag518

    He also need to state them in the listener classes, like:
    Code:java
    1. public PlayerListener() {
    2. plugin.getServer().getPluginManager().registerEvents(this, plugin);
    3. }
     
  11. actually... not. Why should he register the listeners twice? That would not make much sense.
     
  12. Offline

    MrMag518

    He needs to register the events in the listener.. ugh..

    else it wont register any events.
     
  13. if you register them in your main-class, you don't need to. Like I said, it wouldn't make that much sense to register them twice.
     
  14. Offline

    deregudegu

    Thanks for all.
    But and PLAYER_TOGGLE_SNEAK?
    I used OnPlayerToggleSneak but don't work.
     
  15. Offline

    theguynextdoor

  16. Offline

    MrMag518

    Dude, he needs to register the Listener, then register the registered events in the main class, in my case I have to.
     
  17. Read the thread:
    New Event System
    Do you see anywhere, where he registers the listener inside the listener AND in the main class? I don't. I only see where here registers the listener ONE time. Yeah it's inside the listener, but this is ONE time.
     
  18. Offline

    MrMag518

    I never siad register it two times in the main class, I said one time in the listener and one in the main class. bump.
    http://wiki.bukkit.org/Introduction_to_the_New_Event_System

    And btw, I never said he's going to register the listener two places either.
    But I won't argue more, so im unwatching this thread.
     
  19. but that's what you just did two lines earlier:
    So to clarify this (and like it's state in the post of md_5):
    You need to register them only ONE time. No matter where, might it be the listener itselft or the main class, you only need to do it ONE time.
     
  20. Offline

    MrMag518

    I just tested what you said. (never registering the events in the listener, but do it from the main class)
    And it returned negative.
    Just to clearify, Your not understanding what I mean.
    I'm talking about events AND listeners, I never said register the LISTENERS two times.
     
  21. Offline

    Father Of Time

    This argument makes no sense... You don't register an event, an event is simply something that occurs naturally due to code embedded into Bukkit, whether something is listening for the event or not is irrelevant.

    You do however register a listener because the only way Bukkit knows to notify your plug-in of these always occurring events is by registering your listener with the Bukkit so that every time that event occurs Bukkit can send the data to your listener.

    This simply isn't true, if you would have read the entire thread you would realize this:

    md_5 quote:
    Honestly it appears that you misspoke and are now simply trying to backpedal... Personally I have a greater appreciation for people who say "You are right, thank you for the correction" as appose to people who will just continue to argument a moot point to save face...
     
    kumpelblase2 likes this.
  22. Offline

    MrMag518

    Againt, you obviously don't understand what I ment by all this.
     
  23. Offline

    Father Of Time

    Apparently not, it's hard when it makes little to no sense... If you can manage to explain it to us I would be more than happy to listen, but what you've stated above is chalk full of contradictions and flat out misinformation...
     
Thread Status:
Not open for further replies.

Share This Page