Pre-generate event classes (#2463)

This commit is contained in:
Luck committed 2020-07-16 21:00:17 +01:00
1 parent 47ca6b162b
commit ef556f7cf7
3 files changed
+52

No files matched your search

@@ -341,4 +341,44 @@ public final class EventDispatcher {
}
}
public static List<Class<? extends LuckPermsEvent>> getKnownEventTypes() {
return ImmutableList.of(
ContextUpdateEvent.class,
ExtensionLoadEvent.class,
GroupCacheLoadEvent.class,
GroupCreateEvent.class,
GroupDataRecalculateEvent.class,
GroupDeleteEvent.class,
GroupLoadAllEvent.class,
GroupLoadEvent.class,
LogBroadcastEvent.class,
LogNetworkPublishEvent.class,
LogNotifyEvent.class,
LogPublishEvent.class,
LogReceiveEvent.class,
NodeAddEvent.class,
NodeClearEvent.class,
NodeRemoveEvent.class,
PlayerDataSaveEvent.class,
PlayerLoginProcessEvent.class,
ConfigReloadEvent.class,
PostSyncEvent.class,
PreNetworkSyncEvent.class,
PreSyncEvent.class,
TrackCreateEvent.class,
TrackDeleteEvent.class,
TrackLoadAllEvent.class,
TrackLoadEvent.class,
TrackAddGroupEvent.class,
TrackClearEvent.class,
TrackRemoveGroupEvent.class,
UserCacheLoadEvent.class,
UserDataRecalculateEvent.class,
UserFirstLoginEvent.class,
UserLoadEvent.class,
UserDemoteEvent.class,
UserPromoteEvent.class
);
}
}
@@ -26,6 +26,7 @@
package me.lucko.luckperms.common.event.gen;
import me.lucko.luckperms.common.cache.LoadingMap;
import me.lucko.luckperms.common.event.EventDispatcher;
import net.bytebuddy.ByteBuddy;
import net.bytebuddy.ClassFileVersion;
@@ -80,6 +81,15 @@ public class GeneratedEventClass {
return CACHE.get(event);
}
/**
* Pre-generates {@link GeneratedEventClass}es for known event types.
*/
public static void preGenerate() {
for (Class<? extends LuckPermsEvent> eventType : EventDispatcher.getKnownEventTypes()) {
generate(eventType);
}
}
/**
* A method handle for the constructor of the event class.
*/
@@ -37,6 +37,7 @@ import me.lucko.luckperms.common.dependencies.Dependency;
import me.lucko.luckperms.common.dependencies.DependencyManager;
import me.lucko.luckperms.common.event.AbstractEventBus;
import me.lucko.luckperms.common.event.EventDispatcher;
import me.lucko.luckperms.common.event.gen.GeneratedEventClass;
import me.lucko.luckperms.common.extension.SimpleExtensionManager;
import me.lucko.luckperms.common.inheritance.InheritanceGraphFactory;
import me.lucko.luckperms.common.locale.LocaleManager;
@@ -176,6 +177,7 @@ public abstract class AbstractLuckPermsPlugin implements LuckPermsPlugin {
// register with the LP API
this.apiProvider = new LuckPermsApiProvider(this);
this.eventDispatcher = new EventDispatcher(provideEventBus(this.apiProvider));
getBootstrap().getScheduler().executeAsync(GeneratedEventClass::preGenerate);
ApiRegistrationUtil.registerProvider(this.apiProvider);
registerApiOnPlatform(this.apiProvider);