取消注册事件或听众

你可以取消注册单个事件,整个监听器类或你的插件或其他插件注册的所有事件!

取消注册特定事件

每个事件类都有 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.