mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-11-24 19:46:33 +01:00
Correctly override SpoutPlugin's sendPacket method.
This commit is contained in:
parent
4406cdb571
commit
a798147e71
@ -2,7 +2,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.comphenix.protocol</groupId>
|
<groupId>com.comphenix.protocol</groupId>
|
||||||
<artifactId>ProtocolLib</artifactId>
|
<artifactId>ProtocolLib</artifactId>
|
||||||
<version>2.3.0</version>
|
<version>2.3.1-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<description>Provides read/write access to the Minecraft protocol.</description>
|
<description>Provides read/write access to the Minecraft protocol.</description>
|
||||||
|
|
||||||
@ -219,16 +219,16 @@
|
|||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.powermock</groupId>
|
<groupId>org.powermock</groupId>
|
||||||
<artifactId>powermock-module-junit4</artifactId>
|
<artifactId>powermock-module-junit4</artifactId>
|
||||||
<version>${powermock.version}</version>
|
<version>${powermock.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.powermock</groupId>
|
<groupId>org.powermock</groupId>
|
||||||
<artifactId>powermock-api-mockito</artifactId>
|
<artifactId>powermock-api-mockito</artifactId>
|
||||||
<version>${powermock.version}</version>
|
<version>${powermock.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
@ -20,6 +20,8 @@ package com.comphenix.protocol.injector.player;
|
|||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
import net.sf.cglib.proxy.*;
|
import net.sf.cglib.proxy.*;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -45,8 +47,8 @@ import com.comphenix.protocol.utility.MinecraftReflection;
|
|||||||
* @author Kristian
|
* @author Kristian
|
||||||
*/
|
*/
|
||||||
class NetworkServerInjector extends PlayerInjector {
|
class NetworkServerInjector extends PlayerInjector {
|
||||||
|
|
||||||
private volatile static CallbackFilter callbackFilter;
|
private volatile static CallbackFilter callbackFilter;
|
||||||
|
private volatile static boolean foundSendPacket;
|
||||||
|
|
||||||
private volatile static Field disconnectField;
|
private volatile static Field disconnectField;
|
||||||
private InjectedServerConnection serverInjection;
|
private InjectedServerConnection serverInjection;
|
||||||
@ -168,10 +170,12 @@ class NetworkServerInjector extends PlayerInjector {
|
|||||||
callbackFilter = new CallbackFilter() {
|
callbackFilter = new CallbackFilter() {
|
||||||
@Override
|
@Override
|
||||||
public int accept(Method method) {
|
public int accept(Method method) {
|
||||||
if (method.equals(sendPacket))
|
if (isCallableEqual(sendPacket, method)) {
|
||||||
|
foundSendPacket = true;
|
||||||
return 0;
|
return 0;
|
||||||
else
|
} else {
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -204,8 +208,10 @@ class NetworkServerInjector extends PlayerInjector {
|
|||||||
|
|
||||||
// Inject it now
|
// Inject it now
|
||||||
if (proxyObject != null) {
|
if (proxyObject != null) {
|
||||||
// This will be done by InjectedServerConnection instead
|
// Did we override a sendPacket method?
|
||||||
//copyTo(serverHandler, proxyObject);
|
if (!foundSendPacket) {
|
||||||
|
throw new IllegalArgumentException("Unable to find a sendPacket method in " + serverClass);
|
||||||
|
}
|
||||||
|
|
||||||
serverInjection.replaceServerHandler(serverHandler, proxyObject);
|
serverInjection.replaceServerHandler(serverHandler, proxyObject);
|
||||||
serverHandlerRef.setValue(proxyObject);
|
serverHandlerRef.setValue(proxyObject);
|
||||||
@ -215,6 +221,20 @@ class NetworkServerInjector extends PlayerInjector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if the two methods are equal in terms of call semantics.
|
||||||
|
* <p>
|
||||||
|
* Two methods are equal if they have the same name, parameter types and return type.
|
||||||
|
* @param first - first method.
|
||||||
|
* @param second - second method.
|
||||||
|
* @return TRUE if they are, FALSE otherwise.
|
||||||
|
*/
|
||||||
|
private boolean isCallableEqual(Method first, Method second) {
|
||||||
|
return first.getName().equals(second.getName()) &&
|
||||||
|
first.getReturnType().equals(second.getReturnType()) &&
|
||||||
|
Arrays.equals(first.getParameterTypes(), second.getParameterTypes());
|
||||||
|
}
|
||||||
|
|
||||||
private Object getProxyServerHandler() {
|
private Object getProxyServerHandler() {
|
||||||
if (proxyServerField != null && !proxyServerField.equals(serverHandlerRef.getField())) {
|
if (proxyServerField != null && !proxyServerField.equals(serverHandlerRef.getField())) {
|
||||||
try {
|
try {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
name: ProtocolLib
|
name: ProtocolLib
|
||||||
version: 2.3.0
|
version: 2.3.1-SNAPSHOT
|
||||||
description: Provides read/write access to the Minecraft protocol.
|
description: Provides read/write access to the Minecraft protocol.
|
||||||
author: Comphenix
|
author: Comphenix
|
||||||
website: http://www.comphenix.net/ProtocolLib
|
website: http://www.comphenix.net/ProtocolLib
|
||||||
|
Loading…
Reference in New Issue
Block a user