Commit 7b700b7b492aa7aaa2006a3e959ec92fdc787119
1 parent
189931b8
provider ServerData and RealmsServer in onJoinGame
Showing
10 changed files
with
92 additions
and
33 deletions
.classpath
... | ... | @@ -20,5 +20,6 @@ |
20 | 20 | <classpathentry exported="true" kind="lib" path="/Client/jars/libraries/org/lwjgl/lwjgl/lwjgl/2.9.1/lwjgl-2.9.1.jar"/> |
21 | 21 | <classpathentry exported="true" kind="lib" path="lib/asm-debug-all-5.0.3.jar"/> |
22 | 22 | <classpathentry exported="true" kind="lib" path="/Client/jars/libraries/org/lwjgl/lwjgl/lwjgl_util/2.9.1/lwjgl_util-2.9.1.jar"/> |
23 | + <classpathentry exported="true" kind="lib" path="/Client/jars/libraries/com/mojang/realms/1.5.5/realms-1.5.5.jar"/> | |
23 | 24 | <classpathentry kind="output" path="bin"/> |
24 | 25 | </classpath> | ... | ... |
java/common/com/mumfrey/liteloader/JoinGameListener.java renamed to java/client/com/mumfrey/liteloader/JoinGameListener.java
1 | 1 | package com.mumfrey.liteloader; |
2 | 2 | |
3 | +import net.minecraft.client.multiplayer.ServerData; | |
3 | 4 | import net.minecraft.network.INetHandler; |
4 | 5 | import net.minecraft.network.play.server.S01PacketJoinGame; |
5 | 6 | |
7 | +import com.mojang.realmsclient.dto.RealmsServer; | |
8 | + | |
6 | 9 | |
7 | 10 | /** |
8 | 11 | * Interface for mods which wish to be notified when the player connects to a server (or local game) |
... | ... | @@ -16,6 +19,8 @@ public interface JoinGameListener extends LiteMod |
16 | 19 | * |
17 | 20 | * @param netHandler Net handler |
18 | 21 | * @param joinGamePacket Join game packet |
22 | + * @param serverData ServerData object representing the server being connected to | |
23 | + * @param realmsServer If connecting to a realm, a reference to the RealmsServer object | |
19 | 24 | */ |
20 | - public abstract void onJoinGame(INetHandler netHandler, S01PacketJoinGame joinGamePacket); | |
25 | + public abstract void onJoinGame(INetHandler netHandler, S01PacketJoinGame joinGamePacket, ServerData serverData, RealmsServer realmsServer); | |
21 | 26 | } | ... | ... |
java/client/com/mumfrey/liteloader/client/PacketEventsClient.java
1 | 1 | package com.mumfrey.liteloader.client; |
2 | 2 | |
3 | +import net.minecraft.client.Minecraft; | |
3 | 4 | import net.minecraft.network.INetHandler; |
4 | 5 | import net.minecraft.network.Packet; |
5 | 6 | import net.minecraft.network.login.INetHandlerLoginClient; |
... | ... | @@ -10,8 +11,11 @@ import net.minecraft.network.play.server.S02PacketChat; |
10 | 11 | import net.minecraft.util.ChatComponentText; |
11 | 12 | import net.minecraft.util.IChatComponent; |
12 | 13 | |
14 | +import com.mojang.realmsclient.RealmsMainScreen; | |
15 | +import com.mojang.realmsclient.dto.RealmsServer; | |
13 | 16 | import com.mumfrey.liteloader.ChatFilter; |
14 | 17 | import com.mumfrey.liteloader.ChatListener; |
18 | +import com.mumfrey.liteloader.JoinGameListener; | |
15 | 19 | import com.mumfrey.liteloader.PostLoginListener; |
16 | 20 | import com.mumfrey.liteloader.PreJoinGameListener; |
17 | 21 | import com.mumfrey.liteloader.common.transformers.PacketEventInfo; |
... | ... | @@ -20,9 +24,11 @@ import com.mumfrey.liteloader.core.LiteLoaderEventBroker.ReturnValue; |
20 | 24 | import com.mumfrey.liteloader.core.InterfaceRegistrationDelegate; |
21 | 25 | import com.mumfrey.liteloader.core.LiteLoader; |
22 | 26 | import com.mumfrey.liteloader.core.PacketEvents; |
27 | +import com.mumfrey.liteloader.core.event.EventCancellationException; | |
23 | 28 | import com.mumfrey.liteloader.core.event.HandlerList; |
24 | 29 | import com.mumfrey.liteloader.core.event.HandlerList.ReturnLogicOp; |
25 | 30 | import com.mumfrey.liteloader.interfaces.FastIterableDeque; |
31 | +import com.mumfrey.liteloader.transformers.event.EventInfo; | |
26 | 32 | import com.mumfrey.liteloader.util.log.LiteLoaderLogger; |
27 | 33 | |
28 | 34 | /** |
... | ... | @@ -32,6 +38,9 @@ import com.mumfrey.liteloader.util.log.LiteLoaderLogger; |
32 | 38 | */ |
33 | 39 | public class PacketEventsClient extends PacketEvents |
34 | 40 | { |
41 | + private static RealmsServer joiningRealm; | |
42 | + | |
43 | + private FastIterableDeque<JoinGameListener> joinGameListeners = new HandlerList<JoinGameListener>(JoinGameListener.class); | |
35 | 44 | private FastIterableDeque<ChatListener> chatListeners = new HandlerList<ChatListener>(ChatListener.class); |
36 | 45 | private FastIterableDeque<ChatFilter> chatFilters = new HandlerList<ChatFilter>(ChatFilter.class, ReturnLogicOp.AND_BREAK_ON_FALSE); |
37 | 46 | private FastIterableDeque<PreJoinGameListener> preJoinGameListeners = new HandlerList<PreJoinGameListener>(PreJoinGameListener.class, ReturnLogicOp.OR); |
... | ... | @@ -42,11 +51,20 @@ public class PacketEventsClient extends PacketEvents |
42 | 51 | { |
43 | 52 | super.registerInterfaces(delegate); |
44 | 53 | |
54 | + delegate.registerInterface(JoinGameListener.class); | |
45 | 55 | delegate.registerInterface(ChatListener.class); |
46 | 56 | delegate.registerInterface(ChatFilter.class); |
47 | 57 | delegate.registerInterface(PreJoinGameListener.class); |
48 | 58 | delegate.registerInterface(PostLoginListener.class); |
49 | 59 | } |
60 | + | |
61 | + /** | |
62 | + * @param joinGameListener | |
63 | + */ | |
64 | + public void registerJoinGameListener(JoinGameListener joinGameListener) | |
65 | + { | |
66 | + this.joinGameListeners.add(joinGameListener); | |
67 | + } | |
50 | 68 | |
51 | 69 | /** |
52 | 70 | * @param chatFilter |
... | ... | @@ -86,28 +104,56 @@ public class PacketEventsClient extends PacketEvents |
86 | 104 | { |
87 | 105 | this.postLoginListeners.add(postLoginListener); |
88 | 106 | } |
89 | - | |
107 | + | |
108 | + public static void onJoinRealm(EventInfo<RealmsMainScreen> e, long arg1, RealmsServer server) | |
109 | + { | |
110 | + PacketEventsClient.joiningRealm = server; | |
111 | + } | |
112 | + | |
90 | 113 | /* (non-Javadoc) |
91 | 114 | * @see com.mumfrey.liteloader.core.PacketEvents#handlePacket(com.mumfrey.liteloader.common.transformers.PacketEventInfo, net.minecraft.network.INetHandler, net.minecraft.network.play.server.S01PacketJoinGame) |
92 | 115 | */ |
93 | 116 | @Override |
94 | 117 | protected void handlePacket(PacketEventInfo<Packet> e, INetHandler netHandler, S01PacketJoinGame packet) |
95 | 118 | { |
96 | - if (!(netHandler instanceof INetHandlerPlayClient)) | |
119 | + if (this.preJoinGame(e, netHandler, packet)) | |
97 | 120 | { |
98 | 121 | return; |
99 | 122 | } |
100 | 123 | |
101 | - e.cancel(); | |
124 | + ((INetHandlerPlayClient)netHandler).handleJoinGame(packet); | |
125 | + super.handlePacket(e, netHandler, packet); | |
126 | + | |
127 | + this.postJoinGame(e, netHandler, packet); | |
128 | + } | |
102 | 129 | |
103 | - if (this.preJoinGameListeners.all().onPreJoinGame(netHandler, packet)) | |
130 | + /** | |
131 | + * @param e | |
132 | + * @param netHandler | |
133 | + * @param packet | |
134 | + * @throws EventCancellationException | |
135 | + */ | |
136 | + private boolean preJoinGame(PacketEventInfo<Packet> e, INetHandler netHandler, S01PacketJoinGame packet) throws EventCancellationException | |
137 | + { | |
138 | + if (!(netHandler instanceof INetHandlerPlayClient)) | |
104 | 139 | { |
105 | - return; | |
140 | + return true; | |
106 | 141 | } |
107 | 142 | |
108 | - ((INetHandlerPlayClient)netHandler).handleJoinGame(packet); | |
109 | - | |
110 | - super.handlePacket(e, netHandler, packet); | |
143 | + e.cancel(); | |
144 | + | |
145 | + return this.preJoinGameListeners.all().onPreJoinGame(netHandler, packet); | |
146 | + } | |
147 | + | |
148 | + /** | |
149 | + * @param e | |
150 | + * @param netHandler | |
151 | + * @param packet | |
152 | + */ | |
153 | + private void postJoinGame(PacketEventInfo<Packet> e, INetHandler netHandler, S01PacketJoinGame packet) | |
154 | + { | |
155 | + this.joinGameListeners.all().onJoinGame(netHandler, packet, Minecraft.getMinecraft().getCurrentServerData(), PacketEventsClient.joiningRealm); | |
156 | + PacketEventsClient.joiningRealm = null; | |
111 | 157 | |
112 | 158 | ClientPluginChannels clientPluginChannels = LiteLoader.getClientPluginChannels(); |
113 | 159 | if (clientPluginChannels instanceof ClientPluginChannelsClient) | ... | ... |
java/client/com/mumfrey/liteloader/client/transformers/LiteLoaderEventInjectionTransformer.java
... | ... | @@ -54,6 +54,7 @@ public class LiteLoaderEventInjectionTransformer extends EventInjectionTransform |
54 | 54 | Event onSaveScreenshot = Event.getOrCreate("onSaveScreenshot", true); |
55 | 55 | Event onRenderEntity = Event.getOrCreate("onRenderEntity", false); |
56 | 56 | Event onPostRenderEntity = Event.getOrCreate("onPostRenderEntity", false); |
57 | + Event onJoinRealm = Event.getOrCreate("onJoinRealm", false); | |
57 | 58 | |
58 | 59 | // Injection Points |
59 | 60 | InjectionPoint methodHead = new MethodHead(); |
... | ... | @@ -67,6 +68,7 @@ public class LiteLoaderEventInjectionTransformer extends EventInjectionTransform |
67 | 68 | InjectionPoint beforeEndProfiler = new BeforeInvoke(endSection); |
68 | 69 | InjectionPoint beforeIsFBOEnabled = new BeforeInvoke(isFramebufferEnabled); |
69 | 70 | InjectionPoint beforeRenderEntity = new BeforeInvoke(doRender).setCaptureLocals(true); |
71 | + InjectionPoint beforeStopRealsmFetcher = new BeforeInvoke(realmsStopFetcher).setCaptureLocals(true); | |
70 | 72 | InjectionPoint beforeTickProfiler = new BeforeStringInvoke("tick", startSection); |
71 | 73 | InjectionPoint beforeCenterProfiler = new BeforeStringInvoke("center", startSection); |
72 | 74 | InjectionPoint beforeRenderProfiler = new BeforeStringInvoke("gameRenderer", endStartSection); |
... | ... | @@ -106,10 +108,26 @@ public class LiteLoaderEventInjectionTransformer extends EventInjectionTransform |
106 | 108 | |
107 | 109 | // Compatibility handlers |
108 | 110 | this.add(onSessionProfileBad, getProfile, (beforeNewGameProfile), "generateOfflineUUID"); |
111 | + | |
112 | + // Protocol handlers | |
113 | + this.add(onJoinRealm, realmsPlay, (beforeStopRealsmFetcher), "onJoinRealm", Obf.PacketEventsClient); | |
109 | 114 | } |
110 | 115 | |
111 | 116 | protected final Event add(Event event, MethodInfo targetMethod, InjectionPoint injectionPoint, String callback) |
112 | 117 | { |
113 | - return this.addEvent(event, targetMethod, injectionPoint).addListener(new MethodInfo(Obf.CallbackProxyClient, callback)); | |
118 | + return this.add(event, targetMethod, injectionPoint, callback, Obf.CallbackProxyClient); | |
119 | + } | |
120 | + | |
121 | + /** | |
122 | + * @param event | |
123 | + * @param targetMethod | |
124 | + * @param injectionPoint | |
125 | + * @param callback | |
126 | + * @param proxy | |
127 | + * @return | |
128 | + */ | |
129 | + private Event add(Event event, MethodInfo targetMethod, InjectionPoint injectionPoint, String callback, Obf proxy) | |
130 | + { | |
131 | + return this.addEvent(event, targetMethod, injectionPoint).addListener(new MethodInfo(proxy, callback)); | |
114 | 132 | } |
115 | 133 | } | ... | ... |
java/common/com/mumfrey/liteloader/PacketHandler.java
... | ... | @@ -18,9 +18,11 @@ public interface PacketHandler extends LiteMod |
18 | 18 | public List<Class<? extends Packet>> getHandledPackets(); |
19 | 19 | |
20 | 20 | /** |
21 | - * @param netHandler | |
22 | - * @param packet | |
23 | - * @return | |
21 | + * @param netHandler The vanilla nethandler which will handle this packet if not cancelled | |
22 | + * @param packet Incoming packet | |
23 | + * @return True to allow further processing of this packet, including other PacketHandlers and eventually the vanilla netHandler, to inhibit further | |
24 | + * processing return false. You may choose to return false and then invoke the vanilla handler method on the supplied INetHandler if you wish to | |
25 | + * inhibit later PacketHandlers but preserve vanilla behaviour. | |
24 | 26 | */ |
25 | 27 | public abstract boolean handlePacket(INetHandler netHandler, Packet packet); |
26 | 28 | } | ... | ... |
java/common/com/mumfrey/liteloader/PluginChannelListener.java
... | ... | @@ -9,7 +9,7 @@ import com.mumfrey.liteloader.core.CommonPluginChannelListener; |
9 | 9 | * |
10 | 10 | * @author Adam Mummery-Smith |
11 | 11 | */ |
12 | -public interface PluginChannelListener extends CommonPluginChannelListener, JoinGameListener | |
12 | +public interface PluginChannelListener extends LiteMod, CommonPluginChannelListener | |
13 | 13 | { |
14 | 14 | /** |
15 | 15 | * Called when a custom payload packet arrives on a channel this mod has registered | ... | ... |
java/common/com/mumfrey/liteloader/core/PacketEvents.java
... | ... | @@ -13,7 +13,6 @@ import net.minecraft.network.play.server.S01PacketJoinGame; |
13 | 13 | import net.minecraft.network.play.server.S02PacketChat; |
14 | 14 | import net.minecraft.network.play.server.S3FPacketCustomPayload; |
15 | 15 | |
16 | -import com.mumfrey.liteloader.JoinGameListener; | |
17 | 16 | import com.mumfrey.liteloader.PacketHandler; |
18 | 17 | import com.mumfrey.liteloader.ServerChatFilter; |
19 | 18 | import com.mumfrey.liteloader.api.InterfaceProvider; |
... | ... | @@ -23,7 +22,6 @@ import com.mumfrey.liteloader.core.event.HandlerList; |
23 | 22 | import com.mumfrey.liteloader.core.event.HandlerList.ReturnLogicOp; |
24 | 23 | import com.mumfrey.liteloader.core.runtime.Packets; |
25 | 24 | import com.mumfrey.liteloader.interfaces.FastIterable; |
26 | -import com.mumfrey.liteloader.interfaces.FastIterableDeque; | |
27 | 25 | import com.mumfrey.liteloader.util.log.LiteLoaderLogger; |
28 | 26 | |
29 | 27 | /** |
... | ... | @@ -34,7 +32,7 @@ import com.mumfrey.liteloader.util.log.LiteLoaderLogger; |
34 | 32 | public abstract class PacketEvents implements InterfaceProvider |
35 | 33 | { |
36 | 34 | protected static PacketEvents instance; |
37 | - | |
35 | + | |
38 | 36 | class PacketHandlerList extends HandlerList<PacketHandler> |
39 | 37 | { |
40 | 38 | private static final long serialVersionUID = 1L; |
... | ... | @@ -49,7 +47,6 @@ public abstract class PacketEvents implements InterfaceProvider |
49 | 47 | private PacketHandlerList packetHandlers[] = new PacketHandlerList[Packets.count()]; |
50 | 48 | |
51 | 49 | private FastIterable<ServerChatFilter> serverChatFilters = new HandlerList<ServerChatFilter>(ServerChatFilter.class, ReturnLogicOp.AND_BREAK_ON_FALSE); |
52 | - private FastIterableDeque<JoinGameListener> joinGameListeners = new HandlerList<JoinGameListener>(JoinGameListener.class); | |
53 | 50 | |
54 | 51 | private final int loginSuccessPacketId = Packets.S02PacketLoginSuccess.getIndex(); |
55 | 52 | private final int serverChatPacketId = Packets.S02PacketChat.getIndex(); |
... | ... | @@ -74,7 +71,6 @@ public abstract class PacketEvents implements InterfaceProvider |
74 | 71 | public void registerInterfaces(InterfaceRegistrationDelegate delegate) |
75 | 72 | { |
76 | 73 | delegate.registerInterface(PacketHandler.class); |
77 | - delegate.registerInterface(JoinGameListener.class); | |
78 | 74 | delegate.registerInterface(ServerChatFilter.class); |
79 | 75 | } |
80 | 76 | |
... | ... | @@ -82,14 +78,6 @@ public abstract class PacketEvents implements InterfaceProvider |
82 | 78 | public void initProvider() |
83 | 79 | { |
84 | 80 | } |
85 | - | |
86 | - /** | |
87 | - * @param joinGameListener | |
88 | - */ | |
89 | - public void registerJoinGameListener(JoinGameListener joinGameListener) | |
90 | - { | |
91 | - this.joinGameListeners.add(joinGameListener); | |
92 | - } | |
93 | 81 | |
94 | 82 | /** |
95 | 83 | * @param serverChatFilter |
... | ... | @@ -123,7 +111,7 @@ public abstract class PacketEvents implements InterfaceProvider |
123 | 111 | } |
124 | 112 | } |
125 | 113 | } |
126 | - | |
114 | + | |
127 | 115 | public static void handlePacket(PacketEventInfo<Packet> e, INetHandler netHandler) |
128 | 116 | { |
129 | 117 | PacketEvents.instance.handlePacket(e, netHandler, e.getPacketId()); |
... | ... | @@ -235,7 +223,6 @@ public abstract class PacketEvents implements InterfaceProvider |
235 | 223 | protected void handlePacket(PacketEventInfo<Packet> e, INetHandler netHandler, S01PacketJoinGame packet) |
236 | 224 | { |
237 | 225 | this.loader.onJoinGame(netHandler, packet); |
238 | - this.joinGameListeners.all().onJoinGame(netHandler, packet); | |
239 | 226 | } |
240 | 227 | |
241 | 228 | /** | ... | ... |
java/common/com/mumfrey/liteloader/core/runtime/Methods.java
... | ... | @@ -36,6 +36,8 @@ public abstract class Methods |
36 | 36 | public static final MethodInfo doRenderEntity = new MethodInfo(Obf.RenderManager, Obf.doRenderEntity, Boolean.TYPE, Obf.Entity, Double.TYPE, Double.TYPE, Double.TYPE, Float.TYPE, Float.TYPE, Boolean.TYPE); |
37 | 37 | public static final MethodInfo doRender = new MethodInfo(Obf.Render, Obf.doRender, Void.TYPE, Obf.Entity, Double.TYPE, Double.TYPE, Double.TYPE, Float.TYPE, Float.TYPE); |
38 | 38 | public static final MethodInfo doRenderShadowAndFire = new MethodInfo(Obf.Render, Obf.doRenderShadowAndFire, Void.TYPE, Obf.Entity, Double.TYPE, Double.TYPE, Double.TYPE, Float.TYPE, Float.TYPE); |
39 | + public static final MethodInfo realmsPlay = new MethodInfo(Obf.RealmsMainScreen, "play", Void.TYPE, Long.TYPE); | |
40 | + public static final MethodInfo realmsStopFetcher = new MethodInfo(Obf.RealmsMainScreen, "stopRealmsFetcherAndPinger", Void.TYPE); | |
39 | 41 | |
40 | 42 | public static final MethodInfo startSection = new MethodInfo(Obf.Profiler, Obf.startSection, Void.TYPE, String.class); |
41 | 43 | public static final MethodInfo endSection = new MethodInfo(Obf.Profiler, Obf.endSection, Void.TYPE); | ... | ... |
java/common/com/mumfrey/liteloader/core/runtime/Obf.java
... | ... | @@ -23,11 +23,13 @@ public class Obf |
23 | 23 | public static final Obf HandlerList = new Obf("com.mumfrey.liteloader.core.event.HandlerList" ); |
24 | 24 | public static final Obf BakedHandlerList = new Obf("com.mumfrey.liteloader.core.event.HandlerList$BakedHandlerList" ); |
25 | 25 | public static final Obf PacketEvents = new Obf("com.mumfrey.liteloader.core.PacketEvents" ); |
26 | + public static final Obf PacketEventsClient = new Obf("com.mumfrey.liteloader.client.PacketEventsClient" ); | |
26 | 27 | public static final Obf LoadingBar = new Obf("com.mumfrey.liteloader.client.gui.startup.LoadingBar" ); |
27 | 28 | public static final Obf GameProfile = new Obf("com.mojang.authlib.GameProfile" ); |
28 | 29 | public static final Obf MinecraftMain = new Obf("net.minecraft.client.main.Main" ); |
29 | 30 | public static final Obf MinecraftServer = new Obf("net.minecraft.server.MinecraftServer" ); |
30 | 31 | public static final Obf GL11 = new Obf("org.lwjgl.opengl.GL11" ); |
32 | + public static final Obf RealmsMainScreen = new Obf("com.mojang.realmsclient.RealmsMainScreen" ); | |
31 | 33 | public static final Obf constructor = new Obf("<init>" ); |
32 | 34 | |
33 | 35 | // Classes | ... | ... |
java/common/com/mumfrey/liteloader/permissions/PermissionsManagerClient.java
... | ... | @@ -178,10 +178,6 @@ public class PermissionsManagerClient implements PermissionsManager, PluginChann |
178 | 178 | this.registeredClientPermissions.put(mod, new TreeSet<String>()); |
179 | 179 | } |
180 | 180 | |
181 | - /* (non-Javadoc) | |
182 | - * @see com.mumfrey.liteloader.JoinGameListener#onJoinGame(net.minecraft.network.INetHandler, net.minecraft.network.play.server.S01PacketJoinGame) | |
183 | - */ | |
184 | - @Override | |
185 | 181 | public void onJoinGame(INetHandler netHandler, S01PacketJoinGame joinGamePacket) |
186 | 182 | { |
187 | 183 | this.clearServerPermissions(); | ... | ... |