mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-11-09 04:09:43 +01:00
Merge branch 'master' into gh-pages
This commit is contained in:
commit
cdcb7ce656
@ -42,7 +42,8 @@ public class PacketConstructor {
|
|||||||
this.unwrappers = Lists.newArrayList((Unwrapper) new BukkitUnwrapper());
|
this.unwrappers = Lists.newArrayList((Unwrapper) new BukkitUnwrapper());
|
||||||
}
|
}
|
||||||
|
|
||||||
private PacketConstructor(Constructor<?> constructorMethod, List<Unwrapper> unwrappers) {
|
private PacketConstructor(int packetID, Constructor<?> constructorMethod, List<Unwrapper> unwrappers) {
|
||||||
|
this.packetID = packetID;
|
||||||
this.constructorMethod = constructorMethod;
|
this.constructorMethod = constructorMethod;
|
||||||
this.unwrappers = unwrappers;
|
this.unwrappers = unwrappers;
|
||||||
}
|
}
|
||||||
@ -65,7 +66,7 @@ public class PacketConstructor {
|
|||||||
* @return A constructor with a different set of unwrappers.
|
* @return A constructor with a different set of unwrappers.
|
||||||
*/
|
*/
|
||||||
public PacketConstructor withUnwrappers(List<Unwrapper> unwrappers) {
|
public PacketConstructor withUnwrappers(List<Unwrapper> unwrappers) {
|
||||||
return new PacketConstructor(constructorMethod, unwrappers);
|
return new PacketConstructor(packetID, constructorMethod, unwrappers);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -75,17 +76,28 @@ public class PacketConstructor {
|
|||||||
* @return A packet constructor with these types.
|
* @return A packet constructor with these types.
|
||||||
* @throws IllegalArgumentException If no packet constructor could be created with these types.
|
* @throws IllegalArgumentException If no packet constructor could be created with these types.
|
||||||
*/
|
*/
|
||||||
public PacketConstructor withPacket(int id, Class<?>[] types) {
|
public PacketConstructor withPacket(int id, Object[] values) {
|
||||||
|
|
||||||
|
Class<?>[] types = new Class<?>[values.length];
|
||||||
|
|
||||||
for (int i = 0; i < types.length; i++) {
|
for (int i = 0; i < types.length; i++) {
|
||||||
for (Unwrapper unwrapper : unwrappers) {
|
// Default type
|
||||||
Class<?> result = unwrapper.unwrapType(types[i]);
|
if (values[i] != null) {
|
||||||
|
types[i] = values[i].getClass();
|
||||||
|
|
||||||
// Update type we're searching for
|
for (Unwrapper unwrapper : unwrappers) {
|
||||||
if (result != null) {
|
Object result = unwrapper.unwrapItem(values[i]);
|
||||||
types[i] = result;
|
|
||||||
break;
|
// Update type we're searching for
|
||||||
|
if (result != null) {
|
||||||
|
types[i] = result.getClass();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// Try it
|
||||||
|
types[i] = Object.class;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +112,7 @@ public class PacketConstructor {
|
|||||||
|
|
||||||
if (isCompatible(types, params)) {
|
if (isCompatible(types, params)) {
|
||||||
// Right, we've found our type
|
// Right, we've found our type
|
||||||
return new PacketConstructor(constructor, unwrappers);
|
return new PacketConstructor(id, constructor, unwrappers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,21 +202,6 @@ public class PacketConstructor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Class<?> unwrapType(Class<?> type) {
|
|
||||||
|
|
||||||
if (type == null)
|
|
||||||
throw new IllegalArgumentException("type cannot be null.");
|
|
||||||
|
|
||||||
Method unwrapped = initializeCache(type);
|
|
||||||
|
|
||||||
// Determine the unwrapped type
|
|
||||||
if (unwrapped != null)
|
|
||||||
return unwrapped.getReturnType();
|
|
||||||
else
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Method initializeCache(Class<?> type) {
|
private Method initializeCache(Class<?> type) {
|
||||||
|
|
||||||
// See if we're already determined this
|
// See if we're already determined this
|
||||||
@ -230,6 +227,5 @@ public class PacketConstructor {
|
|||||||
|
|
||||||
public static interface Unwrapper {
|
public static interface Unwrapper {
|
||||||
public Object unwrapItem(Object wrappedObject);
|
public Object unwrapItem(Object wrappedObject);
|
||||||
public Class<?> unwrapType(Class<?> type);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -328,14 +328,7 @@ public final class PacketFilterManager implements ProtocolManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PacketConstructor createPacketConstructor(int id, Object... arguments) {
|
public PacketConstructor createPacketConstructor(int id, Object... arguments) {
|
||||||
Class<?>[] types = new Class<?>[arguments.length];
|
return PacketConstructor.DEFAULT.withPacket(id, arguments);
|
||||||
|
|
||||||
// Initialize types
|
|
||||||
for (int i = 0; i < arguments.length; i++) {
|
|
||||||
types[i] = arguments[i] != null ? arguments[i].getClass() : Object.class;
|
|
||||||
}
|
|
||||||
|
|
||||||
return PacketConstructor.DEFAULT.withPacket(id, types);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user