mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2026-05-18 20:19:55 +08:00
Funnel all gson calls into helper functions
Add deprecated getGsonFactory for plugin compat until 3.0
This commit is contained in:
committed by
Luke H-W
Unverified
parent
76fcbb477b
commit
c6323e9759
@@ -15,6 +15,7 @@ import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class DataLoader {
|
||||
|
||||
@@ -69,6 +70,24 @@ public class DataLoader {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static <T> T loadClass(String resourcePath, Class<T> classType) throws IOException {
|
||||
try (InputStreamReader reader = loadReader(resourcePath)) {
|
||||
return Utils.loadJsonToClass(reader, classType);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> List<T> loadList(String resourcePath, Class<T> classType) throws IOException {
|
||||
try (InputStreamReader reader = loadReader(resourcePath)) {
|
||||
return Utils.loadJsonToList(reader, classType);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T1,T2> Map<T1,T2> loadMap(String resourcePath, Class<T1> keyType, Class<T2> valueType) throws IOException {
|
||||
try (InputStreamReader reader = loadReader(resourcePath)) {
|
||||
return Utils.loadJsonToMap(reader, keyType, valueType);
|
||||
}
|
||||
}
|
||||
|
||||
public static void checkAllFiles() {
|
||||
try {
|
||||
List<Path> filenames = FileUtils.getPathsFromResource("/defaults/data/");
|
||||
|
||||
Reference in New Issue
Block a user