Skip to content

WithPlugin interface

Gabriel Souza edited this page Jul 6, 2020 · 1 revision

WithPlugin is a helper interface that holds a Plugin instance, normally used in Managers/Controllers. You will use it for minimize your calls to functions that depends of a Plugin, this means that menu, scoreboard, event, Online Player Collectionand others will not need to be called like thisplugin.menu(...)`.

class MyClass(override plugin: YourPlugin) : WithPlugin<YourPlugin> {
  val playersUsingSomething = onlinePlayerList()

  init {
    events {
      event<PlayerJoinEvent> {
         if(player.hasPermission("abc") {
           playersUsingSomethig.add(player)
         }
      }
    }
  }

}

You can use KListener as well, it is an Interface and WithPlugin combination.

class MyClass(override plugin: YourPlugin) : KListener<YourPlugin> {
  val playersUsingSomething = onlinePlayerList()

  init {
    event<PlayerJoinEvent> {
      if(player.hasPermission("abc") {
        playersUsingSomethig.add(player)
      }
    }
  }

}
Clone this wiki locally