mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-17 08:45:11 +00:00
Implemented banned classes config for Nashorn scripts.
This commit is contained in:
1 parent
c24a900f18
commit
df88e5b4f9
2 files changed
+34
-2
No files matched your search
@@ -1,6 +1,8 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import jdk.nashorn.api.scripting.ClassFilter;
|
||||
import jdk.nashorn.api.scripting.NashornScriptEngineFactory;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
@@ -248,7 +250,22 @@ public class ScriptController {
|
||||
private static final List<String> nashornNames = immutableList("nashorn", "Nashorn", "js", "JS", "JavaScript", "javascript", "ECMAScript", "ecmascript");
|
||||
public ScriptEngine getEngineByName(String language) {
|
||||
if (nashornNames.contains(language) && this.nashornFactory != null) {
|
||||
ScriptEngine scriptEngine = this.nashornFactory.getScriptEngine();
|
||||
ScriptEngine scriptEngine;
|
||||
|
||||
try {
|
||||
ClassFilter filter = s -> {
|
||||
for (String className : ConfigScript.BannedClasses) {
|
||||
if (s.compareTo(className) == 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
NashornScriptEngineFactory nashornScriptEngineFactory = (NashornScriptEngineFactory) this.nashornFactory;
|
||||
scriptEngine = nashornScriptEngineFactory.getScriptEngine(filter);
|
||||
} catch (Exception e) {
|
||||
scriptEngine = this.nashornFactory.getScriptEngine();
|
||||
}
|
||||
scriptEngine.setBindings(this.manager.getBindings(), ScriptContext.GLOBAL_SCOPE);
|
||||
return scriptEngine;
|
||||
}
|
||||
@@ -300,4 +317,4 @@ public class ScriptController {
|
||||
|
||||
shouldSave = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user