mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-24 16:24:26 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d752db8a49 | ||
|
|
b490e04bb0 | ||
|
|
99616854a7 | ||
|
|
236b901e61 | ||
|
|
810e29ca75 | ||
|
|
d119a7524e | ||
|
|
2b5fcc12cc |
No files matched your search
+1
-1
@@ -36,7 +36,7 @@
|
||||
def embedMixin = !project.hasProperty("nomixin");
|
||||
dependencies {
|
||||
runtimeOnlyNonPublishable("com.github.GTNewHorizons:NotEnoughItems:2.5.4-GTNH:dev")
|
||||
runtimeOnlyNonPublishable("curse.maven:Nashorn-374413:2924946")
|
||||
shadowImplementation(project.files("lib/GraalJS.jar"))
|
||||
|
||||
if(embedMixin){
|
||||
// Normal Jar will include built in Mixins
|
||||
|
||||
Binary file not shown.
+1
-1
Submodule src/api updated: a869b33edc...5c6b16e75f.
@@ -230,6 +230,10 @@ public class PacketUtil {
|
||||
tabCompound.setInteger("TotalScripts", containers.size());
|
||||
GuiDataPacket.sendGuiData(player, tabCompound);
|
||||
}
|
||||
|
||||
NBTTagCompound loadComplete = new NBTTagCompound();
|
||||
loadComplete.setInteger("LoadComplete", 1);
|
||||
GuiDataPacket.sendGuiData(player, loadComplete);
|
||||
}
|
||||
|
||||
public static void saveScripts(IScriptHandler data, ByteBuf buffer) throws IOException {
|
||||
|
||||
@@ -98,8 +98,6 @@ public class ImageDownloadAlt extends SimpleTexture {
|
||||
this.imageThread = new Thread("Texture Downloader #" + threadDownloadCounter.incrementAndGet()) {
|
||||
public void run() {
|
||||
HttpURLConnection connection = null;
|
||||
ImageDownloadAlt.logger.debug("Downloading http texture from {} to {}", new Object[]{ImageDownloadAlt.this.imageUrl, ImageDownloadAlt.this.cacheFile});
|
||||
|
||||
try {
|
||||
URL url = new URL(ImageDownloadAlt.this.imageUrl);
|
||||
connection = (HttpURLConnection) (url).openConnection(Minecraft.getMinecraft().getProxy());
|
||||
|
||||
@@ -27,6 +27,7 @@ public class GuiScript extends GuiNPCInterface implements IGuiData, GuiYesNoCall
|
||||
public Map<String, List<String>> languages = new HashMap<String, List<String>>();
|
||||
|
||||
private static int activeConsole = 0;
|
||||
boolean loaded = false;
|
||||
|
||||
public GuiScript(EntityNPCInterface npc) {
|
||||
super(npc);
|
||||
@@ -258,12 +259,15 @@ public class GuiScript extends GuiNPCInterface implements IGuiData, GuiYesNoCall
|
||||
}
|
||||
this.languages = languages;
|
||||
initGui();
|
||||
loaded = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save() {
|
||||
setScript();
|
||||
NPCScriptPacket.Save(script.writeToNBT(new NBTTagCompound()));
|
||||
if(loaded){
|
||||
setScript();
|
||||
NPCScriptPacket.Save(script.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -39,6 +39,11 @@ public class GuiNPCEventScripts extends GuiScriptInterface {
|
||||
}
|
||||
|
||||
public void setGuiData(NBTTagCompound compound) {
|
||||
if(compound.hasKey("LoadComplete")){
|
||||
loaded = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!compound.hasKey("Tab")) {
|
||||
script.setLanguage(compound.getString("ScriptLanguage"));
|
||||
script.setEnabled(compound.getBoolean("ScriptEnabled"));
|
||||
@@ -58,16 +63,18 @@ public class GuiNPCEventScripts extends GuiScriptInterface {
|
||||
}
|
||||
|
||||
public void save() {
|
||||
super.save();
|
||||
List<ScriptContainer> containers = this.script.getScripts();
|
||||
for (int i = 0; i < containers.size(); i++) {
|
||||
ScriptContainer container = containers.get(i);
|
||||
EventScriptPacket.Save(i, containers.size(), container.writeToNBT(new NBTTagCompound()));
|
||||
if(loaded) {
|
||||
super.save();
|
||||
List<ScriptContainer> containers = this.script.getScripts();
|
||||
for (int i = 0; i < containers.size(); i++) {
|
||||
ScriptContainer container = containers.get(i);
|
||||
EventScriptPacket.Save(i, containers.size(), container.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
NBTTagCompound scriptData = new NBTTagCompound();
|
||||
scriptData.setString("ScriptLanguage", this.script.getLanguage());
|
||||
scriptData.setBoolean("ScriptEnabled", this.script.getEnabled());
|
||||
scriptData.setTag("ScriptConsole", NBTTags.NBTLongStringMap(this.script.getConsoleText()));
|
||||
EventScriptPacket.Save(-1, containers.size(), scriptData);
|
||||
}
|
||||
NBTTagCompound scriptData = new NBTTagCompound();
|
||||
scriptData.setString("ScriptLanguage", this.script.getLanguage());
|
||||
scriptData.setBoolean("ScriptEnabled", this.script.getEnabled());
|
||||
scriptData.setTag("ScriptConsole", NBTTags.NBTLongStringMap(this.script.getConsoleText()));
|
||||
EventScriptPacket.Save(-1, containers.size(), scriptData);
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,11 @@ public class GuiScriptAllNPCs extends GuiScriptInterface {
|
||||
}
|
||||
|
||||
public void setGuiData(NBTTagCompound compound) {
|
||||
if(compound.hasKey("LoadComplete")){
|
||||
loaded = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!compound.hasKey("Tab")) {
|
||||
script.setLanguage(compound.getString("ScriptLanguage"));
|
||||
script.setEnabled(compound.getBoolean("ScriptEnabled"));
|
||||
@@ -54,16 +59,18 @@ public class GuiScriptAllNPCs extends GuiScriptInterface {
|
||||
}
|
||||
|
||||
public void save() {
|
||||
super.save();
|
||||
List<ScriptContainer> containers = this.script.getScripts();
|
||||
for (int i = 0; i < containers.size(); i++) {
|
||||
ScriptContainer container = containers.get(i);
|
||||
GlobalNPCScriptPacket.Save(i, containers.size(), container.writeToNBT(new NBTTagCompound()));
|
||||
if(loaded){
|
||||
super.save();
|
||||
List<ScriptContainer> containers = this.script.getScripts();
|
||||
for (int i = 0; i < containers.size(); i++) {
|
||||
ScriptContainer container = containers.get(i);
|
||||
GlobalNPCScriptPacket.Save(i, containers.size(), container.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
NBTTagCompound scriptData = new NBTTagCompound();
|
||||
scriptData.setString("ScriptLanguage", this.script.getLanguage());
|
||||
scriptData.setBoolean("ScriptEnabled", this.script.getEnabled());
|
||||
scriptData.setTag("ScriptConsole", NBTTags.NBTLongStringMap(this.script.getConsoleText()));
|
||||
GlobalNPCScriptPacket.Save(-1, containers.size(), scriptData);
|
||||
}
|
||||
NBTTagCompound scriptData = new NBTTagCompound();
|
||||
scriptData.setString("ScriptLanguage", this.script.getLanguage());
|
||||
scriptData.setBoolean("ScriptEnabled", this.script.getEnabled());
|
||||
scriptData.setTag("ScriptConsole", NBTTags.NBTLongStringMap(this.script.getConsoleText()));
|
||||
GlobalNPCScriptPacket.Save(-1, containers.size(), scriptData);
|
||||
}
|
||||
}
|
||||
@@ -30,10 +30,13 @@ public class GuiScriptBlock extends GuiScriptInterface {
|
||||
public void setGuiData(NBTTagCompound compound) {
|
||||
this.tileScripted.setNBT(compound);
|
||||
super.setGuiData(compound);
|
||||
loaded = true;
|
||||
}
|
||||
|
||||
public void save() {
|
||||
super.save();
|
||||
BlockScriptPacket.Save(tileScripted.xCoord, tileScripted.yCoord, tileScripted.zCoord, this.tileScripted.getNBT(new NBTTagCompound()));
|
||||
if(loaded) {
|
||||
super.save();
|
||||
BlockScriptPacket.Save(tileScripted.xCoord, tileScripted.yCoord, tileScripted.zCoord, this.tileScripted.getNBT(new NBTTagCompound()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,7 @@ public class GuiScriptEffect extends GuiNPCInterface implements GuiYesNoCallback
|
||||
public final GuiNPCManageEffects parent;
|
||||
public final CustomEffect effect;
|
||||
private final EffectScript scriptHandler;
|
||||
|
||||
boolean loaded = false;
|
||||
|
||||
public GuiScriptEffect(GuiNPCManageEffects parent, CustomEffect effect) {
|
||||
this.drawDefaultBackground = true;
|
||||
@@ -315,6 +315,11 @@ public class GuiScriptEffect extends GuiNPCInterface implements GuiYesNoCallback
|
||||
}
|
||||
|
||||
public void setGuiData(NBTTagCompound compound) {
|
||||
if(compound.hasKey("LoadComplete")){
|
||||
loaded = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!compound.hasKey("Tab")) {
|
||||
this.scriptHandler.setLanguage(compound.getString("ScriptLanguage"));
|
||||
this.scriptHandler.setEnabled(compound.getBoolean("ScriptEnabled"));
|
||||
@@ -326,7 +331,6 @@ public class GuiScriptEffect extends GuiNPCInterface implements GuiYesNoCallback
|
||||
this.scriptHandler.container = container;
|
||||
this.initGui();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void copiedSetGuiData(NBTTagCompound compound) {
|
||||
@@ -350,19 +354,21 @@ public class GuiScriptEffect extends GuiNPCInterface implements GuiYesNoCallback
|
||||
}
|
||||
|
||||
public void save() {
|
||||
this.setScript();
|
||||
if(loaded) {
|
||||
this.setScript();
|
||||
|
||||
List<ScriptContainer> containers = this.scriptHandler.getScripts();
|
||||
for (int i = 0; i < containers.size(); i++) {
|
||||
ScriptContainer container = containers.get(i);
|
||||
EffectScriptPacket.Save(effect.id, i, containers.size(), container.writeToNBT(new NBTTagCompound()));
|
||||
List<ScriptContainer> containers = this.scriptHandler.getScripts();
|
||||
for (int i = 0; i < containers.size(); i++) {
|
||||
ScriptContainer container = containers.get(i);
|
||||
EffectScriptPacket.Save(effect.id, i, containers.size(), container.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
NBTTagCompound scriptData = new NBTTagCompound();
|
||||
scriptData.setString("ScriptLanguage", this.scriptHandler.getLanguage());
|
||||
scriptData.setBoolean("ScriptEnabled", this.scriptHandler.getEnabled());
|
||||
scriptData.setTag("ScriptConsole", NBTTags.NBTLongStringMap(this.scriptHandler.getConsoleText()));
|
||||
|
||||
EffectScriptPacket.Save(effect.id, -1, containers.size(), scriptData);
|
||||
}
|
||||
NBTTagCompound scriptData = new NBTTagCompound();
|
||||
scriptData.setString("ScriptLanguage", this.scriptHandler.getLanguage());
|
||||
scriptData.setBoolean("ScriptEnabled", this.scriptHandler.getEnabled());
|
||||
scriptData.setTag("ScriptConsole", NBTTags.NBTLongStringMap(this.scriptHandler.getConsoleText()));
|
||||
|
||||
EffectScriptPacket.Save(effect.id, -1, containers.size(), scriptData);
|
||||
}
|
||||
|
||||
public void textUpdate(String text) {
|
||||
|
||||
@@ -65,6 +65,11 @@ public class GuiScriptForge extends GuiScriptInterface {
|
||||
}
|
||||
|
||||
public void setGuiData(NBTTagCompound compound) {
|
||||
if(compound.hasKey("LoadComplete")){
|
||||
loaded = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!compound.hasKey("Tab")) {
|
||||
script.setLanguage(compound.getString("ScriptLanguage"));
|
||||
script.setEnabled(compound.getBoolean("ScriptEnabled"));
|
||||
@@ -84,16 +89,18 @@ public class GuiScriptForge extends GuiScriptInterface {
|
||||
}
|
||||
|
||||
public void save() {
|
||||
super.save();
|
||||
List<ScriptContainer> containers = this.script.getScripts();
|
||||
for (int i = 0; i < containers.size(); i++) {
|
||||
ScriptContainer container = containers.get(i);
|
||||
ForgeScriptPacket.Save(i, containers.size(), container.writeToNBT(new NBTTagCompound()));
|
||||
if(loaded) {
|
||||
super.save();
|
||||
List<ScriptContainer> containers = this.script.getScripts();
|
||||
for (int i = 0; i < containers.size(); i++) {
|
||||
ScriptContainer container = containers.get(i);
|
||||
ForgeScriptPacket.Save(i, containers.size(), container.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
NBTTagCompound scriptData = new NBTTagCompound();
|
||||
scriptData.setString("ScriptLanguage", this.script.getLanguage());
|
||||
scriptData.setBoolean("ScriptEnabled", this.script.getEnabled());
|
||||
scriptData.setTag("ScriptConsole", NBTTags.NBTLongStringMap(this.script.getConsoleText()));
|
||||
ForgeScriptPacket.Save(-1, containers.size(), scriptData);
|
||||
}
|
||||
NBTTagCompound scriptData = new NBTTagCompound();
|
||||
scriptData.setString("ScriptLanguage", this.script.getLanguage());
|
||||
scriptData.setBoolean("ScriptEnabled", this.script.getEnabled());
|
||||
scriptData.setTag("ScriptConsole", NBTTags.NBTLongStringMap(this.script.getConsoleText()));
|
||||
ForgeScriptPacket.Save(-1, containers.size(), scriptData);
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
public Map<String, List<String>> languages = new HashMap();
|
||||
private int scriptLimit = 1;
|
||||
public List<String> hookList = new ArrayList<String>();
|
||||
protected boolean loaded = false;
|
||||
|
||||
public GuiScriptInterface() {
|
||||
this.drawDefaultBackground = true;
|
||||
@@ -338,7 +339,8 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
}
|
||||
|
||||
public void save() {
|
||||
this.setScript();
|
||||
if(loaded)
|
||||
this.setScript();
|
||||
}
|
||||
|
||||
public void textUpdate(String text) {
|
||||
|
||||
@@ -44,12 +44,15 @@ public class GuiScriptItem extends GuiScriptInterface {
|
||||
this.item.setMCNbt(compound);
|
||||
this.item.loadScriptData();
|
||||
super.setGuiData(compound);
|
||||
loaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void save() {
|
||||
super.save();
|
||||
ItemScriptPacket.Save(this.item.getMCNbt());
|
||||
if(loaded) {
|
||||
super.save();
|
||||
ItemScriptPacket.Save(this.item.getMCNbt());
|
||||
}
|
||||
}
|
||||
|
||||
protected String getConsoleText() {
|
||||
|
||||
@@ -30,6 +30,7 @@ public class GuiScriptLinkedItem extends GuiNPCInterface implements GuiYesNoCall
|
||||
public final GuiNPCManageLinked parent;
|
||||
public final LinkedItem linkedItem;
|
||||
private final LinkedItemScript scriptHandler;
|
||||
boolean loaded = false;
|
||||
|
||||
public GuiScriptLinkedItem(GuiNPCManageLinked parent, LinkedItem linkedItem) {
|
||||
this.drawDefaultBackground = true;
|
||||
@@ -326,6 +327,11 @@ public class GuiScriptLinkedItem extends GuiNPCInterface implements GuiYesNoCall
|
||||
}
|
||||
|
||||
public void setGuiData(NBTTagCompound compound) {
|
||||
if(compound.hasKey("LoadComplete")){
|
||||
loaded = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!compound.hasKey("Tab")) {
|
||||
this.scriptHandler.setLanguage(compound.getString("ScriptLanguage"));
|
||||
this.scriptHandler.setEnabled(compound.getBoolean("ScriptEnabled"));
|
||||
@@ -361,19 +367,21 @@ public class GuiScriptLinkedItem extends GuiNPCInterface implements GuiYesNoCall
|
||||
}
|
||||
|
||||
public void save() {
|
||||
this.setScript();
|
||||
if(loaded) {
|
||||
this.setScript();
|
||||
|
||||
List<ScriptContainer> containers = this.scriptHandler.getScripts();
|
||||
for (int i = 0; i < containers.size(); i++) {
|
||||
ScriptContainer container = containers.get(i);
|
||||
LinkedItemScriptPacket.Save(linkedItem.id, i, containers.size(), container.writeToNBT(new NBTTagCompound()));
|
||||
List<ScriptContainer> containers = this.scriptHandler.getScripts();
|
||||
for (int i = 0; i < containers.size(); i++) {
|
||||
ScriptContainer container = containers.get(i);
|
||||
LinkedItemScriptPacket.Save(linkedItem.id, i, containers.size(), container.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
NBTTagCompound scriptData = new NBTTagCompound();
|
||||
scriptData.setString("ScriptLanguage", this.scriptHandler.getLanguage());
|
||||
scriptData.setBoolean("ScriptEnabled", this.scriptHandler.getEnabled());
|
||||
scriptData.setTag("ScriptConsole", NBTTags.NBTLongStringMap(this.scriptHandler.getConsoleText()));
|
||||
|
||||
LinkedItemScriptPacket.Save(linkedItem.id, -1, containers.size(), scriptData);
|
||||
}
|
||||
NBTTagCompound scriptData = new NBTTagCompound();
|
||||
scriptData.setString("ScriptLanguage", this.scriptHandler.getLanguage());
|
||||
scriptData.setBoolean("ScriptEnabled", this.scriptHandler.getEnabled());
|
||||
scriptData.setTag("ScriptConsole", NBTTags.NBTLongStringMap(this.scriptHandler.getConsoleText()));
|
||||
|
||||
LinkedItemScriptPacket.Save(linkedItem.id, -1, containers.size(), scriptData);
|
||||
}
|
||||
|
||||
public void textUpdate(String text) {
|
||||
|
||||
@@ -90,6 +90,11 @@ public class GuiScriptPlayers extends GuiScriptInterface {
|
||||
}
|
||||
|
||||
public void setGuiData(NBTTagCompound compound) {
|
||||
if(compound.hasKey("LoadComplete")){
|
||||
loaded = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!compound.hasKey("Tab")) {
|
||||
script.setLanguage(compound.getString("ScriptLanguage"));
|
||||
script.setEnabled(compound.getBoolean("ScriptEnabled"));
|
||||
@@ -109,16 +114,18 @@ public class GuiScriptPlayers extends GuiScriptInterface {
|
||||
}
|
||||
|
||||
public void save() {
|
||||
super.save();
|
||||
List<ScriptContainer> containers = this.script.getScripts();
|
||||
for (int i = 0; i < containers.size(); i++) {
|
||||
ScriptContainer container = containers.get(i);
|
||||
PlayerScriptPacket.Save(i, containers.size(), container.writeToNBT(new NBTTagCompound()));
|
||||
if(loaded) {
|
||||
super.save();
|
||||
List<ScriptContainer> containers = this.script.getScripts();
|
||||
for (int i = 0; i < containers.size(); i++) {
|
||||
ScriptContainer container = containers.get(i);
|
||||
PlayerScriptPacket.Save(i, containers.size(), container.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
NBTTagCompound scriptData = new NBTTagCompound();
|
||||
scriptData.setString("ScriptLanguage", this.script.getLanguage());
|
||||
scriptData.setBoolean("ScriptEnabled", this.script.getEnabled());
|
||||
scriptData.setTag("ScriptConsole", NBTTags.NBTLongStringMap(this.script.getConsoleText()));
|
||||
PlayerScriptPacket.Save(-1, containers.size(), scriptData);
|
||||
}
|
||||
NBTTagCompound scriptData = new NBTTagCompound();
|
||||
scriptData.setString("ScriptLanguage", this.script.getLanguage());
|
||||
scriptData.setBoolean("ScriptEnabled", this.script.getEnabled());
|
||||
scriptData.setTag("ScriptConsole", NBTTags.NBTLongStringMap(this.script.getConsoleText()));
|
||||
PlayerScriptPacket.Save(-1, containers.size(), scriptData);
|
||||
}
|
||||
}
|
||||
@@ -92,22 +92,20 @@ public class ScriptContainer {
|
||||
|
||||
private String getFullCode() {
|
||||
if (!this.evaluated) {
|
||||
this.fullscript = this.script;
|
||||
if (!this.fullscript.isEmpty()) {
|
||||
this.fullscript = this.fullscript + "\n";
|
||||
}
|
||||
|
||||
Iterator var1 = this.scripts.iterator();
|
||||
|
||||
while (var1.hasNext()) {
|
||||
String loc = (String) var1.next();
|
||||
String code = (String) ScriptController.Instance.scripts.get(loc);
|
||||
// build includes first
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String loc : this.scripts) {
|
||||
String code = ScriptController.Instance.scripts.get(loc);
|
||||
if (code != null && !code.isEmpty()) {
|
||||
this.fullscript = this.fullscript + code + "\n";
|
||||
sb.append(code).append("\n");
|
||||
}
|
||||
}
|
||||
|
||||
this.unknownFunctions = new HashSet<String>();
|
||||
// then your per‐hook script
|
||||
if (this.script != null && !this.script.isEmpty()) {
|
||||
sb.append(this.script).append("\n");
|
||||
}
|
||||
this.fullscript = sb.toString();
|
||||
this.unknownFunctions = new HashSet<>();
|
||||
}
|
||||
return this.fullscript;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import com.oracle.truffle.js.scriptengine.GraalJSEngineFactory;
|
||||
import com.oracle.truffle.js.scriptengine.GraalJSScriptEngine;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import jdk.nashorn.api.scripting.ClassFilter;
|
||||
import jdk.nashorn.api.scripting.NashornScriptEngineFactory;
|
||||
//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;
|
||||
@@ -21,6 +23,8 @@ import noppes.npcs.entity.EntityNPCInterface;
|
||||
import noppes.npcs.scripted.ScriptWorld;
|
||||
import noppes.npcs.util.JsonException;
|
||||
import noppes.npcs.util.NBTJsonUtil;
|
||||
import org.graalvm.polyglot.Context;
|
||||
import org.graalvm.polyglot.HostAccess;
|
||||
|
||||
import javax.script.ScriptContext;
|
||||
import javax.script.ScriptEngine;
|
||||
@@ -31,6 +35,7 @@ import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import static noppes.npcs.util.CustomNPCsThreader.customNPCThread;
|
||||
|
||||
@@ -39,7 +44,7 @@ public class ScriptController {
|
||||
public static ScriptController Instance;
|
||||
public static boolean HasStart = false;
|
||||
private final ScriptEngineManager manager;
|
||||
private ScriptEngineFactory nashornFactory;
|
||||
private ScriptEngineFactory graalFactory;
|
||||
public Map<String, String> languages = new HashMap<String, String>();
|
||||
public Map<String, String> scripts = new HashMap<String, String>();
|
||||
public long lastLoaded = 0;
|
||||
@@ -64,14 +69,14 @@ public class ScriptController {
|
||||
LogWriter.info("Script Engines Available:");
|
||||
|
||||
try {
|
||||
this.nashornFactory = new NashornScriptEngineFactory();
|
||||
LogWriter.info("→ standalone Nashorn loaded");
|
||||
} catch (NoClassDefFoundError e) {
|
||||
this.graalFactory = new GraalJSEngineFactory();
|
||||
LogWriter.info("→ standalone Nashorn loaded: " + this.graalFactory.getEngineName());
|
||||
} catch (Exception e) {
|
||||
// fallback to built-in (Java 8–11) — also guarded
|
||||
try {
|
||||
ScriptEngine eng = manager.getEngineByName("nashorn");
|
||||
if (eng != null) {
|
||||
this.nashornFactory = eng.getFactory();
|
||||
this.graalFactory = eng.getFactory();
|
||||
LogWriter.info("→ built-in Nashorn loaded");
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
@@ -298,25 +303,27 @@ 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;
|
||||
if (nashornNames.contains(language) && this.graalFactory != null) {
|
||||
ScriptEngine scriptEngine = getGraalJSEngine();
|
||||
if (scriptEngine != null) return scriptEngine;
|
||||
|
||||
if (ConfigScript.EnableBannedClasses) {
|
||||
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);
|
||||
// ClassFilter filter = s -> {
|
||||
// for (String className : ConfigScript.BannedClasses) {
|
||||
// if (s.compareTo(className) == 0) {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
// return true;
|
||||
// };
|
||||
// NashornScriptEngineFactory nashornScriptEngineFactory = (NashornScriptEngineFactory) this.graalFactory;
|
||||
// scriptEngine = nashornScriptEngineFactory.getScriptEngine(filter);
|
||||
} catch (Exception e) {
|
||||
scriptEngine = this.nashornFactory.getScriptEngine();
|
||||
scriptEngine = this.graalFactory.getScriptEngine();
|
||||
}
|
||||
} else {
|
||||
scriptEngine = this.nashornFactory.getScriptEngine();
|
||||
scriptEngine = this.graalFactory.getScriptEngine();
|
||||
}
|
||||
scriptEngine.setBindings(this.manager.getBindings(), ScriptContext.GLOBAL_SCOPE);
|
||||
return scriptEngine;
|
||||
@@ -324,6 +331,22 @@ public class ScriptController {
|
||||
return manager.getEngineByName(language);
|
||||
}
|
||||
|
||||
public ScriptEngine getGraalJSEngine() {
|
||||
Context.Builder polyglotContext = Context.newBuilder("js")
|
||||
.option("js.nashorn-compat", "true")
|
||||
.option("js.scripting", "true")
|
||||
.option("js.syntax-extensions", "true")
|
||||
.allowAllAccess(true)
|
||||
.allowNativeAccess(true)
|
||||
.allowIO(true)
|
||||
.allowHostAccess(HostAccess.ALL)
|
||||
.allowHostClassLookup(s -> true);
|
||||
|
||||
return GraalJSScriptEngine.create(
|
||||
((GraalJSEngineFactory)this.graalFactory).getPolyglotEngine(),
|
||||
polyglotContext);
|
||||
}
|
||||
|
||||
private static List<String> immutableList(String... elements) {
|
||||
return Collections.unmodifiableList(Arrays.asList(elements));
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package noppes.npcs.controllers.data.action;
|
||||
|
||||
import noppes.npcs.api.handler.data.IAction;
|
||||
import noppes.npcs.config.ConfigScript;
|
||||
import noppes.npcs.scripted.ScriptedActionManager;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -128,7 +127,7 @@ public class Action implements IAction {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAction addData(String key, Object v) {
|
||||
public IAction setData(String key, Object v) {
|
||||
dataStore.put(key, v);
|
||||
return this;
|
||||
}
|
||||
@@ -139,6 +138,11 @@ public class Action implements IAction {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasData(String key) {
|
||||
return dataStore.containsKey(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUpdateEveryXTick() {
|
||||
return updateEveryXTick;
|
||||
|
||||
@@ -136,7 +136,11 @@ public class ScriptWorld implements IWorld {
|
||||
}
|
||||
|
||||
public IBlock getTopBlock(int x, int z) {
|
||||
return NpcAPI.Instance().getIBlock(this, x, world.getTopSolidOrLiquidBlock(x, z), z);
|
||||
int yAbove = world.getTopSolidOrLiquidBlock(x, z);
|
||||
if (yAbove <= 0) {
|
||||
return null;
|
||||
}
|
||||
return NpcAPI.Instance().getIBlock(this, x, yAbove - 1, z);
|
||||
}
|
||||
|
||||
public IBlock getTopBlock(IPos pos) {
|
||||
|
||||
Reference in new issue
Block a user