Fixed the old server listener.

This commit is contained in:
Kristian S. Stangeland 2012-09-16 02:07:18 +02:00
parent 913ff7eed1
commit b299886b62
2 changed files with 28 additions and 13 deletions

View File

@ -22,8 +22,6 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;

View File

@ -436,18 +436,20 @@ public final class PacketFilterManager implements ProtocolManager {
// The player listener! Good times. // The player listener! Good times.
Class<?> playerListener = loader.loadClass("org.bukkit.event.player.PlayerListener"); Class<?> playerListener = loader.loadClass("org.bukkit.event.player.PlayerListener");
Class<?> serverListener = loader.loadClass("org.bukkit.event.server.ServerListener");
// Find the register event method // Find the register event method
Method registerEvent = FuzzyReflection.fromObject(manager).getMethodByParameters("registerEvent", Method registerEvent = FuzzyReflection.fromObject(manager).getMethodByParameters("registerEvent",
eventTypes, Listener.class, eventPriority, Plugin.class); eventTypes, Listener.class, eventPriority, Plugin.class);
Enhancer ex = new Enhancer(); Enhancer playerEx = new Enhancer();
ex.setSuperclass(playerListener); Enhancer serverEx = new Enhancer();
ex.setClassLoader(classLoader);
ex.setCallback(new MethodInterceptor() { playerEx.setSuperclass(playerListener);
playerEx.setClassLoader(classLoader);
playerEx.setCallback(new MethodInterceptor() {
@Override @Override
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable { public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
// Must have a parameter // Must have a parameter
if (args.length == 1) { if (args.length == 1) {
Object event = args[0]; Object event = args[0];
@ -457,20 +459,35 @@ public final class PacketFilterManager implements ProtocolManager {
injectPlayer(((PlayerJoinEvent) event).getPlayer()); injectPlayer(((PlayerJoinEvent) event).getPlayer());
else if (event instanceof PlayerQuitEvent) else if (event instanceof PlayerQuitEvent)
injectPlayer(((PlayerQuitEvent) event).getPlayer()); injectPlayer(((PlayerQuitEvent) event).getPlayer());
else if (event instanceof PluginDisableEvent) }
return null;
}
});
serverEx.setSuperclass(serverListener);
serverEx.setClassLoader(classLoader);
serverEx.setCallback(new MethodInterceptor() {
@Override
public Object intercept(Object obj, Method method, Object[] args,
MethodProxy proxy) throws Throwable {
// Must have a parameter
if (args.length == 1) {
Object event = args[0];
if (event instanceof PluginDisableEvent)
removePacketListeners(((PluginDisableEvent) event).getPlugin()); removePacketListeners(((PluginDisableEvent) event).getPlugin());
} }
return null; return null;
} }
}); });
// Create our listener // Create our listener
Object proxy = ex.create(); Object playerProxy = playerEx.create();
Object serverProxy = serverEx.create();
registerEvent.invoke(manager, playerJoinType, proxy, priorityNormal, plugin); registerEvent.invoke(manager, playerJoinType, playerProxy, priorityNormal, plugin);
registerEvent.invoke(manager, playerQuitType, proxy, priorityNormal, plugin); registerEvent.invoke(manager, playerQuitType, playerProxy, priorityNormal, plugin);
registerEvent.invoke(manager, pluginDisabledType, proxy, priorityNormal, plugin); registerEvent.invoke(manager, pluginDisabledType, serverProxy, priorityNormal, plugin);
// A lot can go wrong // A lot can go wrong
} catch (ClassNotFoundException e1) { } catch (ClassNotFoundException e1) {