From 56807cbd3a6f5e7f36b9534a31c3bef79d3950ce Mon Sep 17 00:00:00 2001 From: "Kristian S. Stangeland" Date: Tue, 26 Feb 2013 19:14:40 +0100 Subject: [PATCH] Don't throw a NullPointerException if the injection fails. --- .../protocol/injector/player/NetLoginInjector.java | 13 ++++++++----- .../player/ProxyPlayerInjectionHandler.java | 9 ++++++++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/NetLoginInjector.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/NetLoginInjector.java index db454e15..f7f669be 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/NetLoginInjector.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/NetLoginInjector.java @@ -78,10 +78,13 @@ class NetLoginInjector { // This is the case if we're dealing with a connection initiated by the injected server socket if (socketInjector != null) { PlayerInjector injector = injectionHandler.injectPlayer(socketInjector.getPlayer(), inserting, GamePhase.LOGIN); - injector.updateOnLogin = true; - - // Save the login - injectedLogins.putIfAbsent(inserting, injector); + + if (injector != null) { + injector.updateOnLogin = true; + + // Save the login + injectedLogins.putIfAbsent(inserting, injector); + } } // NetServerInjector can never work (currently), so we don't need to replace the NetLoginHandler @@ -90,7 +93,7 @@ class NetLoginInjector { } catch (Throwable e) { // Minecraft can't handle this, so we'll deal with it here reporter.reportDetailed(this, "Unable to hook " + - MinecraftReflection.getNetLoginHandlerName() + ".", e, inserting); + MinecraftReflection.getNetLoginHandlerName() + ".", e, inserting, injectionHandler); return inserting; } } diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/ProxyPlayerInjectionHandler.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/ProxyPlayerInjectionHandler.java index 62da9e9b..5a2b4c45 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/ProxyPlayerInjectionHandler.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/player/ProxyPlayerInjectionHandler.java @@ -269,6 +269,13 @@ class ProxyPlayerInjectionHandler implements PlayerInjectionHandler { * @return The resulting player injector, or NULL if the injection failed. */ 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. synchronized (player) { return injectPlayerInternal(player, injectionPoint, phase); @@ -288,7 +295,7 @@ class ProxyPlayerInjectionHandler implements PlayerInjectionHandler { boolean invalidInjector = injector != null ? !injector.canInject(phase) : true; // 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) { // Whether or not the current hook method failed completely boolean hookFailed = false;