mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-12-18 09:54:59 +01:00
Fix bad casting exceptions with scene garbages objects
This commit is contained in:
@@ -2,6 +2,9 @@ package emu.grasscutter.scripts.serializer;
|
||||
|
||||
import com.esotericsoftware.reflectasm.ConstructorAccess;
|
||||
import com.esotericsoftware.reflectasm.MethodAccess;
|
||||
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.scripts.ScriptUtils;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
@@ -9,6 +12,8 @@ import lombok.experimental.FieldDefaults;
|
||||
import org.luaj.vm2.LuaTable;
|
||||
import org.luaj.vm2.LuaValue;
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@@ -31,6 +36,10 @@ public class LuaSerializer implements Serializer {
|
||||
public <T> List<T> serializeList(Class<T> type, LuaTable table) {
|
||||
List<T> list = new ArrayList<>();
|
||||
|
||||
if (table == null) {
|
||||
return list;
|
||||
}
|
||||
|
||||
try {
|
||||
LuaValue[] keys = table.keys();
|
||||
for (LuaValue k : keys) {
|
||||
@@ -79,7 +88,7 @@ public class LuaSerializer implements Serializer {
|
||||
}
|
||||
|
||||
try {
|
||||
if(!methodAccessCache.containsKey(type)){
|
||||
if (!methodAccessCache.containsKey(type)) {
|
||||
cacheType(type);
|
||||
}
|
||||
var methodAccess = methodAccessCache.get(type);
|
||||
@@ -87,9 +96,10 @@ public class LuaSerializer implements Serializer {
|
||||
|
||||
object = (T) constructorCache.get(type).newInstance();
|
||||
|
||||
if(table == null){
|
||||
if (table == null) {
|
||||
return object;
|
||||
}
|
||||
|
||||
LuaValue[] keys = table.keys();
|
||||
for (LuaValue k : keys) {
|
||||
try {
|
||||
@@ -117,6 +127,7 @@ public class LuaSerializer implements Serializer {
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Grasscutter.getLogger().info(ScriptUtils.toMap(table).toString());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user