diff --git a/src/main/java/cpw/mods/fml/common/FMLCommonHandler.java b/src/main/java/cpw/mods/fml/common/FMLCommonHandler.java index f917590..82b1784 100644 --- a/src/main/java/cpw/mods/fml/common/FMLCommonHandler.java +++ b/src/main/java/cpw/mods/fml/common/FMLCommonHandler.java @@ -247,7 +247,7 @@ public void onPostServerTick() { profiler.startSection("forge_onPostServerTick"); - bus().post(new TickEvent.ServerTickEvent(Phase.END)); + bus().postWithProfile(profiler, new TickEvent.ServerTickEvent(Phase.END)); profiler.endSection(); } @@ -264,7 +264,7 @@ public void onPreServerTick() { profiler.startSection("forge_onPreServerTick"); - bus().post(new TickEvent.ServerTickEvent(Phase.START)); + bus().postWithProfile(profiler, new TickEvent.ServerTickEvent(Phase.START)); profiler.endSection(); } diff --git a/src/main/java/cpw/mods/fml/common/eventhandler/ASMEventHandler.java b/src/main/java/cpw/mods/fml/common/eventhandler/ASMEventHandler.java index 48245f9..15a0421 100644 --- a/src/main/java/cpw/mods/fml/common/eventhandler/ASMEventHandler.java +++ b/src/main/java/cpw/mods/fml/common/eventhandler/ASMEventHandler.java @@ -148,4 +148,11 @@ { return readable; } + + /* ======================================== ULTRAMINE START ===================================== */ + + public String getOwner() + { + return owner != null ? owner.getModId() : null; + } } \ No newline at end of file diff --git a/src/main/java/cpw/mods/fml/common/eventhandler/EventBus.java b/src/main/java/cpw/mods/fml/common/eventhandler/EventBus.java index 0daabe1..c25e0ae 100644 --- a/src/main/java/cpw/mods/fml/common/eventhandler/EventBus.java +++ b/src/main/java/cpw/mods/fml/common/eventhandler/EventBus.java @@ -9,6 +9,8 @@ import javax.annotation.Nonnull; +import net.minecraft.profiler.Profiler; + import org.apache.logging.log4j.Level; import com.google.common.base.Preconditions; @@ -156,4 +158,33 @@ FMLLog.log(Level.ERROR, "%d: %s", x, listeners[x]); } } + + /* ======================================== ULTRAMINE START ===================================== */ + + public boolean postWithProfile(Profiler profiler, Event event) + { + IEventListener[] listeners = event.getListenerList().getListeners(busID); + int index = 0; + try + { + for (; index < listeners.length; index++) + { + IEventListener listener = listeners[index]; + String owner = listener instanceof ASMEventHandler ? ((ASMEventHandler)listener).getOwner() : null; + if(owner != null) + profiler.startSection(owner); + + listener.invoke(event); + + if(owner != null) + profiler.endSection(); + } + } + catch (Throwable throwable) + { + exceptionHandler.handleException(this, event, listeners, index, throwable); + Throwables.propagate(throwable); + } + return (event.isCancelable() ? event.isCanceled() : false); + } } \ No newline at end of file