取消註冊事件或聽眾
你可以取消註冊單個事件,整個監聽器類或你的外掛或其他外掛註冊的所有事件!
取消註冊特定事件
每個事件類都有 getHandlerList()
靜態方法,呼叫它然後你可以使用 .unregister()
方法。
PlayerInteractEvent.getHandlerList().unregister(plugin);
// this will unregister all PlayerInteractEvent instances from the plugin
// you can also specify a listener class instead of plugin.
現在你知道為什麼在自定義事件中需要 getHandlerList()
。
取消註冊所有活動
使用 HandlerList 類及其 unregisterAll()
靜態方法,你可以輕鬆地從偵聽器類或外掛中取消註冊事件。
HandlerList.unregisterAll(plugin);
// this will unregister all events from the specified plugin
// you can also specify a listener class instead of plugin.