Events.java
9.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
package com.mumfrey.liteloader.core;
import java.util.LinkedList;
import net.minecraft.client.resources.IResourceManager;
import net.minecraft.client.resources.IResourceManagerReloadListener;
import net.minecraft.command.ICommandManager;
import net.minecraft.command.ServerCommandManager;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.INetHandler;
import net.minecraft.network.NetHandlerPlayServer;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.INetHandlerPlayServer;
import net.minecraft.network.play.client.C01PacketChatMessage;
import net.minecraft.network.play.server.S01PacketJoinGame;
import net.minecraft.profiler.Profiler;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.management.ServerConfigurationManager;
import net.minecraft.world.World;
import net.minecraft.world.WorldSettings;
import com.mojang.authlib.GameProfile;
import com.mumfrey.liteloader.LiteMod;
import com.mumfrey.liteloader.PluginChannelListener;
import com.mumfrey.liteloader.ServerChatFilter;
import com.mumfrey.liteloader.ServerCommandProvider;
import com.mumfrey.liteloader.ServerPlayerListener;
import com.mumfrey.liteloader.ServerPluginChannelListener;
import com.mumfrey.liteloader.api.InterfaceProvider;
import com.mumfrey.liteloader.api.Listener;
import com.mumfrey.liteloader.common.GameEngine;
import com.mumfrey.liteloader.common.LoadingProgress;
import com.mumfrey.liteloader.launch.LoaderProperties;
import com.mumfrey.liteloader.util.log.LiteLoaderLogger;
/**
* @author Adam Mummery-Smith
*
* @param <TClient> Type of the client runtime, "Minecraft" on client and null on the server
* @param <TServer> Type of the server runtime, "IntegratedServer" on the client, "MinecraftServer" on the server
*/
public abstract class Events<TClient, TServer extends MinecraftServer> implements InterfaceProvider, IResourceManagerReloadListener
{
/**
* Reference to the loader instance
*/
protected final LiteLoader loader;
/**
* Reference to the game
*/
protected final GameEngine<TClient, TServer> engine;
/**
* Profiler
*/
protected final Profiler profiler;
protected LiteLoaderMods mods;
/**
* List of mods which can filter server chat
*/
private LinkedList<ServerChatFilter> serverChatFilters = new LinkedList<ServerChatFilter>();
/**
* List of mods which provide server commands
*/
private LinkedList<ServerCommandProvider> serverCommandProviders = new LinkedList<ServerCommandProvider>();
/**
* List of mods which monitor server player events
*/
private LinkedList<ServerPlayerListener> serverPlayerListeners = new LinkedList<ServerPlayerListener>();
/**
* Package private ctor
*
* @param loader
* @param minecraft
*/
public Events(LiteLoader loader, GameEngine<TClient, TServer> engine, LoaderProperties properties)
{
this.loader = loader;
this.engine = engine;
this.profiler = engine.getProfiler();
}
/**
* @param mods
*/
void setMods(LiteLoaderMods mods)
{
this.mods = mods;
}
/**
*
*/
protected void onStartupComplete()
{
LoadingProgress.setMessage("Initialising CoreProviders...");
this.loader.onStartupComplete();
LoadingProgress.setMessage("Starting Game...");
}
/**
* @param listener
* @deprecated Use LiteLoader.getInterfaceManager().registerListener() instead
*/
@Deprecated
public void addListener(LiteMod listener)
{
LiteLoader.getInterfaceManager().registerListener(listener);
}
/* (non-Javadoc)
* @see com.mumfrey.liteloader.api.InterfaceProvider#getListenerBaseType()
*/
@Override
public Class<? extends Listener> getListenerBaseType()
{
return LiteMod.class;
}
/* (non-Javadoc)
* @see com.mumfrey.liteloader.api.InterfaceProvider#registerInterfaces(com.mumfrey.liteloader.core.InterfaceRegistrationDelegate)
*/
@Override
public void registerInterfaces(InterfaceRegistrationDelegate delegate)
{
delegate.registerInterface(ServerChatFilter.class);
delegate.registerInterface(ServerCommandProvider.class);
delegate.registerInterface(ServerPlayerListener.class);
delegate.registerInterface(CommonPluginChannelListener.class);
}
/**
* Add a listener to the relevant listener lists
*
* @param listener
*/
public void addCommonPluginChannelListener(CommonPluginChannelListener listener)
{
if (!(listener instanceof PluginChannelListener) && !(listener instanceof ServerPluginChannelListener))
{
LiteLoaderLogger.warning("Interface error for mod '%1s'. Implementing CommonPluginChannelListener has no effect! Use PluginChannelListener or ServerPluginChannelListener instead", listener.getName());
}
}
/**
* @param serverChatFilter
*/
public void addServerChatFilter(ServerChatFilter serverChatFilter)
{
if (!this.serverChatFilters.contains(serverChatFilter))
{
this.serverChatFilters.add(serverChatFilter);
}
}
/**
* @param serverCommandProvider
*/
public void addServerCommandProvider(ServerCommandProvider serverCommandProvider)
{
if (!this.serverCommandProviders.contains(serverCommandProvider))
{
this.serverCommandProviders.add(serverCommandProvider);
}
}
/**
* @param serverPlayerListener
*/
public void addServerPlayerListener(ServerPlayerListener serverPlayerListener)
{
if (!this.serverPlayerListeners.contains(serverPlayerListener))
{
this.serverPlayerListeners.add(serverPlayerListener);
}
}
@Override
public void onResourceManagerReload(IResourceManager resourceManager)
{
LoadingProgress.setMessage("Reloading Resources...");
}
/**
* Callback from the chat hook
* @param netHandler
*
* @param chatPacket
* @return
*/
public boolean onServerChat(INetHandlerPlayServer netHandler, C01PacketChatMessage chatPacket)
{
EntityPlayerMP player = netHandler instanceof NetHandlerPlayServer ? ((NetHandlerPlayServer)netHandler).playerEntity : null;
for (ServerChatFilter chatFilter : this.serverChatFilters)
{
if (!chatFilter.onChat(player, chatPacket, chatPacket.func_149439_c()))
{
return false;
}
}
return true;
}
/**
* @param instance
* @param folderName
* @param worldName
* @param worldSettings
*/
public void onStartServer(MinecraftServer instance, String folderName, String worldName, WorldSettings worldSettings)
{
ICommandManager commandManager = instance.getCommandManager();
if (commandManager instanceof ServerCommandManager)
{
ServerCommandManager serverCommandManager = (ServerCommandManager)commandManager;
for (ServerCommandProvider commandProvider : this.serverCommandProviders)
commandProvider.provideCommands(serverCommandManager);
}
LiteLoader.getServerPluginChannels().onServerStartup();
}
/**
* @param scm
* @param player
* @param profile
*/
public void onSpawnPlayer(ServerConfigurationManager scm, EntityPlayerMP player, GameProfile profile)
{
for (ServerPlayerListener serverPlayerListener : this.serverPlayerListeners)
serverPlayerListener.onPlayerConnect(player, profile);
}
/**
* @param scm
* @param player
*/
public void onPlayerLogin(ServerConfigurationManager scm, EntityPlayerMP player)
{
LiteLoader.getServerPluginChannels().onPlayerJoined(player);
}
/**
* @param scm
* @param netManager
* @param player
*/
public void onInitializePlayerConnection(ServerConfigurationManager scm, NetworkManager netManager, EntityPlayerMP player)
{
for (ServerPlayerListener serverPlayerListener : this.serverPlayerListeners)
serverPlayerListener.onPlayerLoggedIn(player);
}
/**
* @param scm
* @param player
* @param oldPlayer
* @param dimension
* @param copy
*/
public void onRespawnPlayer(ServerConfigurationManager scm, EntityPlayerMP player, EntityPlayerMP oldPlayer, int dimension, boolean won)
{
for (ServerPlayerListener serverPlayerListener : this.serverPlayerListeners)
serverPlayerListener.onPlayerRespawn(player, oldPlayer, dimension, won);
}
/**
* @param scm
* @param player
*/
public void onPlayerLogout(ServerConfigurationManager scm, EntityPlayerMP player)
{
for (ServerPlayerListener serverPlayerListener : this.serverPlayerListeners)
serverPlayerListener.onPlayerLogout(player);
}
protected void onTick(boolean clock, float partialTicks, boolean inGame)
{
this.loader.onTick(clock, partialTicks, inGame);
}
protected void onPostRender(int mouseX, int mouseY, float partialTicks)
{
this.loader.onPostRender(mouseX, mouseY, partialTicks);
}
protected void onWorldChanged(World world)
{
this.loader.onWorldChanged(world);
}
protected void onJoinGame(INetHandler netHandler, S01PacketJoinGame loginPacket)
{
this.loader.onJoinGame(netHandler, loginPacket);
}
/**
* @deprecated use LiteLoader.getInterfaceManager().registerListener(listener); instead
* @param chatFilter
*/
@Deprecated
public void addChatFilter(Object chatFilter)
{
}
/**
* @deprecated use LiteLoader.getInterfaceManager().registerListener(listener); instead
* @param tickListener
*/
@Deprecated
public void addTickListener(Object tickListener)
{
}
}