forked from Limework/skript-db
Fixed missing 'string' field in Skript 2.8
This commit is contained in:
parent
2dc1f70f4f
commit
41881dbb7d
@ -14,24 +14,22 @@ public class SkriptUtil {
|
|||||||
private static final Field EXPR;
|
private static final Field EXPR;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
Field _FIELD = null;
|
STRING = tryGetOldStringField()
|
||||||
try {
|
.or(() -> tryGetNewStringField())
|
||||||
_FIELD = VariableString.class.getDeclaredField("string");
|
.orElseGet(() -> {
|
||||||
_FIELD.setAccessible(true);
|
|
||||||
} catch (NoSuchFieldException e) {
|
|
||||||
Skript.error("Skript's 'string' field could not be resolved.");
|
Skript.error("Skript's 'string' field could not be resolved.");
|
||||||
e.printStackTrace();
|
return null;
|
||||||
}
|
});
|
||||||
STRING = _FIELD;
|
|
||||||
|
|
||||||
|
Field f = null;
|
||||||
try {
|
try {
|
||||||
Optional<Class<?>> expressionInfo = Arrays.stream(VariableString.class.getDeclaredClasses())
|
Optional<Class<?>> expressionInfo = Arrays.stream(VariableString.class.getDeclaredClasses())
|
||||||
.filter(cls -> cls.getSimpleName().equals("ExpressionInfo"))
|
.filter(cls -> cls.getSimpleName().equals("ExpressionInfo"))
|
||||||
.findFirst();
|
.findFirst();
|
||||||
if (expressionInfo.isPresent()) {
|
if (expressionInfo.isPresent()) {
|
||||||
Class<?> expressionInfoClass = expressionInfo.get();
|
Class<?> expressionInfoClass = expressionInfo.get();
|
||||||
_FIELD = expressionInfoClass.getDeclaredField("expr");
|
f = expressionInfoClass.getDeclaredField("expr");
|
||||||
_FIELD.setAccessible(true);
|
f.setAccessible(true);
|
||||||
} else {
|
} else {
|
||||||
Skript.error("Skript's 'ExpressionInfo' class could not be resolved.");
|
Skript.error("Skript's 'ExpressionInfo' class could not be resolved.");
|
||||||
}
|
}
|
||||||
@ -39,7 +37,7 @@ public class SkriptUtil {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Skript.error("Skript's 'expr' field could not be resolved.");
|
Skript.error("Skript's 'expr' field could not be resolved.");
|
||||||
}
|
}
|
||||||
EXPR = _FIELD;
|
EXPR = f;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object[] getTemplateString(VariableString vs) {
|
public static Object[] getTemplateString(VariableString vs) {
|
||||||
@ -58,4 +56,24 @@ public class SkriptUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Optional<Field> tryGetOldStringField() {
|
||||||
|
try {
|
||||||
|
Field f = VariableString.class.getDeclaredField("string");
|
||||||
|
f.setAccessible(true);
|
||||||
|
return Optional.of(f);
|
||||||
|
} catch (NoSuchFieldException e) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Optional<Field> tryGetNewStringField() {
|
||||||
|
try {
|
||||||
|
Field f = VariableString.class.getDeclaredField("strings");
|
||||||
|
f.setAccessible(true);
|
||||||
|
return Optional.of(f);
|
||||||
|
} catch (NoSuchFieldException e) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user