mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-19 15:09:18 +00:00
dynamically resolve snippet classes
This commit is contained in:
@@ -50,8 +50,7 @@ import java.io.FileReader;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Objects;
|
import java.util.*;
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class IrisData implements ExclusionStrategy, TypeAdapterFactory {
|
public class IrisData implements ExclusionStrategy, TypeAdapterFactory {
|
||||||
@@ -407,6 +406,33 @@ public class IrisData implements ExclusionStrategy, TypeAdapterFactory {
|
|||||||
possibleSnippets.clear();
|
possibleSnippets.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Set<Class<?>> resolveSnippets() {
|
||||||
|
var result = new HashSet<Class<?>>();
|
||||||
|
var processed = new HashSet<Class<?>>();
|
||||||
|
var excluder = gson.excluder();
|
||||||
|
|
||||||
|
var queue = new LinkedList<Class<?>>(loaders.keySet());
|
||||||
|
while (!queue.isEmpty()) {
|
||||||
|
var type = queue.poll();
|
||||||
|
if (excluder.excludeClass(type, false) || !processed.add(type))
|
||||||
|
continue;
|
||||||
|
if (type.isAnnotationPresent(Snippet.class))
|
||||||
|
result.add(type);
|
||||||
|
|
||||||
|
try {
|
||||||
|
for (var field : type.getDeclaredFields()) {
|
||||||
|
if (excluder.excludeField(field, false))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
queue.add(field.getType());
|
||||||
|
}
|
||||||
|
} catch (Throwable ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public String toLoadKey(File f) {
|
public String toLoadKey(File f) {
|
||||||
if (f.getPath().startsWith(getDataFolder().getPath())) {
|
if (f.getPath().startsWith(getDataFolder().getPath())) {
|
||||||
String[] full = f.getPath().split("\\Q" + File.separator + "\\E");
|
String[] full = f.getPath().split("\\Q" + File.separator + "\\E");
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import com.volmit.iris.core.IrisSettings;
|
|||||||
import com.volmit.iris.core.loader.IrisData;
|
import com.volmit.iris.core.loader.IrisData;
|
||||||
import com.volmit.iris.core.loader.IrisRegistrant;
|
import com.volmit.iris.core.loader.IrisRegistrant;
|
||||||
import com.volmit.iris.core.loader.ResourceLoader;
|
import com.volmit.iris.core.loader.ResourceLoader;
|
||||||
import com.volmit.iris.core.scripting.environment.SimpleEnvironment;
|
|
||||||
import com.volmit.iris.core.tools.IrisToolbelt;
|
import com.volmit.iris.core.tools.IrisToolbelt;
|
||||||
import com.volmit.iris.engine.object.*;
|
import com.volmit.iris.engine.object.*;
|
||||||
import com.volmit.iris.engine.object.annotations.Snippet;
|
import com.volmit.iris.engine.object.annotations.Snippet;
|
||||||
@@ -326,7 +325,7 @@ public class IrisProject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Class<?> i : Iris.getClasses("com.volmit.iris.engine.object.", Snippet.class)) {
|
for (Class<?> i : dm.resolveSnippets()) {
|
||||||
try {
|
try {
|
||||||
String snipType = i.getDeclaredAnnotation(Snippet.class).value();
|
String snipType = i.getDeclaredAnnotation(Snippet.class).value();
|
||||||
JSONObject o = new JSONObject();
|
JSONObject o = new JSONObject();
|
||||||
|
|||||||
Reference in New Issue
Block a user