This repository has been archived by the owner on Dec 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
//TODO event 调用待优化
- Loading branch information
Showing
6 changed files
with
69 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/kotlin/tech/cookiepower/jythonengine/script/trigger/EventListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package tech.cookiepower.jythonengine.script.trigger | ||
|
||
import org.bukkit.event.EventPriority | ||
import org.bukkit.event.HandlerList | ||
import org.bukkit.event.Listener | ||
import org.bukkit.plugin.RegisteredListener | ||
import taboolib.common.platform.function.submit | ||
import taboolib.platform.BukkitPlugin | ||
|
||
class EventListener : Listener { | ||
private val handlers = ArrayList<HandlerList>() | ||
private val listener = RegisteredListener( this, | ||
{ _, event -> EventTrigger.onEventCall(event) }, | ||
EventPriority.NORMAL, | ||
BukkitPlugin.getInstance(), | ||
false | ||
) | ||
private var lastSize = 0 | ||
val task = submit(period = 20, async = true) { | ||
if (lastSize != HandlerList.getHandlerLists().size){ | ||
HandlerList.getHandlerLists().filter { | ||
it !in handlers | ||
}.forEach { | ||
it.register(listener) | ||
handlers.add(it) | ||
} | ||
lastSize = HandlerList.getHandlerLists().size | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters