Don't throw a NullPointerException if the injection fails.

This commit is contained in:
Kristian S. Stangeland 2013-02-26 19:14:40 +01:00
parent 3357fd6c9c
commit 56807cbd3a
2 changed files with 16 additions and 6 deletions

View File

@ -78,10 +78,13 @@ class NetLoginInjector {
// This is the case if we're dealing with a connection initiated by the injected server socket // This is the case if we're dealing with a connection initiated by the injected server socket
if (socketInjector != null) { if (socketInjector != null) {
PlayerInjector injector = injectionHandler.injectPlayer(socketInjector.getPlayer(), inserting, GamePhase.LOGIN); PlayerInjector injector = injectionHandler.injectPlayer(socketInjector.getPlayer(), inserting, GamePhase.LOGIN);
injector.updateOnLogin = true;
if (injector != null) {
// Save the login injector.updateOnLogin = true;
injectedLogins.putIfAbsent(inserting, injector);
// Save the login
injectedLogins.putIfAbsent(inserting, injector);
}
} }
// NetServerInjector can never work (currently), so we don't need to replace the NetLoginHandler // NetServerInjector can never work (currently), so we don't need to replace the NetLoginHandler
@ -90,7 +93,7 @@ class NetLoginInjector {
} catch (Throwable e) { } catch (Throwable e) {
// Minecraft can't handle this, so we'll deal with it here // Minecraft can't handle this, so we'll deal with it here
reporter.reportDetailed(this, "Unable to hook " + reporter.reportDetailed(this, "Unable to hook " +
MinecraftReflection.getNetLoginHandlerName() + ".", e, inserting); MinecraftReflection.getNetLoginHandlerName() + ".", e, inserting, injectionHandler);
return inserting; return inserting;
} }
} }

View File

@ -269,6 +269,13 @@ class ProxyPlayerInjectionHandler implements PlayerInjectionHandler {
* @return The resulting player injector, or NULL if the injection failed. * @return The resulting player injector, or NULL if the injection failed.
*/ */
PlayerInjector injectPlayer(Player player, Object injectionPoint, GamePhase phase) { PlayerInjector injectPlayer(Player player, Object injectionPoint, GamePhase phase) {
if (player == null)
throw new IllegalArgumentException("Player cannot be NULL.");
if (injectionPoint == null)
throw new IllegalArgumentException("injectionPoint cannot be NULL.");
if (phase == null)
throw new IllegalArgumentException("phase cannot be NULL.");
// Unfortunately, due to NetLoginHandler, multiple threads may potentially call this method. // Unfortunately, due to NetLoginHandler, multiple threads may potentially call this method.
synchronized (player) { synchronized (player) {
return injectPlayerInternal(player, injectionPoint, phase); return injectPlayerInternal(player, injectionPoint, phase);
@ -288,7 +295,7 @@ class ProxyPlayerInjectionHandler implements PlayerInjectionHandler {
boolean invalidInjector = injector != null ? !injector.canInject(phase) : true; boolean invalidInjector = injector != null ? !injector.canInject(phase) : true;
// Don't inject if the class has closed // Don't inject if the class has closed
if (!hasClosed && player != null && (tempHook != getInjectorType(injector) || invalidInjector)) { if (!hasClosed && (tempHook != getInjectorType(injector) || invalidInjector)) {
while (tempHook != PlayerInjectHooks.NONE) { while (tempHook != PlayerInjectHooks.NONE) {
// Whether or not the current hook method failed completely // Whether or not the current hook method failed completely
boolean hookFailed = false; boolean hookFailed = false;