Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Module System #4573

Closed
Closed
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 22 additions & 44 deletions src/main/java/ch/njol/skript/Skript.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.logging.Filter;
import java.util.logging.Level;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -528,15 +526,9 @@ public void onEnable() {
new DefaultFunctions();

ChatMessages.registerListeners();

try {
getAddonInstance().loadClasses("ch.njol.skript",
"conditions", "effects", "events", "expressions", "entity", "sections", "structures");
} catch (final Exception e) {
exception(e, "Could not load required .class files: " + e.getLocalizedMessage());
setEnabled(false);
return;
}

getAddonInstance().loadClasses("ch.njol.skript", "conditions", "effects", "events", "expressions", "entity", "sections", "structures")
.loadModules("org.skriptlang", "skript.syntax", "skriptbukkit");

Commands.registerListeners();

Expand All @@ -545,50 +537,32 @@ public void onEnable() {

final long tick = testing() ? Bukkit.getWorlds().get(0).getFullTime() : 0;
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
@SuppressWarnings("synthetic-access")
@Override
@SuppressWarnings("synthetic-access")
public void run() {
assert Bukkit.getWorlds().get(0).getFullTime() == tick;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this actually for? It's a test-only action but I can't see a comment explaining it.


// Load hooks from Skript jar
try {
try (JarFile jar = new JarFile(getFile())) {
for (JarEntry e : new EnumerationIterable<>(jar.entries())) {
if (e.getName().startsWith("ch/njol/skript/hooks/") && e.getName().endsWith("Hook.class") && StringUtils.count("" + e.getName(), '/') <= 5) {
final String c = e.getName().replace('/', '.').substring(0, e.getName().length() - ".class".length());
try {
Class<?> hook = Class.forName(c, true, getClassLoader());
if (Hook.class.isAssignableFrom(hook) && !Modifier.isAbstract(hook.getModifiers()) && isHookEnabled((Class<? extends Hook<?>>) hook)) {
hook.getDeclaredConstructor().setAccessible(true);
hook.getDeclaredConstructor().newInstance();
}
} catch (ClassNotFoundException ex) {
Skript.exception(ex, "Cannot load class " + c);
} catch (ExceptionInInitializerError err) {
Skript.exception(err.getCause(), "Class " + c + " generated an exception while loading");
} catch (Exception ex) {
Skript.exception(ex, "Exception initializing hook: " + c);
}
}
getAddonInstance().loadClasses("ch.njol.skript.hooks", false, false, hook -> {
//noinspection unchecked - We made sure that it's a valid hook
if (Hook.class.isAssignableFrom(hook) && !hook.isInterface() && !Modifier.isAbstract(hook.getModifiers()) && isHookEnabled((Class<? extends Hook<?>>) hook)) {
try {
hook.getDeclaredConstructor().setAccessible(true);
hook.getDeclaredConstructor().newInstance();
} catch (Exception ex) {
//noinspection ThrowableNotThrown
Skript.exception(ex, "Failed to load hook class " + hook);
}
}
} catch (IOException e) {
error("Error while loading plugin hooks" + (e.getLocalizedMessage() == null ? "" : ": " + e.getLocalizedMessage()));
Skript.exception(e);
}
});
finishedLoadingHooks = true;

if (TestMode.ENABLED) {
info("Preparing Skript for testing...");
tainted = true;
try {
getAddonInstance().loadClasses("ch.njol.skript", "tests");
} catch (IOException e) {
Skript.exception("Failed to load testing environment.");
Bukkit.getServer().shutdown();
}
getAddonInstance().loadClasses("ch.njol.skript", "tests");
}

stopAcceptingRegistrations();


Expand Down Expand Up @@ -1218,10 +1192,14 @@ public static void checkAcceptRegistrations() {

private static void stopAcceptingRegistrations() {
acceptRegistrations = false;

Converters.createMissingConverters();

Classes.onRegistrationsStop();

// Clear each cache
getAddonInstance().resetEntryCache(); // The SkriptAddon representing Skript is not part of the addons list
getAddons().forEach(SkriptAddon::resetEntryCache);
}

// ================ ADDONS ================
Expand Down
Loading