mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-22 20:03:21 +00:00
Fix FieldFetch
not getting fields from superclasses
This commit is contained in:
parent
27be6c31e6
commit
3c0e834348
@ -1,8 +1,5 @@
|
||||
package emu.grasscutter.utils;
|
||||
|
||||
import static emu.grasscutter.utils.FileUtils.getResourcePath;
|
||||
import static emu.grasscutter.utils.lang.Language.translate;
|
||||
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.config.ConfigContainer;
|
||||
import emu.grasscutter.data.DataLoader;
|
||||
@ -11,15 +8,20 @@ import emu.grasscutter.utils.objects.Returnable;
|
||||
import io.javalin.http.Context;
|
||||
import io.netty.buffer.*;
|
||||
import it.unimi.dsi.fastutil.ints.*;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Field;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.*;
|
||||
import java.time.*;
|
||||
import java.time.temporal.TemporalAdjusters;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import javax.annotation.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import static emu.grasscutter.utils.FileUtils.getResourcePath;
|
||||
import static emu.grasscutter.utils.lang.Language.translate;
|
||||
|
||||
@SuppressWarnings({"UnusedReturnValue", "BooleanMethodIsAlwaysInverted"})
|
||||
public final class Utils {
|
||||
@ -484,6 +486,7 @@ public final class Utils {
|
||||
*
|
||||
* @param runnable The task to run.
|
||||
*/
|
||||
@SuppressWarnings("BusyWait")
|
||||
public static void waitFor(Returnable<Boolean> runnable) {
|
||||
while (!runnable.invoke()) {
|
||||
try {
|
||||
@ -493,4 +496,23 @@ public final class Utils {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively finds all fields in a class.
|
||||
*
|
||||
* @param type The class to find fields in.
|
||||
* @return A list of all fields in the class.
|
||||
*/
|
||||
public static List<Field> getAllFields(Class<?> type) {
|
||||
var fields = new LinkedList<>(
|
||||
Arrays.asList(type.getDeclaredFields())
|
||||
);
|
||||
|
||||
// Check for superclasses.
|
||||
if (type.getSuperclass() != null) {
|
||||
fields.addAll(getAllFields(type.getSuperclass()));
|
||||
}
|
||||
|
||||
return fields;
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
package emu.grasscutter.utils.objects;
|
||||
|
||||
import com.google.gson.JsonNull;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.*;
|
||||
import emu.grasscutter.server.dispatch.IDispatcher;
|
||||
import emu.grasscutter.utils.Utils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.*;
|
||||
|
||||
public interface FieldFetch {
|
||||
/**
|
||||
@ -18,7 +18,7 @@ public interface FieldFetch {
|
||||
// Prepare field properties.
|
||||
var fieldValues = new JsonObject();
|
||||
var fieldMap = new HashMap<String, Field>();
|
||||
Arrays.stream(this.getClass().getDeclaredFields())
|
||||
Utils.getAllFields(this.getClass())
|
||||
.forEach(field -> fieldMap.put(field.getName(), field));
|
||||
|
||||
// Find the values of all requested fields.
|
||||
|
Loading…
Reference in New Issue
Block a user