Skip to content

Commit

Permalink
Create lookups on register for "manually registered event listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
nelind3 committed Nov 2, 2024
1 parent 44b1f77 commit 841cf97
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,29 @@

import com.google.inject.Singleton;
import org.spongepowered.common.event.manager.SpongeEventManager;
import org.spongepowered.plugin.PluginContainer;

import java.lang.invoke.MethodHandles;

// TODO(loofah): figure out the event situation.
// how much and what kind of event sync between loofah/sponge and fapi are we going to do?
/** Copied from {@link org.spongepowered.vanilla.launch.event.VanillaEventManager} */
@Singleton
public class FabricEventManager extends SpongeEventManager {
private static final MethodHandles.Lookup LOOFAH_EVENTMANAGER_LOOKUP = MethodHandles.lookup();

@Override
public SpongeEventManager registerListeners(final PluginContainer plugin, final Object listener) {
MethodHandles.Lookup usedLookup;
try {
usedLookup = MethodHandles.privateLookupIn(listener.getClass(), FabricEventManager.LOOFAH_EVENTMANAGER_LOOKUP);
} catch (IllegalAccessException ex) {
String errorMessage = "Loofah was unable to create a lookup for " + listener +
" registered as an event listener by plugin " + plugin.metadata().id();
throw new IllegalArgumentException(errorMessage, ex);
}

this.registerListeners(plugin, listener, usedLookup);
return this;
}
}

0 comments on commit 841cf97

Please sign in to comment.