Commit 3810e8964c0494422aff7310a8c8ba558ee0c196
1 parent
2a83f2dc
handle login success packet asynchronously, closes #72
Showing
3 changed files
with
32 additions
and
6 deletions
java/client/com/mumfrey/liteloader/PostLoginListener.java
@@ -9,5 +9,12 @@ import net.minecraft.network.login.server.S02PacketLoginSuccess; | @@ -9,5 +9,12 @@ import net.minecraft.network.login.server.S02PacketLoginSuccess; | ||
9 | */ | 9 | */ |
10 | public interface PostLoginListener extends LiteMod | 10 | public interface PostLoginListener extends LiteMod |
11 | { | 11 | { |
12 | + /** | ||
13 | + * Called immediately after login, before the player has properly joined the game. Note that this event is raised | ||
14 | + * <b>in the network thread</b> and is not marshalled to the main thread as other packet-generated events are. | ||
15 | + * | ||
16 | + * @param netHandler | ||
17 | + * @param packet | ||
18 | + */ | ||
12 | public abstract void onPostLogin(INetHandlerLoginClient netHandler, S02PacketLoginSuccess packet); | 19 | public abstract void onPostLogin(INetHandlerLoginClient netHandler, S02PacketLoginSuccess packet); |
13 | } | 20 | } |
java/common/com/mumfrey/liteloader/core/LiteLoader.java
@@ -44,6 +44,7 @@ import com.mumfrey.liteloader.interfaces.LoaderEnumerator; | @@ -44,6 +44,7 @@ import com.mumfrey.liteloader.interfaces.LoaderEnumerator; | ||
44 | import com.mumfrey.liteloader.interfaces.ObjectFactory; | 44 | import com.mumfrey.liteloader.interfaces.ObjectFactory; |
45 | import com.mumfrey.liteloader.interfaces.PanelManager; | 45 | import com.mumfrey.liteloader.interfaces.PanelManager; |
46 | import com.mumfrey.liteloader.launch.LoaderEnvironment; | 46 | import com.mumfrey.liteloader.launch.LoaderEnvironment; |
47 | +import com.mumfrey.liteloader.launch.LoaderEnvironment.EnvironmentType; | ||
47 | import com.mumfrey.liteloader.launch.LoaderProperties; | 48 | import com.mumfrey.liteloader.launch.LoaderProperties; |
48 | import com.mumfrey.liteloader.messaging.MessageBus; | 49 | import com.mumfrey.liteloader.messaging.MessageBus; |
49 | import com.mumfrey.liteloader.modconfig.ConfigManager; | 50 | import com.mumfrey.liteloader.modconfig.ConfigManager; |
@@ -486,6 +487,14 @@ public final class LiteLoader | @@ -486,6 +487,14 @@ public final class LiteLoader | ||
486 | } | 487 | } |
487 | 488 | ||
488 | /** | 489 | /** |
490 | + * Get the type of environment (client or dedicated server) | ||
491 | + */ | ||
492 | + public static EnvironmentType getEnvironmentType() | ||
493 | + { | ||
494 | + return LiteLoader.instance.environment.getType(); | ||
495 | + } | ||
496 | + | ||
497 | + /** | ||
489 | * Used to get the name of the modpack being used | 498 | * Used to get the name of the modpack being used |
490 | * | 499 | * |
491 | * @return name of the modpack in use or null if no pack | 500 | * @return name of the modpack in use or null if no pack |
java/common/com/mumfrey/liteloader/core/PacketEvents.java
@@ -126,6 +126,7 @@ public abstract class PacketEvents implements InterfaceProvider | @@ -126,6 +126,7 @@ public abstract class PacketEvents implements InterfaceProvider | ||
126 | IThreadListener threadListener = this.getPacketContextListener(packetInfo.getContext()); | 126 | IThreadListener threadListener = this.getPacketContextListener(packetInfo.getContext()); |
127 | if (threadListener != null && !threadListener.isCallingFromMinecraftThread()) | 127 | if (threadListener != null && !threadListener.isCallingFromMinecraftThread()) |
128 | { | 128 | { |
129 | + this.handleAsyncPacketEvent(e, netHandler, packetId); | ||
129 | return; | 130 | return; |
130 | } | 131 | } |
131 | 132 | ||
@@ -146,24 +147,33 @@ public abstract class PacketEvents implements InterfaceProvider | @@ -146,24 +147,33 @@ public abstract class PacketEvents implements InterfaceProvider | ||
146 | * @param context | 147 | * @param context |
147 | */ | 148 | */ |
148 | protected abstract IThreadListener getPacketContextListener(Packets.Context context); | 149 | protected abstract IThreadListener getPacketContextListener(Packets.Context context); |
149 | - | 150 | + |
150 | /** | 151 | /** |
151 | * @param e | 152 | * @param e |
152 | * @param netHandler | 153 | * @param netHandler |
153 | * @param packetId | 154 | * @param packetId |
154 | - * | ||
155 | - * @return true if the packet was handled by a local handler and shouldn't be forwarded to later handlers | ||
156 | */ | 155 | */ |
157 | - protected boolean handlePacketEvent(PacketEventInfo<Packet> e, INetHandler netHandler, int packetId) | 156 | + protected void handleAsyncPacketEvent(PacketEventInfo<Packet> e, INetHandler netHandler, int packetId) |
158 | { | 157 | { |
159 | Packet packet = e.getSource(); | 158 | Packet packet = e.getSource(); |
160 | 159 | ||
161 | if (packetId == this.loginSuccessPacketId) | 160 | if (packetId == this.loginSuccessPacketId) |
162 | { | 161 | { |
163 | this.handlePacket(e, netHandler, (S02PacketLoginSuccess)packet); | 162 | this.handlePacket(e, netHandler, (S02PacketLoginSuccess)packet); |
164 | - return true; | ||
165 | } | 163 | } |
166 | - | 164 | + } |
165 | + | ||
166 | + /** | ||
167 | + * @param e | ||
168 | + * @param netHandler | ||
169 | + * @param packetId | ||
170 | + * | ||
171 | + * @return true if the packet was handled by a local handler and shouldn't be forwarded to later handlers | ||
172 | + */ | ||
173 | + protected boolean handlePacketEvent(PacketEventInfo<Packet> e, INetHandler netHandler, int packetId) | ||
174 | + { | ||
175 | + Packet packet = e.getSource(); | ||
176 | + | ||
167 | if (packetId == this.serverChatPacketId) | 177 | if (packetId == this.serverChatPacketId) |
168 | { | 178 | { |
169 | this.handlePacket(e, netHandler, (S02PacketChat)packet); | 179 | this.handlePacket(e, netHandler, (S02PacketChat)packet); |