mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-11-24 03:25:29 +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());
|
||||
}
|
||||
|
||||
private PacketConstructor(Constructor<?> constructorMethod, List<Unwrapper> unwrappers) {
|
||||
private PacketConstructor(int packetID, Constructor<?> constructorMethod, List<Unwrapper> unwrappers) {
|
||||
this.packetID = packetID;
|
||||
this.constructorMethod = constructorMethod;
|
||||
this.unwrappers = unwrappers;
|
||||
}
|
||||
@ -65,7 +66,7 @@ public class PacketConstructor {
|
||||
* @return A constructor with a different set of unwrappers.
|
||||
*/
|
||||
public PacketConstructor withUnwrappers(List<Unwrapper> unwrappers) {
|
||||
return new PacketConstructor(constructorMethod, unwrappers);
|
||||
return new PacketConstructor(packetID, constructorMethod, unwrappers);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -75,18 +76,29 @@ public class PacketConstructor {
|
||||
* @return A packet constructor 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++) {
|
||||
// Default type
|
||||
if (values[i] != null) {
|
||||
types[i] = values[i].getClass();
|
||||
|
||||
for (Unwrapper unwrapper : unwrappers) {
|
||||
Class<?> result = unwrapper.unwrapType(types[i]);
|
||||
Object result = unwrapper.unwrapItem(values[i]);
|
||||
|
||||
// Update type we're searching for
|
||||
if (result != null) {
|
||||
types[i] = result;
|
||||
types[i] = result.getClass();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// Try it
|
||||
types[i] = Object.class;
|
||||
}
|
||||
}
|
||||
|
||||
Class<?> packetType = MinecraftRegistry.getPacketClassFromID(id);
|
||||
@ -100,7 +112,7 @@ public class PacketConstructor {
|
||||
|
||||
if (isCompatible(types, params)) {
|
||||
// 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) {
|
||||
|
||||
// See if we're already determined this
|
||||
@ -230,6 +227,5 @@ public class PacketConstructor {
|
||||
|
||||
public static interface Unwrapper {
|
||||
public Object unwrapItem(Object wrappedObject);
|
||||
public Class<?> unwrapType(Class<?> type);
|
||||
}
|
||||
}
|
||||
|
@ -328,14 +328,7 @@ public final class PacketFilterManager implements ProtocolManager {
|
||||
|
||||
@Override
|
||||
public PacketConstructor createPacketConstructor(int id, Object... arguments) {
|
||||
Class<?>[] types = new Class<?>[arguments.length];
|
||||
|
||||
// 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);
|
||||
return PacketConstructor.DEFAULT.withPacket(id, arguments);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user