mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-24 21:04:27 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
23357b6a79 | ||
|
|
d355e64662 | ||
|
|
de3f71918c | ||
|
|
7b9f182e32 |
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")
|
||||||
shadowImplementation(project.files("lib/GraalJS.jar"))
|
runtimeOnlyNonPublishable("curse.maven:Nashorn-374413:2924946")
|
||||||
|
|
||||||
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: 5c6b16e75f...a869b33edc.
@@ -230,10 +230,6 @@ 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,6 +98,8 @@ 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,7 +27,6 @@ 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);
|
||||||
@@ -259,15 +258,12 @@ 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() {
|
||||||
if(loaded){
|
setScript();
|
||||||
setScript();
|
NPCScriptPacket.Save(script.writeToNBT(new NBTTagCompound()));
|
||||||
NPCScriptPacket.Save(script.writeToNBT(new NBTTagCompound()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -39,11 +39,6 @@ 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"));
|
||||||
@@ -63,18 +58,16 @@ public class GuiNPCEventScripts extends GuiScriptInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void save() {
|
public void save() {
|
||||||
if(loaded) {
|
super.save();
|
||||||
super.save();
|
List<ScriptContainer> containers = this.script.getScripts();
|
||||||
List<ScriptContainer> containers = this.script.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);
|
EventScriptPacket.Save(i, containers.size(), container.writeToNBT(new NBTTagCompound()));
|
||||||
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,11 +35,6 @@ 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"));
|
||||||
@@ -59,18 +54,16 @@ public class GuiScriptAllNPCs extends GuiScriptInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void save() {
|
public void save() {
|
||||||
if(loaded){
|
super.save();
|
||||||
super.save();
|
List<ScriptContainer> containers = this.script.getScripts();
|
||||||
List<ScriptContainer> containers = this.script.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);
|
GlobalNPCScriptPacket.Save(i, containers.size(), container.writeToNBT(new NBTTagCompound()));
|
||||||
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,13 +30,10 @@ 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() {
|
||||||
if(loaded) {
|
super.save();
|
||||||
super.save();
|
BlockScriptPacket.Save(tileScripted.xCoord, tileScripted.yCoord, tileScripted.zCoord, this.tileScripted.getNBT(new NBTTagCompound()));
|
||||||
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,11 +315,6 @@ 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"));
|
||||||
@@ -331,6 +326,7 @@ 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) {
|
||||||
@@ -354,21 +350,19 @@ public class GuiScriptEffect extends GuiNPCInterface implements GuiYesNoCallback
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void save() {
|
public void save() {
|
||||||
if(loaded) {
|
this.setScript();
|
||||||
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,11 +65,6 @@ 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"));
|
||||||
@@ -89,18 +84,16 @@ public class GuiScriptForge extends GuiScriptInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void save() {
|
public void save() {
|
||||||
if(loaded) {
|
super.save();
|
||||||
super.save();
|
List<ScriptContainer> containers = this.script.getScripts();
|
||||||
List<ScriptContainer> containers = this.script.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);
|
ForgeScriptPacket.Save(i, containers.size(), container.writeToNBT(new NBTTagCompound()));
|
||||||
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,7 +25,6 @@ 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;
|
||||||
@@ -339,8 +338,7 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void save() {
|
public void save() {
|
||||||
if(loaded)
|
this.setScript();
|
||||||
this.setScript();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void textUpdate(String text) {
|
public void textUpdate(String text) {
|
||||||
|
|||||||
@@ -44,15 +44,12 @@ 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() {
|
||||||
if(loaded) {
|
super.save();
|
||||||
super.save();
|
ItemScriptPacket.Save(this.item.getMCNbt());
|
||||||
ItemScriptPacket.Save(this.item.getMCNbt());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getConsoleText() {
|
protected String getConsoleText() {
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ 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;
|
||||||
@@ -327,11 +326,6 @@ 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"));
|
||||||
@@ -367,21 +361,19 @@ public class GuiScriptLinkedItem extends GuiNPCInterface implements GuiYesNoCall
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void save() {
|
public void save() {
|
||||||
if(loaded) {
|
this.setScript();
|
||||||
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,11 +90,6 @@ 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"));
|
||||||
@@ -114,18 +109,16 @@ public class GuiScriptPlayers extends GuiScriptInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void save() {
|
public void save() {
|
||||||
if(loaded) {
|
super.save();
|
||||||
super.save();
|
List<ScriptContainer> containers = this.script.getScripts();
|
||||||
List<ScriptContainer> containers = this.script.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);
|
PlayerScriptPacket.Save(i, containers.size(), container.writeToNBT(new NBTTagCompound()));
|
||||||
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,20 +92,22 @@ public class ScriptContainer {
|
|||||||
|
|
||||||
private String getFullCode() {
|
private String getFullCode() {
|
||||||
if (!this.evaluated) {
|
if (!this.evaluated) {
|
||||||
// build includes first
|
this.fullscript = this.script;
|
||||||
StringBuilder sb = new StringBuilder();
|
if (!this.fullscript.isEmpty()) {
|
||||||
for (String loc : this.scripts) {
|
this.fullscript = this.fullscript + "\n";
|
||||||
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()) {
|
||||||
sb.append(code).append("\n");
|
this.fullscript = this.fullscript + code + "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// then your per‐hook script
|
|
||||||
if (this.script != null && !this.script.isEmpty()) {
|
this.unknownFunctions = new HashSet<String>();
|
||||||
sb.append(this.script).append("\n");
|
|
||||||
}
|
|
||||||
this.fullscript = sb.toString();
|
|
||||||
this.unknownFunctions = new HashSet<>();
|
|
||||||
}
|
}
|
||||||
return this.fullscript;
|
return this.fullscript;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
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;
|
||||||
@@ -23,8 +21,6 @@ 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;
|
||||||
@@ -35,7 +31,6 @@ 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;
|
||||||
|
|
||||||
@@ -44,7 +39,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 graalFactory;
|
private ScriptEngineFactory nashornFactory;
|
||||||
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;
|
||||||
@@ -69,14 +64,14 @@ public class ScriptController {
|
|||||||
LogWriter.info("Script Engines Available:");
|
LogWriter.info("Script Engines Available:");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.graalFactory = new GraalJSEngineFactory();
|
this.nashornFactory = new NashornScriptEngineFactory();
|
||||||
LogWriter.info("→ standalone Nashorn loaded: " + this.graalFactory.getEngineName());
|
LogWriter.info("→ standalone Nashorn loaded");
|
||||||
} catch (Exception e) {
|
} catch (NoClassDefFoundError 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.graalFactory = eng.getFactory();
|
this.nashornFactory = eng.getFactory();
|
||||||
LogWriter.info("→ built-in Nashorn loaded");
|
LogWriter.info("→ built-in Nashorn loaded");
|
||||||
}
|
}
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
@@ -303,27 +298,25 @@ 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.graalFactory != null) {
|
if (nashornNames.contains(language) && this.nashornFactory != null) {
|
||||||
ScriptEngine scriptEngine = getGraalJSEngine();
|
ScriptEngine scriptEngine;
|
||||||
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.graalFactory;
|
NashornScriptEngineFactory nashornScriptEngineFactory = (NashornScriptEngineFactory) this.nashornFactory;
|
||||||
// scriptEngine = nashornScriptEngineFactory.getScriptEngine(filter);
|
scriptEngine = nashornScriptEngineFactory.getScriptEngine(filter);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
scriptEngine = this.graalFactory.getScriptEngine();
|
scriptEngine = this.nashornFactory.getScriptEngine();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
scriptEngine = this.graalFactory.getScriptEngine();
|
scriptEngine = this.nashornFactory.getScriptEngine();
|
||||||
}
|
}
|
||||||
scriptEngine.setBindings(this.manager.getBindings(), ScriptContext.GLOBAL_SCOPE);
|
scriptEngine.setBindings(this.manager.getBindings(), ScriptContext.GLOBAL_SCOPE);
|
||||||
return scriptEngine;
|
return scriptEngine;
|
||||||
@@ -331,22 +324,6 @@ 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,6 +1,7 @@
|
|||||||
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;
|
||||||
@@ -127,7 +128,7 @@ public class Action implements IAction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IAction setData(String key, Object v) {
|
public IAction addData(String key, Object v) {
|
||||||
dataStore.put(key, v);
|
dataStore.put(key, v);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -138,11 +139,6 @@ 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,11 +136,7 @@ public class ScriptWorld implements IWorld {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public IBlock getTopBlock(int x, int z) {
|
public IBlock getTopBlock(int x, int z) {
|
||||||
int yAbove = world.getTopSolidOrLiquidBlock(x, z);
|
return NpcAPI.Instance().getIBlock(this, x, world.getTopSolidOrLiquidBlock(x, z), 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