Skip to content

Commit

Permalink
fix groovy class loader not work if not using global
Browse files Browse the repository at this point in the history
  • Loading branch information
eric2788 committed Jun 19, 2022
1 parent 9eadf79 commit d9b6e89
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ class GroovierModule extends AbstractModule {
private final Map<Class, Class> classMap = new HashMap<>()
private final Map<Class, Class<Provider<?>>> providerMap = new HashMap<>();

private final GroovyClassLoader classLoader = new GroovyClassLoader(getClass().getClassLoader())

private ScriptPlugin scriptPlugin

@Override
protected void configure() {
if (scriptPlugin == null) {
throw new IllegalStateException("scriptPluginClass is not set")
}
bind(GroovyClassLoader.class).toInstance(classLoader)
bind(ScriptCacheManager.class).to(GroovierCacheManager.class).in(Scopes.SINGLETON)
bind(ScriptPlugin.class).toInstance(scriptPlugin)
reloadableSet.forEach(reloadable -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,37 @@ class GroovierScriptLoader {

@Inject
private ScriptPlugin plugin

@Inject
private GroovierLifeCycle lifeCycle

@Inject
private ScriptCacheManager cacheManager
@Inject
private GroovyClassLoader classLoader

CompletableFuture<Void> loadAllScripts() {
try (def classLoader = new GroovyClassLoader(plugin.getClass().getClassLoader())) {
CompletableFuture<Void> future = new CompletableFuture<>()
CompletableFuture.runAsync(() -> {
var globalLibraries = new File(plugin.getPluginFolder(), "grapesConfig.groovy")
if (globalLibraries.exists()) {
plugin.logger.info("loading global libraries...")
classLoader.parseClass(globalLibraries)
plugin.logger.info("global libraries loaded.")
}
loaders.forEach(loader -> {
plugin.getLogger().info("Loading ${loader.class.simpleName}")
loader.load(classLoader)
plugin.getLogger().info("${loader.class.simpleName} loading completed.")
})
loaders.forEach(loader -> loader.afterLoad())
(cacheManager as GroovierCacheManager).flush()
}).thenAccept((v) -> {
plugin.runSyncTask(() -> {
lifeCycle.onScriptLoad()
future.complete(v)
})
CompletableFuture<Void> future = new CompletableFuture<>()
CompletableFuture.runAsync(() -> {
var globalLibraries = new File(plugin.getPluginFolder(), "grapesConfig.groovy")
if (globalLibraries.exists()) {
plugin.logger.info("loading global libraries...")
classLoader.parseClass(globalLibraries)
plugin.logger.info("global libraries loaded.")
}
loaders.forEach(loader -> {
plugin.getLogger().info("Loading ${loader.class.simpleName}")
loader.load(classLoader)
plugin.getLogger().info("${loader.class.simpleName} loading completed.")
})
return future
}
loaders.forEach(loader -> loader.afterLoad())
((GroovierCacheManager)cacheManager).flush()
}).thenAccept((v) -> {
plugin.logger.info("All Scripts loaded.")
plugin.runSyncTask(() -> {
lifeCycle.onScriptLoad()
future.complete(v)
})
})
return future
}

void unloadAllScripts() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.ericlam.mc.groovier.scriptloaders

import com.ericlam.mc.groovier.ScriptPlugin

interface GroovierLifeCycle {

void onEnable();
Expand Down

0 comments on commit d9b6e89

Please sign in to comment.