Merge pull request #154 from pvginkel/master
Fixed class loader of the script engine.
This commit is contained in:
commit
0906f61575
1 changed files with 17 additions and 9 deletions
|
@ -1,13 +1,16 @@
|
|||
package net.walterhiggins.scriptcraft;
|
||||
|
||||
import java.io.InputStreamReader;
|
||||
import javax.script.*;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.command.*;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import javax.script.Invocable;
|
||||
import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptEngineManager;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ScriptCraftPlugin extends JavaPlugin implements Listener
|
||||
{
|
||||
|
@ -19,6 +22,9 @@ public class ScriptCraftPlugin extends JavaPlugin implements Listener
|
|||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
Thread currentThread = Thread.currentThread();
|
||||
ClassLoader previousClassLoader = currentThread.getContextClassLoader();
|
||||
currentThread.setContextClassLoader(getClassLoader());
|
||||
try{
|
||||
ScriptEngineManager factory = new ScriptEngineManager();
|
||||
this.engine = factory.getEngineByName("JavaScript");
|
||||
|
@ -32,6 +38,8 @@ public class ScriptCraftPlugin extends JavaPlugin implements Listener
|
|||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
this.getLogger().severe(e.getMessage());
|
||||
}finally{
|
||||
currentThread.setContextClassLoader(previousClassLoader);
|
||||
}
|
||||
}
|
||||
public List<String> onTabComplete(CommandSender sender, Command cmd,
|
||||
|
|
Reference in a new issue