Skip to content

Commit

Permalink
Fix hotswap agent & child event mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
aromaa committed Jun 17, 2024
1 parent b4fdf69 commit 39dd130
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {

allprojects {
group = "io.quut"
version = "1.2"
version = "1.2.1"

apply(plugin = "com.diffplug.spotless")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public static void registerManager(final CtClass ctClass, final ClassPool classP
classPool.get("org.spongepowered.plugin.PluginContainer"),
classPool.get("java.util.Map"),
classPool.get("java.util.Map"),
classPool.get("java.util.Map")
}).insertAfter(initialization.toString());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ internal class SpongeHarmonyEventManager<T : Any>(
val scope: T = mapping(e) ?: return@EventListener
val scopeData: ScopeData = this.scopes[scope] ?: return@EventListener

scopeData.handleEvent(scope, e, listener.eventType.type)
scopeData.handleEvent(scope, e)
}

Sponge.game().eventManager().registerListener(
Expand Down Expand Up @@ -210,11 +210,23 @@ internal class SpongeHarmonyEventManager<T : Any>(
private val child: SpongeHarmonyEventManager<*>?,
private val childMappings: Map<Class<*>, (Any, Any) -> Any?>)
{
fun handleEvent(scope: Any, event: Event, eventClass: Class<*>)
private val mappingCache: MutableMap<Class<*>, ((Any, Any) -> Any?)?> = hashMapOf()

fun handleEvent(scope: Any, event: Event)
{
this.eventManager.post(event)

val childScope: Any = this.childMappings[eventClass]?.invoke(scope, event) ?: return
val mapping: (Any, Any) -> Any? = synchronized(this.mappingCache)
{
this.mappingCache.computeIfAbsent(event.javaClass)
{ key ->
SpongeHarmonyEventManager.walkHierarchy(key) { child -> this.childMappings[child]?.let { return@computeIfAbsent it } }

return@computeIfAbsent null
}
} ?: return

val childScope: Any = mapping(scope, event) ?: return
val scopeData: ScopeData = this.child!!.scopes[childScope] ?: return

scopeData.eventManager.post(event)
Expand Down

0 comments on commit 39dd130

Please sign in to comment.