From 2bae6cafc2ec677a3e7aabe6b682578aacdbc781 Mon Sep 17 00:00:00 2001 From: md_5 Date: Tue, 19 Mar 2013 17:21:54 +1100 Subject: [PATCH] Try and prevent inefficient plugins by nagging when events take longer than 0.25ms to process. Someone let me know if this spams and I need to increase the max time. --- .../net/md_5/bungee/api/plugin/PluginManager.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/api/src/main/java/net/md_5/bungee/api/plugin/PluginManager.java b/api/src/main/java/net/md_5/bungee/api/plugin/PluginManager.java index 96728010..7eeb68e8 100644 --- a/api/src/main/java/net/md_5/bungee/api/plugin/PluginManager.java +++ b/api/src/main/java/net/md_5/bungee/api/plugin/PluginManager.java @@ -19,6 +19,7 @@ import lombok.RequiredArgsConstructor; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.event.LoginEvent; import org.yaml.snakeyaml.Yaml; /** @@ -226,7 +227,17 @@ public class PluginManager */ public T callEvent(T event) { + long start = System.nanoTime(); eventBus.post( event ); + // TODO: No exceptions! + if ( !( event instanceof LoginEvent ) ) + { + long elapsed = start - System.nanoTime(); + if ( elapsed > 250000 ) + { + ProxyServer.getInstance().getLogger().log( Level.WARNING, "Event {0} took more than 0.25ms to process!", event ); + } + } return event; }