Skip to content

Commit cabb567

Browse files
committed
fix(app): load scripts with Skript class loader
since Skript doesn't expose a class loader instance we use loadScript to use it implicitly
1 parent 90f6117 commit cabb567

File tree

1 file changed

+3
-16
lines changed

1 file changed

+3
-16
lines changed

src/main/java/org/byteskript/skript/app/ScriptRunner.java

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,6 @@ public class ScriptRunner {
2424
static final List<Script> SCRIPTS = new ArrayList<>();
2525

2626
public static void main(String... args) throws IOException, ClassNotFoundException {
27-
final Class<?>[] classes = findClasses("skript/");
28-
for (final Class<?> source : classes) {
29-
final Script script = SKRIPT.loadScript(source);
30-
SCRIPTS.add(script);
31-
}
32-
new SimpleThrottleController(SKRIPT).run();
33-
}
34-
35-
protected static Class<?>[] findClasses(final String namespace) throws IOException, ClassNotFoundException {
36-
final List<Class<?>> classes = new ArrayList<>();
3727
final CodeSource src = ScriptRunner.class.getProtectionDomain().getCodeSource();
3828
if (src != null) {
3929
final URL jar = src.getLocation();
@@ -44,17 +34,14 @@ protected static Class<?>[] findClasses(final String namespace) throws IOExcepti
4434
if (entry.isDirectory()) continue;
4535
final String name = entry.getName();
4636
if (!name.endsWith(".class")) continue;
47-
if (name.startsWith(namespace)) {
48-
final Class<?> data = Class.forName(name
49-
.substring(0, name.length() - 6)
50-
.replace("/", "."), false, ScriptRunner.class.getClassLoader());
51-
classes.add(data);
37+
if (name.startsWith("skript/")) {
38+
SCRIPTS.add(SKRIPT.loadScript(zip.readAllBytes()));
5239
}
5340
}
5441
}
5542
} else {
5643
throw new ScriptRuntimeError("Unable to access source.");
5744
}
58-
return classes.toArray(new Class[0]);
45+
new SimpleThrottleController(SKRIPT).run();
5946
}
6047
}

0 commit comments

Comments
 (0)