-
-
Notifications
You must be signed in to change notification settings - Fork 372
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
APickledWalrus
wants to merge
19
commits into
SkriptLang:dev/feature
from
APickledWalrus:feature/modules
Closed
Add Module System #4573
Changes from 8 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
adaa688
Implement initial design
APickledWalrus 0328f2b
Merge branch 'master' into feature/modules
APickledWalrus 0e44435
Merge branch 'master' into feature/modules
APickledWalrus 78b61ca
Implement entry cache
APickledWalrus d2f75b7
Use an array instead for the cache
APickledWalrus 72e5797
Merge branch 'master' into feature/modules
APickledWalrus 9a51f9f
It should actually build now
APickledWalrus 3767632
Further documentation updates
APickledWalrus 7305653
Merge branch 'master' into feature/modules
APickledWalrus d4e01a4
Merge branch 'master' into feature/modules
APickledWalrus 2a3f6d0
Improvements and fixes from review
APickledWalrus 803eeb9
Only open JarFile if necessary
APickledWalrus c08c4a6
Make entry cache not contain null elements
APickledWalrus 3038c51
Merge remote-tracking branch 'upstream/master' into feature/modules
APickledWalrus 10973c4
Change default syntax locations
APickledWalrus d6206e2
Fix loading
APickledWalrus 4ac2d16
Remove throws clause
APickledWalrus 2712285
Convert Module to Interface
APickledWalrus 66de7cd
Change default syntax locations
APickledWalrus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,6 +115,7 @@ | |
import java.lang.Thread.UncaughtExceptionHandler; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import java.lang.reflect.Modifier; | ||
import java.net.URL; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
|
@@ -503,14 +504,9 @@ public void onEnable() { | |
new DefaultFunctions(); | ||
|
||
ChatMessages.registerListeners(); | ||
|
||
try { | ||
getAddonInstance().loadClasses("ch.njol.skript", "conditions", "effects", "events", "expressions", "entity", "sections"); | ||
} 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") | ||
.loadModules("org.skriptlang.skript"); | ||
|
||
Commands.registerListeners(); | ||
|
||
|
@@ -519,48 +515,29 @@ 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; | ||
|
||
// Load hooks from Skript jar | ||
try { | ||
try (JarFile jar = new JarFile(getFile())) { | ||
for (final 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 { | ||
final Class<?> hook = Class.forName(c, true, getClassLoader()); | ||
if (hook != null && Hook.class.isAssignableFrom(hook) && !hook.isInterface() && Hook.class != hook && isHookEnabled((Class<? extends Hook<?>>) hook)) { | ||
hook.getDeclaredConstructor().setAccessible(true); | ||
hook.getDeclaredConstructor().newInstance(); | ||
} | ||
} catch (final ClassNotFoundException ex) { | ||
Skript.exception(ex, "Cannot load class " + c); | ||
} catch (final ExceptionInInitializerError err) { | ||
Skript.exception(err.getCause(), "Class " + c + " generated an exception while loading"); | ||
} | ||
} | ||
getAddonInstance().loadClasses(c -> { | ||
if (Hook.class.isAssignableFrom(c) && !c.isInterface() && !Modifier.isAbstract(c.getModifiers())) { | ||
try { | ||
c.getDeclaredConstructor().newInstance(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like to move away from using |
||
} catch (Exception ex) { | ||
Skript.exception(ex, "Failed to load hook class " + c); | ||
} | ||
} | ||
} catch (final Exception e) { | ||
error("Error while loading plugin hooks" + (e.getLocalizedMessage() == null ? "" : ": " + e.getLocalizedMessage())); | ||
Skript.exception(e); | ||
} | ||
}, false, "ch.njol.skript.hooks", false); | ||
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(); | ||
|
||
|
||
|
@@ -1224,10 +1201,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 ================ | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.