Need Help Understanding Line of Code

Discussion in 'Plugin Development' started by jasondorson, Jan 20, 2021.

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

    jasondorson

    What does this code do? I know it executes once the plugin is enabled but what does the getServer part line actually do?
    Code:
        public void onEnable() {
            getServer().getPluginManager().registerEvents(this, this);
        }
    
     
  2. Offline

    timtower Administrator Administrator Moderator

    @jasondorson It finds all methods with @EventHandler that take a single argument (which is an Event) and stores them internally to be able to call them later.
     
  3. Offline

    Kars

    @jasondorson so when you have an @EventHandler annotated method taking a PlayerMoveEvent as an argument for example, it calls that method when a player moves.

    It will look for EventHandler methods in the class passed as the second argument in the snippet you provided (second 'this'). That doesn't have to be your main class but could also be another class, for example.
     
Thread Status:
Not open for further replies.

Share This Page