Commit b4c52de03b8444ad6674ca81b584d2ae3bb103eb
1 parent
58a0b663
switch everything possible to HandlerList
Showing
7 changed files
with
78 additions
and
122 deletions
java/client/com/mumfrey/liteloader/client/ClientEvents.java
| ... | ... | @@ -28,6 +28,8 @@ import com.mumfrey.liteloader.core.Events; |
| 28 | 28 | import com.mumfrey.liteloader.core.InterfaceRegistrationDelegate; |
| 29 | 29 | import com.mumfrey.liteloader.core.LiteLoader; |
| 30 | 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 | 33 | import com.mumfrey.liteloader.launch.LoaderProperties; |
| 32 | 34 | import com.mumfrey.liteloader.transformers.event.EventInfo; |
| 33 | 35 | import com.mumfrey.liteloader.util.log.LiteLoaderLogger; |
| ... | ... | @@ -82,22 +84,22 @@ public class ClientEvents extends Events<Minecraft, IntegratedServer> |
| 82 | 84 | */ |
| 83 | 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 | 104 | @SuppressWarnings("cast") |
| 103 | 105 | public ClientEvents(LiteLoader loader, GameEngineClient engine, LoaderProperties properties) |
| ... | ... | @@ -251,10 +253,7 @@ public class ClientEvents extends Events<Minecraft, IntegratedServer> |
| 251 | 253 | */ |
| 252 | 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<Minecraft, IntegratedServer> |
| 596 | 595 | */ |
| 597 | 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<Minecraft, IntegratedServer> |
| 627 | 625 | */ |
| 628 | 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 | 5 | |
| 6 | 6 | import com.mumfrey.liteloader.PluginChannelListener; |
| 7 | 7 | import com.mumfrey.liteloader.api.Listener; |
| 8 | +import com.mumfrey.liteloader.core.event.HandlerList; | |
| 9 | +import com.mumfrey.liteloader.interfaces.FastIterableDeque; | |
| 8 | 10 | import com.mumfrey.liteloader.permissions.PermissionsManagerClient; |
| 9 | 11 | import com.mumfrey.liteloader.util.log.LiteLoaderLogger; |
| 10 | 12 | |
| ... | ... | @@ -19,8 +21,15 @@ public abstract class ClientPluginChannels extends PluginChannels<PluginChannelL |
| 19 | 21 | |
| 20 | 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 | 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 | 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 | 29 | import com.mumfrey.liteloader.common.GameEngine; |
| 30 | 30 | import com.mumfrey.liteloader.common.LoadingProgress; |
| 31 | 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 | 34 | import com.mumfrey.liteloader.launch.LoaderProperties; |
| 33 | 35 | import com.mumfrey.liteloader.util.log.LiteLoaderLogger; |
| 34 | 36 | |
| ... | ... | @@ -60,17 +62,17 @@ public abstract class Events<TClient, TServer extends MinecraftServer> implement |
| 60 | 62 | /** |
| 61 | 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 | 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 | 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 | 78 | * Package private ctor |
| ... | ... | @@ -157,10 +159,7 @@ public abstract class Events<TClient, TServer extends MinecraftServer> implement |
| 157 | 159 | */ |
| 158 | 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<TClient, TServer extends MinecraftServer> implement |
| 196 | 195 | { |
| 197 | 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 | 4 | import java.io.PrintStream; |
| 5 | 5 | import java.util.ArrayList; |
| 6 | 6 | import java.util.Collection; |
| 7 | -import java.util.LinkedList; | |
| 8 | 7 | import java.util.List; |
| 9 | 8 | |
| 10 | 9 | import javax.activity.InvalidActivityException; |
| ... | ... | @@ -35,9 +34,11 @@ import com.mumfrey.liteloader.common.GameEngine; |
| 35 | 34 | import com.mumfrey.liteloader.common.LoadingProgress; |
| 36 | 35 | import com.mumfrey.liteloader.core.api.LiteLoaderCoreAPI; |
| 37 | 36 | import com.mumfrey.liteloader.core.event.EventProxy; |
| 37 | +import com.mumfrey.liteloader.core.event.HandlerList; | |
| 38 | 38 | import com.mumfrey.liteloader.crashreport.CallableLaunchWrapper; |
| 39 | 39 | import com.mumfrey.liteloader.crashreport.CallableLiteLoaderBrand; |
| 40 | 40 | import com.mumfrey.liteloader.crashreport.CallableLiteLoaderMods; |
| 41 | +import com.mumfrey.liteloader.interfaces.FastIterableDeque; | |
| 41 | 42 | import com.mumfrey.liteloader.interfaces.Loadable; |
| 42 | 43 | import com.mumfrey.liteloader.interfaces.LoadableMod; |
| 43 | 44 | import com.mumfrey.liteloader.interfaces.LoaderEnumerator; |
| ... | ... | @@ -128,27 +129,11 @@ public final class LiteLoader |
| 128 | 129 | /** |
| 129 | 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 | 139 | * Mod panel manager, deliberately raw |
| ... | ... | @@ -245,10 +230,7 @@ public final class LiteLoader |
| 245 | 230 | this.shutdownObservers.addAll(this.apiAdapter.getAllObservers(ShutdownObserver.class)); |
| 246 | 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 | 235 | this.enumerator.onInit(); |
| 254 | 236 | this.mods.init(this.apiAdapter.getAllObservers(ModLoadObserver.class)); |
| ... | ... | @@ -273,10 +255,7 @@ public final class LiteLoader |
| 273 | 255 | // Spawn mod instances and initialise them |
| 274 | 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 | 260 | // Save stuff |
| 282 | 261 | this.properties.writeProperties(); |
| ... | ... | @@ -884,10 +863,7 @@ public final class LiteLoader |
| 884 | 863 | */ |
| 885 | 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 | 868 | this.interfaceManager.registerInterfaces(); |
| 893 | 869 | } |
| ... | ... | @@ -950,10 +926,7 @@ public final class LiteLoader |
| 950 | 926 | { |
| 951 | 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 | 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 | 953 | void onPostRender(int mouseX, int mouseY, float partialTicks) |
| 984 | 954 | { |
| 985 | 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 | 957 | this.profiler.endSection(); |
| 993 | 958 | } |
| 994 | 959 | |
| ... | ... | @@ -1020,10 +985,7 @@ public final class LiteLoader |
| 1020 | 985 | |
| 1021 | 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 | 990 | this.profiler.endSection(); |
| 1029 | 991 | } |
| ... | ... | @@ -1032,10 +994,7 @@ public final class LiteLoader |
| 1032 | 994 | { |
| 1033 | 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 | 999 | this.configManager.syncConfig(); |
| 1041 | 1000 | } | ... | ... |
java/common/com/mumfrey/liteloader/core/LiteLoaderInterfaceManager.java
| ... | ... | @@ -4,7 +4,6 @@ import java.lang.reflect.Method; |
| 4 | 4 | import java.util.ArrayList; |
| 5 | 5 | import java.util.HashMap; |
| 6 | 6 | import java.util.Iterator; |
| 7 | -import java.util.LinkedList; | |
| 8 | 7 | import java.util.List; |
| 9 | 8 | import java.util.Map; |
| 10 | 9 | |
| ... | ... | @@ -15,6 +14,8 @@ import com.mumfrey.liteloader.api.LiteAPI; |
| 15 | 14 | import com.mumfrey.liteloader.api.Observer; |
| 16 | 15 | import com.mumfrey.liteloader.api.exceptions.InvalidProviderException; |
| 17 | 16 | import com.mumfrey.liteloader.api.manager.APIAdapter; |
| 17 | +import com.mumfrey.liteloader.core.event.HandlerList; | |
| 18 | +import com.mumfrey.liteloader.interfaces.FastIterable; | |
| 18 | 19 | import com.mumfrey.liteloader.interfaces.InterfaceRegistry; |
| 19 | 20 | import com.mumfrey.liteloader.util.log.LiteLoaderLogger; |
| 20 | 21 | |
| ... | ... | @@ -152,10 +153,7 @@ public class LiteLoaderInterfaceManager implements InterfaceRegistry |
| 152 | 153 | |
| 153 | 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 | 158 | return true; |
| 161 | 159 | } |
| ... | ... | @@ -197,7 +195,7 @@ public class LiteLoaderInterfaceManager implements InterfaceRegistry |
| 197 | 195 | /** |
| 198 | 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 | 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 | 319 | */ |
| 322 | 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 | 325 | /* (non-Javadoc) | ... | ... |
java/common/com/mumfrey/liteloader/core/PluginChannels.java
| ... | ... | @@ -11,6 +11,7 @@ import java.util.Map; |
| 11 | 11 | import java.util.Set; |
| 12 | 12 | |
| 13 | 13 | import com.mumfrey.liteloader.api.InterfaceProvider; |
| 14 | +import com.mumfrey.liteloader.interfaces.FastIterableDeque; | |
| 14 | 15 | import com.mumfrey.liteloader.util.log.LiteLoaderLogger; |
| 15 | 16 | |
| 16 | 17 | import net.minecraft.network.INetHandler; |
| ... | ... | @@ -34,31 +35,37 @@ public abstract class PluginChannels<L extends CommonPluginChannelListener> impl |
| 34 | 35 | /** |
| 35 | 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 | 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 | 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 | 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 | 56 | * Package private |
| 56 | 57 | */ |
| 57 | 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 | 69 | * Get the current set of registered client-side channels |
| 63 | 70 | */ |
| 64 | 71 | public Set<String> getLocalChannels() |
| ... | ... | @@ -90,10 +97,7 @@ public abstract class PluginChannels<L extends CommonPluginChannelListener> impl |
| 90 | 97 | */ |
| 91 | 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 | 8 | |
| 9 | 9 | import com.mumfrey.liteloader.ServerPluginChannelListener; |
| 10 | 10 | import com.mumfrey.liteloader.api.Listener; |
| 11 | +import com.mumfrey.liteloader.core.event.HandlerList; | |
| 11 | 12 | import com.mumfrey.liteloader.core.exceptions.UnregisteredChannelException; |
| 13 | +import com.mumfrey.liteloader.interfaces.FastIterableDeque; | |
| 12 | 14 | import com.mumfrey.liteloader.permissions.PermissionsManagerServer; |
| 13 | 15 | import com.mumfrey.liteloader.util.log.LiteLoaderLogger; |
| 14 | 16 | |
| ... | ... | @@ -24,10 +26,15 @@ public class ServerPluginChannels extends PluginChannels<ServerPluginChannelList |
| 24 | 26 | public ServerPluginChannels() |
| 25 | 27 | { |
| 26 | 28 | if (ServerPluginChannels.instance != null) throw new RuntimeException("Plugin Channels Startup Error", new InstantiationException("Only a single instance of ServerPluginChannels is allowed")); |
| 27 | - | |
| 28 | 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 | 38 | public static ServerPluginChannels getInstance() |
| 32 | 39 | { |
| 33 | 40 | return instance; | ... | ... |