Commit b4c52de03b8444ad6674ca81b584d2ae3bb103eb

Authored by Mumfrey
1 parent 58a0b663

switch everything possible to HandlerList

java/client/com/mumfrey/liteloader/client/ClientEvents.java
@@ -28,6 +28,8 @@ import com.mumfrey.liteloader.core.Events; @@ -28,6 +28,8 @@ import com.mumfrey.liteloader.core.Events;
28 import com.mumfrey.liteloader.core.InterfaceRegistrationDelegate; 28 import com.mumfrey.liteloader.core.InterfaceRegistrationDelegate;
29 import com.mumfrey.liteloader.core.LiteLoader; 29 import com.mumfrey.liteloader.core.LiteLoader;
30 import com.mumfrey.liteloader.core.event.HandlerList; 30 import com.mumfrey.liteloader.core.event.HandlerList;
  31 +import com.mumfrey.liteloader.core.event.HandlerList.ReturnLogicOp;
  32 +import com.mumfrey.liteloader.interfaces.FastIterableDeque;
31 import com.mumfrey.liteloader.launch.LoaderProperties; 33 import com.mumfrey.liteloader.launch.LoaderProperties;
32 import com.mumfrey.liteloader.transformers.event.EventInfo; 34 import com.mumfrey.liteloader.transformers.event.EventInfo;
33 import com.mumfrey.liteloader.util.log.LiteLoaderLogger; 35 import com.mumfrey.liteloader.util.log.LiteLoaderLogger;
@@ -82,22 +84,22 @@ public class ClientEvents extends Events<Minecraft, IntegratedServer> @@ -82,22 +84,22 @@ public class ClientEvents extends Events<Minecraft, IntegratedServer>
82 */ 84 */
83 private int worldHashCode = 0; 85 private int worldHashCode = 0;
84 86
85 - private HandlerList<Tickable> tickListeners = new HandlerList<Tickable>(Tickable.class);  
86 - private HandlerList<GameLoopListener> loopListeners = new HandlerList<GameLoopListener>(GameLoopListener.class);  
87 - private HandlerList<RenderListener> renderListeners = new HandlerList<RenderListener>(RenderListener.class);  
88 - private HandlerList<PostRenderListener> postRenderListeners = new HandlerList<PostRenderListener>(PostRenderListener.class);  
89 - private HandlerList<HUDRenderListener> hudRenderListeners = new HandlerList<HUDRenderListener>(HUDRenderListener.class);  
90 - private HandlerList<ChatRenderListener> chatRenderListeners = new HandlerList<ChatRenderListener>(ChatRenderListener.class);  
91 - private HandlerList<ChatListener> chatListeners = new HandlerList<ChatListener>(ChatListener.class);  
92 - private HandlerList<PostLoginListener> postLoginListeners = new HandlerList<PostLoginListener>(PostLoginListener.class);  
93 - private HandlerList<JoinGameListener> joinGameListeners = new HandlerList<JoinGameListener>(JoinGameListener.class);  
94 - private HandlerList<OutboundChatListener> outboundChatListeners = new HandlerList<OutboundChatListener>(OutboundChatListener.class);  
95 - private HandlerList<ViewportListener> viewportListeners = new HandlerList<ViewportListener>(ViewportListener.class);  
96 - private HandlerList<FrameBufferListener> frameBufferListeners = new HandlerList<FrameBufferListener>(FrameBufferListener.class);  
97 - private HandlerList<InitCompleteListener> initListeners = new HandlerList<InitCompleteListener>(InitCompleteListener.class);  
98 - private HandlerList<ChatFilter> chatFilters = new HandlerList<ChatFilter>(ChatFilter.class);  
99 - private HandlerList<PreJoinGameListener> preJoinGameListeners = new HandlerList<PreJoinGameListener>(PreJoinGameListener.class);  
100 - private HandlerList<OutboundChatFilter> outboundChatFilters = new HandlerList<OutboundChatFilter>(OutboundChatFilter.class); 87 + private FastIterableDeque<Tickable> tickListeners = new HandlerList<Tickable>(Tickable.class);
  88 + private FastIterableDeque<GameLoopListener> loopListeners = new HandlerList<GameLoopListener>(GameLoopListener.class);
  89 + private FastIterableDeque<RenderListener> renderListeners = new HandlerList<RenderListener>(RenderListener.class);
  90 + private FastIterableDeque<PostRenderListener> postRenderListeners = new HandlerList<PostRenderListener>(PostRenderListener.class);
  91 + private FastIterableDeque<HUDRenderListener> hudRenderListeners = new HandlerList<HUDRenderListener>(HUDRenderListener.class);
  92 + private FastIterableDeque<ChatRenderListener> chatRenderListeners = new HandlerList<ChatRenderListener>(ChatRenderListener.class);
  93 + private FastIterableDeque<ChatListener> chatListeners = new HandlerList<ChatListener>(ChatListener.class);
  94 + private FastIterableDeque<PostLoginListener> postLoginListeners = new HandlerList<PostLoginListener>(PostLoginListener.class);
  95 + private FastIterableDeque<JoinGameListener> joinGameListeners = new HandlerList<JoinGameListener>(JoinGameListener.class);
  96 + private FastIterableDeque<OutboundChatListener> outboundChatListeners = new HandlerList<OutboundChatListener>(OutboundChatListener.class);
  97 + private FastIterableDeque<ViewportListener> viewportListeners = new HandlerList<ViewportListener>(ViewportListener.class);
  98 + private FastIterableDeque<FrameBufferListener> frameBufferListeners = new HandlerList<FrameBufferListener>(FrameBufferListener.class);
  99 + private FastIterableDeque<InitCompleteListener> initListeners = new HandlerList<InitCompleteListener>(InitCompleteListener.class);
  100 + private FastIterableDeque<ChatFilter> chatFilters = new HandlerList<ChatFilter>(ChatFilter.class, ReturnLogicOp.AND_BREAK_ON_FALSE);
  101 + private FastIterableDeque<PreJoinGameListener> preJoinGameListeners = new HandlerList<PreJoinGameListener>(PreJoinGameListener.class, ReturnLogicOp.OR);
  102 + private FastIterableDeque<OutboundChatFilter> outboundChatFilters = new HandlerList<OutboundChatFilter>(OutboundChatFilter.class, ReturnLogicOp.AND);
