mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-11-27 21:26:17 +01:00
parent
f093c9196d
commit
11247f1c01
@ -453,6 +453,17 @@ public class StructureModifier<TField> {
|
|||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <T> StructureModifier<T> withType(Class fieldType, EquivalentConverter<T> converter) {
|
public <T> StructureModifier<T> withType(Class fieldType, EquivalentConverter<T> converter) {
|
||||||
|
if (fieldType == null) {
|
||||||
|
// It's not supported in this version, so return an empty modifier
|
||||||
|
return new StructureModifier<T>() {
|
||||||
|
@Override
|
||||||
|
public T read(int index) { return null; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StructureModifier<T> write(int index, T value) { return this; }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
StructureModifier<T> result = subtypeCache.get(fieldType);
|
StructureModifier<T> result = subtypeCache.get(fieldType);
|
||||||
|
|
||||||
// Do we need to update the cache?
|
// Do we need to update the cache?
|
||||||
@ -462,7 +473,7 @@ public class StructureModifier<TField> {
|
|||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
||||||
for (Field field : data) {
|
for (Field field : data) {
|
||||||
if (fieldType != null && fieldType.isAssignableFrom(field.getType())) {
|
if (fieldType.isAssignableFrom(field.getType())) {
|
||||||
filtered.add(field);
|
filtered.add(field);
|
||||||
|
|
||||||
// Don't use the original index
|
// Don't use the original index
|
||||||
@ -477,14 +488,12 @@ public class StructureModifier<TField> {
|
|||||||
// Cache structure modifiers
|
// Cache structure modifiers
|
||||||
result = withFieldType(fieldType, filtered, defaults);
|
result = withFieldType(fieldType, filtered, defaults);
|
||||||
|
|
||||||
if (fieldType != null) {
|
|
||||||
subtypeCache.put(fieldType, result);
|
subtypeCache.put(fieldType, result);
|
||||||
|
|
||||||
// Automatically compile the structure modifier
|
// Automatically compile the structure modifier
|
||||||
if (useStructureCompiler && BackgroundCompiler.getInstance() != null)
|
if (useStructureCompiler && BackgroundCompiler.getInstance() != null)
|
||||||
BackgroundCompiler.getInstance().scheduleCompilation(subtypeCache, fieldType);
|
BackgroundCompiler.getInstance().scheduleCompilation(subtypeCache, fieldType);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Add the target too
|
// Add the target too
|
||||||
result = result.withTarget(target);
|
result = result.withTarget(target);
|
||||||
|
Loading…
Reference in New Issue
Block a user