Added a "canInject" property in the injectors.

This commit is contained in:
Kristian S. Stangeland 2012-09-26 02:01:44 +02:00
parent d8b300e3a6
commit 9e402a3ab4
4 changed files with 30 additions and 5 deletions

View File

@ -83,6 +83,13 @@ class NetworkFieldInjector extends PlayerInjector {
}
}
@Override
public boolean canInject() {
// Probably
return true;
}
@Override
public void injectManager() {

View File

@ -42,6 +42,14 @@ class NetworkObjectInjector extends PlayerInjector {
}
}
@Override
public boolean canInject() {
// We only support 1.3.0 at the moment. Fixing it require us to
// add jMock, which would add another dependency.
return networkManager != null &&
networkManagerField.getType().isInterface();
}
@Override
public void injectManager() {

View File

@ -67,7 +67,7 @@ public final class PacketFilterManager implements ProtocolManager {
/**
* Override the network handler object itself.
*/
NETWORK_MANAGER_OBJECT
NETWORK_MANAGER_OBJECT,
}
// Create a concurrent set
@ -362,16 +362,20 @@ public final class PacketFilterManager implements ProtocolManager {
* @throws IllegalAccessException Unable to do our reflection magic.
*/
protected PlayerInjector getPlayerHookInstance(Player player) throws IllegalAccessException {
return getHookInstance(player, playerHook);
}
// Helper
private PlayerInjector getHookInstance(Player player, PlayerInjectHooks hook) throws IllegalAccessException {
// Construct the correct player hook
switch (playerHook) {
switch (hook) {
case NETWORK_HANDLER_FIELDS:
return new NetworkFieldInjector(player, this, sendingFilters);
case NETWORK_MANAGER_OBJECT:
return new NetworkObjectInjector(player, this, sendingFilters);
default:
throw new IllegalArgumentException("Cannot construct a player injector.");
}
throw new IllegalArgumentException("Cannot construct a player injector.");
}
/**

View File

@ -190,6 +190,12 @@ abstract class PlayerInjector {
*/
public abstract void cleanupAll();
/**
* Determine if we actually can inject.
* @return TRUE if this injector is compatible with the current CraftBukkit version, FALSE otherwise.
*/
public abstract boolean canInject();
/**
* Allows a packet to be recieved by the listeners.
* @param packet - packet to recieve.