101 103
102 @SuppressWarnings("cast") 104 @SuppressWarnings("cast")
103 public ClientEvents(LiteLoader loader, GameEngineClient engine, LoaderProperties properties) 105 public ClientEvents(LiteLoader loader, GameEngineClient engine, LoaderProperties properties)
@@ -251,10 +253,7 @@ public class ClientEvents extends Events&lt;Minecraft, IntegratedServer&gt; @@ -251,10 +253,7 @@ public class ClientEvents extends Events&lt;Minecraft, IntegratedServer&gt;
251 */ 253 */
252 public void addChatFilter(ChatFilter chatFilter) 254 public void addChatFilter(ChatFilter chatFilter)
253 { 255 {
254 - if (!this.chatFilters.contains(chatFilter))  
255 - {  
256 - this.chatFilters.add(chatFilter);  
257 - } 256 + this.chatFilters.add(chatFilter);
258 } 257 }
259 258
260 /** 259 /**
@@ -596,10 +595,9 @@ public class ClientEvents extends Events&lt;Minecraft, IntegratedServer&gt; @@ -596,10 +595,9 @@ public class ClientEvents extends Events&lt;Minecraft, IntegratedServer&gt;
596 */ 595 */
597 void onSendChatMessage(EventInfo<EntityClientPlayerMP> e, String message) 596 void onSendChatMessage(EventInfo<EntityClientPlayerMP> e, String message)
598 { 597 {
599 - for (OutboundChatFilter outboundChatFilter : this.outboundChatFilters) 598 + if (!this.outboundChatFilters.all().onSendChatMessage(message))
600 { 599 {
601 - if (!outboundChatFilter.onSendChatMessage(message))  
602 - e.cancel(); 600 + e.cancel();
603 } 601 }
604 } 602 }
605 603
@@ -627,14 +625,7 @@ public class ClientEvents extends Events&lt;Minecraft, IntegratedServer&gt; @@ -627,14 +625,7 @@ public class ClientEvents extends Events&lt;Minecraft, IntegratedServer&gt;
627 */ 625 */
628 boolean onPreJoinGame(INetHandler netHandler, S01PacketJoinGame loginPacket) 626 boolean onPreJoinGame(INetHandler netHandler, S01PacketJoinGame loginPacket)
629 { 627 {
630 - boolean cancelled = false;  
631 -  
632 - for (PreJoinGameListener joinGameListener : this.preJoinGameListeners)  
633 - {  
634 - cancelled |= !joinGameListener.onPreJoinGame(netHandler, loginPacket);  
635 - }  
636 -  
637 - return !cancelled; 628 + return !this.preJoinGameListeners.all().onPreJoinGame(netHandler, loginPacket);
638 } 629 }
639 630
640 /** 631 /**
java/common/com/mumfrey/liteloader/core/ClientPluginChannels.java
@@ -5,6 +5,8 @@ import net.minecraft.network.play.server.S3FPacketCustomPayload; @@ -5,6 +5,8 @@ import net.minecraft.network.play.server.S3FPacketCustomPayload;
5 5
6 import com.mumfrey.liteloader.PluginChannelListener; 6 import com.mumfrey.liteloader.PluginChannelListener;
7 import com.mumfrey.liteloader.api.Listener; 7 import com.mumfrey.liteloader.api.Listener;
  8 +import com.mumfrey.liteloader.core.event.HandlerList;
  9 +import com.mumfrey.liteloader.interfaces.FastIterableDeque;
8 import com.mumfrey.liteloader.permissions.PermissionsManagerClient; 10 import com.mumfrey.liteloader.permissions.PermissionsManagerClient;
9 import com.mumfrey.liteloader.util.log.LiteLoaderLogger; 11 import com.mumfrey.liteloader.util.log.LiteLoaderLogger;
10 12
@@ -19,8 +21,15 @@ public abstract class ClientPluginChannels extends PluginChannels&lt;PluginChannelL @@ -19,8 +21,15 @@ public abstract class ClientPluginChannels extends PluginChannels&lt;PluginChannelL
19 21
20 protected ClientPluginChannels() 22 protected ClientPluginChannels()
21 { 23 {
  24 + if (ClientPluginChannels.instance != null) throw new RuntimeException("Plugin Channels Startup Error", new InstantiationException("Only a single instance of ClientPluginChannels is allowed"));
22 ClientPluginChannels.instance = this; 25 ClientPluginChannels.instance = this;
23 } 26 }
  27 +
  28 + @Override
  29 + protected FastIterableDeque<PluginChannelListener> createHandlerList()
  30 + {
  31 + return new HandlerList<PluginChannelListener>(PluginChannelListener.class);
  32 + }
24 33
25 protected static ClientPluginChannels getInstance() 34 protected static ClientPluginChannels getInstance()
26 { 35 {
java/common/com/mumfrey/liteloader/core/Events.java
@@ -29,6 +29,8 @@ import com.mumfrey.liteloader.api.Listener; @@ -29,6 +29,8 @@ import com.mumfrey.liteloader.api.Listener;
29 import com.mumfrey.liteloader.common.GameEngine; 29 import com.mumfrey.liteloader.common.GameEngine;
30 import com.mumfrey.liteloader.common.LoadingProgress; 30 import com.mumfrey.liteloader.common.LoadingProgress;
31 import com.mumfrey.liteloader.core.event.HandlerList; 31 import com.mumfrey.liteloader.core.event.HandlerList;
  32 +import com.mumfrey.liteloader.core.event.HandlerList.ReturnLogicOp;
  33 +import com.mumfrey.liteloader.interfaces.FastIterable;
32 import com.mumfrey.liteloader.launch.LoaderProperties; 34 import com.mumfrey.liteloader.launch.LoaderProperties;
33 import com.mumfrey.liteloader.util.log.LiteLoaderLogger; 35 import com.mumfrey.liteloader.util.log.LiteLoaderLogger;
34 36
@@ -60,17 +62,17 @@ public abstract class Events&lt;TClient, TServer extends MinecraftServer&gt; implement @@ -60,17 +62,17 @@ public abstract class Events&lt;TClient, TServer extends MinecraftServer&gt; implement
60 /** 62 /**
61 * List of mods which can filter server chat 63 * List of mods which can filter server chat
62 */ 64 */
63 - private HandlerList<ServerChatFilter> serverChatFilters = new HandlerList<ServerChatFilter>(ServerChatFilter.class); 65 + private FastIterable<ServerChatFilter> serverChatFilters = new HandlerList<ServerChatFilter>(ServerChatFilter.class, ReturnLogicOp.AND_BREAK_ON_FALSE);
64 66
65 /** 67 /**
66 * List of mods which provide server commands 68 * List of mods which provide server commands
67 */ 69 */
68 - private HandlerList<ServerCommandProvider> serverCommandProviders = new HandlerList<ServerCommandProvider>(ServerCommandProvider.class); 70 + private FastIterable<ServerCommandProvider> serverCommandProviders = new HandlerList<ServerCommandProvider>(ServerCommandProvider.class);
69 71
70 /** 72 /**
71 * List of mods which monitor server player events 73 * List of mods which monitor server player events
72 */ 74 */
73 - private HandlerList<ServerPlayerListener> serverPlayerListeners = new HandlerList<ServerPlayerListener>(ServerPlayerListener.class); 75 + private FastIterable<ServerPlayerListener> serverPlayerListeners = new HandlerList<ServerPlayerListener>(ServerPlayerListener.class);
74 76
75 /** 77 /**
76 * Package private ctor 78 * Package private ctor
@@ -157,10 +159,7 @@ public abstract class Events&lt;TClient, TServer extends MinecraftServer&gt; implement @@ -157,10 +159,7 @@ public abstract class Events&lt;TClient, TServer extends MinecraftServer&gt; implement
157 */ 159 */
158 public void addServerChatFilter(ServerChatFilter serverChatFilter) 160 public void addServerChatFilter(ServerChatFilter serverChatFilter)
159 { 161 {
160 - if (!this.serverChatFilters.contains(serverChatFilter))  
161 - {  
162 - this.serverChatFilters.add(serverChatFilter);  
163 - } 162 + this.serverChatFilters.add(serverChatFilter);
164 } 163 }
165 164
166 /** 165 /**
@@ -196,15 +195,7 @@ public abstract class Events&lt;TClient, TServer extends MinecraftServer&gt; implement @@ -196,15 +195,7 @@ public abstract class Events&lt;TClient, TServer extends MinecraftServer&gt; implement
196 { 195 {
197 EntityPlayerMP player = netHandler instanceof NetHandlerPlayServer ? ((NetHandlerPlayServer)netHandler).playerEntity : null; 196 EntityPlayerMP player = netHandler instanceof NetHandlerPlayServer ? ((NetHandlerPlayServer)netHandler).playerEntity : null;
198 197
199 - for (ServerChatFilter chatFilter : this.serverChatFilters)  
200 - {  
201 - if (!chatFilter.onChat(player, chatPacket, chatPacket.func_149439_c()))  
202 - {  
203 - return false;  
204 - }  
205 - }  
206 -  
207 - return true; 198 + return this.serverChatFilters.all().onChat(player, chatPacket, chatPacket.func_149439_c());
208 } 199 }
209 200
210 /** 201 /**
java/common/com/mumfrey/liteloader/core/LiteLoader.java
@@ -4,7 +4,6 @@ import java.io.File; @@ -4,7 +4,6 @@ import java.io.File;
4 import java.io.PrintStream; 4 import java.io.PrintStream;
5 import java.util.ArrayList; 5 import java.util.ArrayList;
6 import java.util.Collection; 6 import java.util.Collection;
7 -import java.util.LinkedList;  
8 import java.util.List; 7 import java.util.List;
9 8
10 import javax.activity.InvalidActivityException; 9 import javax.activity.InvalidActivityException;
@@ -35,9 +34,11 @@ import com.mumfrey.liteloader.common.GameEngine; @@ -35,9 +34,11 @@ import com.mumfrey.liteloader.common.GameEngine;
35 import com.mumfrey.liteloader.common.LoadingProgress; 34 import com.mumfrey.liteloader.common.LoadingProgress;
36 import com.mumfrey.liteloader.core.api.LiteLoaderCoreAPI; 35 import com.mumfrey.liteloader.core.api.LiteLoaderCoreAPI;
37 import com.mumfrey.liteloader.core.event.EventProxy; 36 import com.mumfrey.liteloader.core.event.EventProxy;
  37 +import com.mumfrey.liteloader.core.event.HandlerList;
38 import com.mumfrey.liteloader.crashreport.CallableLaunchWrapper; 38 import com.mumfrey.liteloader.crashreport.CallableLaunchWrapper;
39 import com.mumfrey.liteloader.crashreport.CallableLiteLoaderBrand; 39 import com.mumfrey.liteloader.crashreport.CallableLiteLoaderBrand;
40 import com.mumfrey.liteloader.crashreport.CallableLiteLoaderMods; 40 import com.mumfrey.liteloader.crashreport.CallableLiteLoaderMods;
  41 +import com.mumfrey.liteloader.interfaces.FastIterableDeque;
41 import com.mumfrey.liteloader.interfaces.Loadable; 42 import com.mumfrey.liteloader.interfaces.Loadable;
42 import com.mumfrey.liteloader.interfaces.LoadableMod; 43 import com.mumfrey.liteloader.interfaces.LoadableMod;
43 import com.mumfrey.liteloader.interfaces.LoaderEnumerator; 44 import com.mumfrey.liteloader.interfaces.LoaderEnumerator;
@@ -128,27 +129,11 @@ public final class LiteLoader @@ -128,27 +129,11 @@ public final class LiteLoader
128 /** 129 /**
129 * Core providers 130 * Core providers
130 */ 131 */
131 - private final List<CoreProvider> coreProviders = new LinkedList<CoreProvider>();  
132 -  
133 - /**  
134 - *  
135 - */  
136 - private final List<TickObserver> tickObservers = new LinkedList<TickObserver>();  
137 -  
138 - /**  
139 - *  
140 - */  
141 - private final List<WorldObserver> worldObservers = new LinkedList<WorldObserver>();  
142 -  
143 - /**  
144 - *  
145 - */  
146 - private final List<ShutdownObserver> shutdownObservers = new LinkedList<ShutdownObserver>();  
147 -  
148 - /**  
149 - *  
150 - */  
151 - private final List<PostRenderObserver> postRenderObservers = new LinkedList<PostRenderObserver>(); 132 + private final FastIterableDeque<CoreProvider> coreProviders = new HandlerList<CoreProvider>(CoreProvider.class);
  133 + private final FastIterableDeque<TickObserver> tickObservers = new HandlerList<TickObserver>(TickObserver.class);
  134 + private final FastIterableDeque<WorldObserver> worldObservers = new HandlerList<WorldObserver>(WorldObserver.class);
  135 + private final FastIterableDeque<ShutdownObserver> shutdownObservers = new HandlerList<ShutdownObserver>(ShutdownObserver.class);
  136 + private final FastIterableDeque<PostRenderObserver> postRenderObservers = new HandlerList<PostRenderObserver>(PostRenderObserver.class);
