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