152 137
153 /** 138 /**
154 * Mod panel manager, deliberately raw 139 * Mod panel manager, deliberately raw
@@ -245,10 +230,7 @@ public final class LiteLoader @@ -245,10 +230,7 @@ public final class LiteLoader
245 this.shutdownObservers.addAll(this.apiAdapter.getAllObservers(ShutdownObserver.class)); 230 this.shutdownObservers.addAll(this.apiAdapter.getAllObservers(ShutdownObserver.class));
246 this.postRenderObservers.addAll(this.apiAdapter.getAllObservers(PostRenderObserver.class)); 231 this.postRenderObservers.addAll(this.apiAdapter.getAllObservers(PostRenderObserver.class));
247 232
248 - for (CoreProvider coreProvider : this.coreProviders)  
249 - {  
250 - coreProvider.onInit();  
251 - } 233 + this.coreProviders.all().onInit();
252 234
253 this.enumerator.onInit(); 235 this.enumerator.onInit();
254 this.mods.init(this.apiAdapter.getAllObservers(ModLoadObserver.class)); 236 this.mods.init(this.apiAdapter.getAllObservers(ModLoadObserver.class));
@@ -273,10 +255,7 @@ public final class LiteLoader @@ -273,10 +255,7 @@ public final class LiteLoader
273 // Spawn mod instances and initialise them 255 // Spawn mod instances and initialise them
274 this.loadAndInitMods(); 256 this.loadAndInitMods();
275 257
276 - for (CoreProvider coreProvider : this.coreProviders)  
277 - {  
278 - coreProvider.onPostInitComplete(this.mods);  
279 - } 258 + this.coreProviders.all().onPostInitComplete(this.mods);
280 259
281 // Save stuff 260 // Save stuff
282 this.properties.writeProperties(); 261 this.properties.writeProperties();
@@ -884,10 +863,7 @@ public final class LiteLoader @@ -884,10 +863,7 @@ public final class LiteLoader
884 */ 863 */
885 private void postInitCoreProviders() 864 private void postInitCoreProviders()
886 { 865 {
887 - for (CoreProvider coreProvider : this.coreProviders)  
888 - {  
889 - coreProvider.onPostInit(this.engine);  
890 - } 866 + this.coreProviders.all().onPostInit(this.engine);
891 867
892 this.interfaceManager.registerInterfaces(); 868 this.interfaceManager.registerInterfaces();
893 } 869 }
@@ -950,10 +926,7 @@ public final class LiteLoader @@ -950,10 +926,7 @@ public final class LiteLoader
950 { 926 {
951 this.permissionsManagerClient.onJoinGame(netHandler, loginPacket); 927 this.permissionsManagerClient.onJoinGame(netHandler, loginPacket);
952 928
953 - for (CoreProvider coreProvider : this.coreProviders)  
954 - {  
955 - coreProvider.onJoinGame(netHandler, loginPacket);  
956 - } 929 + this.coreProviders.all().onJoinGame(netHandler, loginPacket);
957 } 930 }
958 931
959 /** 932 /**
@@ -969,10 +942,7 @@ public final class LiteLoader @@ -969,10 +942,7 @@ public final class LiteLoader
969 this.permissionsManagerClient.scheduleRefresh(); 942 this.permissionsManagerClient.scheduleRefresh();
970 } 943 }
971 944
972 - for (WorldObserver worldObserver : this.worldObservers)  
973 - {  
974 - worldObserver.onWorldChanged(world);  
975 - } 945 + this.worldObservers.all().onWorldChanged(world);
976 } 946 }
977 947
978 /** 948 /**
@@ -983,12 +953,7 @@ public final class LiteLoader @@ -983,12 +953,7 @@ public final class LiteLoader
983 void onPostRender(int mouseX, int mouseY, float partialTicks) 953 void onPostRender(int mouseX, int mouseY, float partialTicks)
984 { 954 {
985 this.profiler.startSection("core"); 955 this.profiler.startSection("core");
986 -  
987 - for (PostRenderObserver postRenderObserver : this.postRenderObservers)  
988 - {  
989 - postRenderObserver.onPostRender(mouseX, mouseY, partialTicks);  
990 - }  
991 - 956 + this.postRenderObservers.all().onPostRender(mouseX, mouseY, partialTicks);
992 this.profiler.endSection(); 957 this.profiler.endSection();
993 } 958 }
994 959
@@ -1020,10 +985,7 @@ public final class LiteLoader @@ -1020,10 +985,7 @@ public final class LiteLoader
1020 985
1021 this.profiler.startSection("observers"); 986 this.profiler.startSection("observers");
1022 987
1023 - for (TickObserver tickObserver : this.tickObservers)  
1024 - {  
1025 - tickObserver.onTick(clock, partialTicks, inGame);  
1026 - } 988 + this.tickObservers.all().onTick(clock, partialTicks, inGame);
1027 989
1028 this.profiler.endSection(); 990 this.profiler.endSection();
1029 } 991 }
@@ -1032,10 +994,7 @@ public final class LiteLoader @@ -1032,10 +994,7 @@ public final class LiteLoader
1032 { 994 {
1033 LiteLoaderLogger.info("LiteLoader is shutting down, shutting down core providers and syncing configuration"); 995 LiteLoaderLogger.info("LiteLoader is shutting down, shutting down core providers and syncing configuration");
1034 996
1035 - for (ShutdownObserver lifeCycleObserver : this.shutdownObservers)  
1036 - {  
1037 - lifeCycleObserver.onShutDown();  
1038 - } 997 + this.shutdownObservers.all().onShutDown();
1039 998
1040 this.configManager.syncConfig(); 999 this.configManager.syncConfig();
1041 } 1000 }
java/common/com/mumfrey/liteloader/core/LiteLoaderInterfaceManager.java
@@ -4,7 +4,6 @@ import java.lang.reflect.Method; @@ -4,7 +4,6 @@ import java.lang.reflect.Method;
4 import java.util.ArrayList; 4 import java.util.ArrayList;
5 import java.util.HashMap; 5 import java.util.HashMap;
6 import java.util.Iterator; 6 import java.util.Iterator;
7 -import java.util.LinkedList;  
8 import java.util.List; 7 import java.util.List;
9 import java.util.Map; 8 import java.util.Map;
10 9
@@ -15,6 +14,8 @@ import com.mumfrey.liteloader.api.LiteAPI; @@ -15,6 +14,8 @@ import com.mumfrey.liteloader.api.LiteAPI;
15 import com.mumfrey.liteloader.api.Observer; 14 import com.mumfrey.liteloader.api.Observer;
16 import com.mumfrey.liteloader.api.exceptions.InvalidProviderException; 15 import com.mumfrey.liteloader.api.exceptions.InvalidProviderException;
17 import com.mumfrey.liteloader.api.manager.APIAdapter; 16 import com.mumfrey.liteloader.api.manager.APIAdapter;
  17 +import com.mumfrey.liteloader.core.event.HandlerList;
  18 +import com.mumfrey.liteloader.interfaces.FastIterable;
18 import com.mumfrey.liteloader.interfaces.InterfaceRegistry; 19 import com.mumfrey.liteloader.interfaces.InterfaceRegistry;
19 import com.mumfrey.liteloader.util.log.LiteLoaderLogger; 20 import com.mumfrey.liteloader.util.log.LiteLoaderLogger;
20 21
@@ -152,10 +153,7 @@ public class LiteLoaderInterfaceManager implements InterfaceRegistry @@ -152,10 +153,7 @@ public class LiteLoaderInterfaceManager implements InterfaceRegistry
152 153
153 this.registeredListeners.add(listener); 154 this.registeredListeners.add(listener);
154 155
155 - for (InterfaceObserver observer : LiteLoaderInterfaceManager.this.observers)  
156 - {  
157 - observer.onRegisterListener(this.provider, this.interfaceType, listener);  
158 - } 156 + LiteLoaderInterfaceManager.this.observers.all().onRegisterListener(this.provider, this.interfaceType, listener);
159 157
160 return true; 158 return true;
161 } 159 }
@@ -197,7 +195,7 @@ public class LiteLoaderInterfaceManager implements InterfaceRegistry @@ -197,7 +195,7 @@ public class LiteLoaderInterfaceManager implements InterfaceRegistry
197 /** 195 /**
198 * Interface observers 196 * Interface observers
199 */ 197 */
200 - protected final List<InterfaceObserver> observers = new LinkedList<InterfaceObserver>(); 198 + protected final FastIterable<InterfaceObserver> observers = new HandlerList<InterfaceObserver>(InterfaceObserver.class);
201 199
202 /** 200 /**
203 * True once the initial init phase (in which all registered providers are initialised) is completed, we 201 * True once the initial init phase (in which all registered providers are initialised) is completed, we
@@ -321,10 +319,7 @@ public class LiteLoaderInterfaceManager implements InterfaceRegistry @@ -321,10 +319,7 @@ public class LiteLoaderInterfaceManager implements InterfaceRegistry
321 */ 319 */
322 public void registerObserver(InterfaceObserver observer) 320 public void registerObserver(InterfaceObserver observer)
323 { 321 {
324 - if (!this.observers.contains(observer))  
325 - {  
326 - this.observers.add(observer);  
327 - } 322 + this.observers.add(observer);
328 } 323 }
329 324
330 /* (non-Javadoc) 325 /* (non-Javadoc)
java/common/com/mumfrey/liteloader/core/PluginChannels.java
@@ -11,6 +11,7 @@ import java.util.Map; @@ -11,6 +11,7 @@ import java.util.Map;
11 import java.util.Set; 11 import java.util.Set;
12 12
13 import com.mumfrey.liteloader.api.InterfaceProvider; 13 import com.mumfrey.liteloader.api.InterfaceProvider;
  14 +import com.mumfrey.liteloader.interfaces.FastIterableDeque;
14 import com.mumfrey.liteloader.util.log.LiteLoaderLogger; 15 import com.mumfrey.liteloader.util.log.LiteLoaderLogger;
15 16
16 import net.minecraft.network.INetHandler; 17 import net.minecraft.network.INetHandler;
@@ -34,31 +35,37 @@ public abstract class PluginChannels&lt;L extends CommonPluginChannelListener&gt; impl @@ -34,31 +35,37 @@ public abstract class PluginChannels&lt;L extends CommonPluginChannelListener&gt; impl
34 /** 35 /**
35 * Mapping of plugin channel names to listeners 36 * Mapping of plugin channel names to listeners
36 */ 37 */
37 - protected HashMap<String, LinkedList<L>> pluginChannels = new HashMap<String, LinkedList<L>>(); 38 + protected final HashMap<String, LinkedList<L>> pluginChannels = new HashMap<String, LinkedList<L>>();
38 39
39 /** 40 /**
40 * List of mods which implement PluginChannelListener interface 41 * List of mods which implement PluginChannelListener interface
41 */ 42 */
42 - protected LinkedList<L> pluginChannelListeners = new LinkedList<L>(); 43 + protected final FastIterableDeque<L> pluginChannelListeners;
43 44
44 /** 45 /**
45 * Plugin channels that we know the server supports 46 * Plugin channels that we know the server supports
46 */ 47 */
47 - protected Set<String> remotePluginChannels = new HashSet<String>(); 48 + protected final Set<String> remotePluginChannels = new HashSet<String>();
48 49
49 /** 50 /**
50 * Keep track of faulting listeners so that we can periodically log a message if a listener is throwing LOTS of exceptions 51 * Keep track of faulting listeners so that we can periodically log a message if a listener is throwing LOTS of exceptions
51 */ 52 */
52 - protected Map<L, Integer> faultingPluginChannelListeners = new HashMap<L, Integer>(); 53 + protected final Map<L, Integer> faultingPluginChannelListeners = new HashMap<L, Integer>();
53 54
54 /** 55 /**
55 * Package private 56 * Package private
56 */ 57 */
57 PluginChannels() 58 PluginChannels()
58 { 59 {
  60 + this.pluginChannelListeners = this.createHandlerList();
59 } 61 }
60 62
61 /** 63 /**
  64 + * @return
  65 + */
  66 + protected abstract FastIterableDeque<L> createHandlerList();
  67 +
  68 + /**
62 * Get the current set of registered client-side channels 69 * Get the current set of registered client-side channels
63 */ 70 */
64 public Set<String> getLocalChannels() 71 public Set<String> getLocalChannels()
@@ -90,10 +97,7 @@ public abstract class PluginChannels&lt;L extends CommonPluginChannelListener&gt; impl @@ -90,10 +97,7 @@ public abstract class PluginChannels&lt;L extends CommonPluginChannelListener&gt; impl
90 */ 97 */
91 protected void addPluginChannelListener(L pluginChannelListener) 98 protected void addPluginChannelListener(L pluginChannelListener)
92 { 99 {
93 - if (!this.pluginChannelListeners.contains(pluginChannelListener))  
94 - {  
95 - this.pluginChannelListeners.add(pluginChannelListener);  
96 - } 100 + this.pluginChannelListeners.add(pluginChannelListener);
97 } 101 }
98 102
99 /** 103 /**
java/common/com/mumfrey/liteloader/core/ServerPluginChannels.java
@@ -8,7 +8,9 @@ import net.minecraft.network.play.server.S3FPacketCustomPayload; @@ -8,7 +8,9 @@ import net.minecraft.network.play.server.S3FPacketCustomPayload;
8 8
9 import com.mumfrey.liteloader.ServerPluginChannelListener; 9 import com.mumfrey.liteloader.ServerPluginChannelListener;
10 import com.mumfrey.liteloader.api.Listener; 10 import com.mumfrey.liteloader.api.Listener;
  11 +import com.mumfrey.liteloader.core.event.HandlerList;
11 import com.mumfrey.liteloader.core.exceptions.UnregisteredChannelException; 12 import com.mumfrey.liteloader.core.exceptions.UnregisteredChannelException;
  13 +import com.mumfrey.liteloader.interfaces.FastIterableDeque;
12 import com.mumfrey.liteloader.permissions.PermissionsManagerServer; 14 import com.mumfrey.liteloader.permissions.PermissionsManagerServer;
13 import com.mumfrey.liteloader.util.log.LiteLoaderLogger; 15 import com.mumfrey.liteloader.util.log.LiteLoaderLogger;
14 16
@@ -24,10 +26,15 @@ public class ServerPluginChannels extends PluginChannels&lt;ServerPluginChannelList @@ -24,10 +26,15 @@ public class ServerPluginChannels extends PluginChannels&lt;ServerPluginChannelList
24 public ServerPluginChannels() 26 public ServerPluginChannels()
25 { 27 {
26 if (ServerPluginChannels.instance != null) throw new RuntimeException("Plugin Channels Startup Error", new InstantiationException("Only a single instance of ServerPluginChannels is allowed")); 28 if (ServerPluginChannels.instance != null) throw new RuntimeException("Plugin Channels Startup Error", new InstantiationException("Only a single instance of ServerPluginChannels is allowed"));
27 -  
28 ServerPluginChannels.instance = this; 29 ServerPluginChannels.instance = this;
29 } 30 }
30 31
  32 + @Override
  33 + protected FastIterableDeque<ServerPluginChannelListener> createHandlerList()
  34 + {
  35 + return new HandlerList<ServerPluginChannelListener>(ServerPluginChannelListener.class);
  36 + }
  37 +
31 public static ServerPluginChannels getInstance() 38 public static ServerPluginChannels getInstance()
32 { 39 {
33 return instance; 40 return instance;