mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-24 17:34:26 +00:00
Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7a4ced1065 | ||
|
|
23357b6a79 | ||
|
|
d355e64662 | ||
|
|
de3f71918c | ||
|
|
7b9f182e32 |
No files matched your search
+1
-7
@@ -5,13 +5,7 @@ plugins {
|
|||||||
id 'idea'
|
id 'idea'
|
||||||
}
|
}
|
||||||
|
|
||||||
java {
|
version = "1.10.1"
|
||||||
toolchain {
|
|
||||||
languageVersion.set(JavaLanguageVersion.of(8))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
version = "1.10.2"
|
|
||||||
group= "kamkeel.customnpc-plus"
|
group= "kamkeel.customnpc-plus"
|
||||||
archivesBaseName = "CustomNPC-Plus"
|
archivesBaseName = "CustomNPC-Plus"
|
||||||
|
|
||||||
|
|||||||
+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")
|
runtimeOnlyNonPublishable("curse.maven:Nashorn-374413:2924946")
|
||||||
|
|
||||||
if(embedMixin){
|
if(embedMixin){
|
||||||
// Normal Jar will include built in Mixins
|
// Normal Jar will include built in Mixins
|
||||||
|
|||||||
@@ -55,7 +55,6 @@ public final class RoleGetPacket extends AbstractPacket {
|
|||||||
|
|
||||||
NBTTagCompound compound = new NBTTagCompound();
|
NBTTagCompound compound = new NBTTagCompound();
|
||||||
compound.setBoolean("RoleData", true);
|
compound.setBoolean("RoleData", true);
|
||||||
compound.setInteger("RoleOrdinal", npc.advanced.role.ordinal());
|
|
||||||
GuiDataPacket.sendGuiData((EntityPlayerMP) player, npc.roleInterface.writeToNBT(compound));
|
GuiDataPacket.sendGuiData((EntityPlayerMP) player, npc.roleInterface.writeToNBT(compound));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -41,7 +41,7 @@ import noppes.npcs.scripted.NpcAPI;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@Mod(modid = "customnpcs", name = "CustomNPC+", version = "1.10.2")
|
@Mod(modid = "customnpcs", name = "CustomNPC+", version = "1.10.1")
|
||||||
public class CustomNpcs {
|
public class CustomNpcs {
|
||||||
|
|
||||||
@SidedProxy(clientSide = "noppes.npcs.client.ClientProxy", serverSide = "noppes.npcs.CommonProxy")
|
@SidedProxy(clientSide = "noppes.npcs.client.ClientProxy", serverSide = "noppes.npcs.CommonProxy")
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ public class GuiNpcAdvanced extends GuiNPCInterface2 implements IGuiData {
|
|||||||
@Override
|
@Override
|
||||||
public void setGuiData(NBTTagCompound compound) {
|
public void setGuiData(NBTTagCompound compound) {
|
||||||
if (compound.hasKey("RoleData")) {
|
if (compound.hasKey("RoleData")) {
|
||||||
npc.advanced.setRole(compound.getInteger("RoleOrdinal"));
|
npc.advanced.setRole(compound.getByte("RoleData"));
|
||||||
if (npc.roleInterface != null)
|
if (npc.roleInterface != null)
|
||||||
npc.roleInterface.readFromNBT(compound);
|
npc.roleInterface.readFromNBT(compound);
|
||||||
|
|
||||||
|
|||||||
@@ -136,20 +136,12 @@ public abstract class GuiDiagram extends Gui {
|
|||||||
String nameFrom = iconFrom != null ? getIconName(iconFrom) : "Unknown";
|
String nameFrom = iconFrom != null ? getIconName(iconFrom) : "Unknown";
|
||||||
String nameTo = iconTo != null ? getIconName(iconTo) : "Unknown";
|
String nameTo = iconTo != null ? getIconName(iconTo) : "Unknown";
|
||||||
tooltip.add(nameFrom + " > " + nameTo + ":");
|
tooltip.add(nameFrom + " > " + nameTo + ":");
|
||||||
// Split Hover Text by newlines
|
tooltip.add(conn.hoverText);
|
||||||
if (conn.hoverText != null && !conn.hoverText.isEmpty()) {
|
|
||||||
String[] lines = conn.hoverText.split("\n");
|
|
||||||
tooltip.addAll(Arrays.asList(lines));
|
|
||||||
}
|
|
||||||
if (allowTwoWay) {
|
if (allowTwoWay) {
|
||||||
DiagramConnection reverse = getConnectionByIds(conn.idTo, conn.idFrom);
|
DiagramConnection reverse = getConnectionByIds(conn.idTo, conn.idFrom);
|
||||||
if (reverse != null) {
|
if (reverse != null) {
|
||||||
tooltip.add(nameTo + " > " + nameFrom + ":");
|
tooltip.add(nameTo + " > " + nameFrom + ":");
|
||||||
// Split Hover Text by newlines
|
tooltip.add(reverse.hoverText);
|
||||||
if (reverse.hoverText != null && !reverse.hoverText.isEmpty()) {
|
|
||||||
String[] lines = reverse.hoverText.split("\n");
|
|
||||||
tooltip.addAll(Arrays.asList(lines));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tooltip;
|
return tooltip;
|
||||||
|
|||||||
@@ -30,10 +30,6 @@ import java.io.BufferedReader;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.lang.reflect.Proxy;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLClassLoader;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import static noppes.npcs.util.CustomNPCsThreader.customNPCThread;
|
import static noppes.npcs.util.CustomNPCsThreader.customNPCThread;
|
||||||
@@ -59,7 +55,6 @@ public class ScriptController {
|
|||||||
|
|
||||||
public GlobalNPCDataScript globalNpcScripts = new GlobalNPCDataScript((EntityNPCInterface) null);
|
public GlobalNPCDataScript globalNpcScripts = new GlobalNPCDataScript((EntityNPCInterface) null);
|
||||||
public long lastGlobalNpcUpdate = 0L;
|
public long lastGlobalNpcUpdate = 0L;
|
||||||
private URLClassLoader loader;
|
|
||||||
|
|
||||||
public ScriptController() {
|
public ScriptController() {
|
||||||
Instance = this;
|
Instance = this;
|
||||||
@@ -69,31 +64,34 @@ public class ScriptController {
|
|||||||
LogWriter.info("Script Engines Available:");
|
LogWriter.info("Script Engines Available:");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
File nashornJar = new File("mods/nashorn.jar"); // Adjust path if needed
|
this.nashornFactory = new NashornScriptEngineFactory();
|
||||||
this.loader = new URLClassLoader(new URL[]{nashornJar.toURI().toURL()}, CustomNpcs.class.getClassLoader());
|
LogWriter.info("→ standalone Nashorn loaded");
|
||||||
|
} catch (NoClassDefFoundError e) {
|
||||||
ClassLoader cl = CustomNpcs.class.getClassLoader();
|
|
||||||
Thread.currentThread().setContextClassLoader(cl);
|
|
||||||
LogWriter.info("ClassLoader: " + cl);
|
|
||||||
LogWriter.info("Parent: " + cl.getParent());
|
|
||||||
|
|
||||||
Class<?> factoryClass = Class.forName("jdk.nashorn.api.scripting.NashornScriptEngineFactory", true, loader);
|
|
||||||
this.nashornFactory = (ScriptEngineFactory) factoryClass.getDeclaredConstructor().newInstance();
|
|
||||||
this.languages.put("ECMAScript", ".js");
|
|
||||||
LogWriter.info("→ standalone Nashorn loaded: " + this.nashornFactory.getEngineName());
|
|
||||||
} 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.nashornFactory = eng.getFactory();
|
||||||
this.languages.put("ECMAScript", ".js");
|
|
||||||
LogWriter.info("→ built-in Nashorn loaded");
|
LogWriter.info("→ built-in Nashorn loaded");
|
||||||
}
|
}
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
LogWriter.error("No Nashorn engine available");
|
LogWriter.error("No Nashorn engine available");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (ScriptEngineFactory fac : manager.getEngineFactories()) {
|
||||||
|
if (fac.getExtensions().isEmpty())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
ScriptEngine scriptEngine = fac.getScriptEngine();
|
||||||
|
try {
|
||||||
|
scriptEngine.put("$RunTest", null);
|
||||||
|
String ext = "." + fac.getExtensions().get(0).toLowerCase();
|
||||||
|
LogWriter.info("Engine " + fac.getEngineName() + " running " + fac.getLanguageName() + " with extension: " + ext);
|
||||||
|
languages.put(fac.getLanguageName(), ext);
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private File forgeScriptsFile() {
|
private File forgeScriptsFile() {
|
||||||
@@ -301,113 +299,31 @@ public class ScriptController {
|
|||||||
|
|
||||||
public ScriptEngine getEngineByName(String language) {
|
public ScriptEngine getEngineByName(String language) {
|
||||||
if (nashornNames.contains(language) && this.nashornFactory != null) {
|
if (nashornNames.contains(language) && this.nashornFactory != null) {
|
||||||
try {
|
|
||||||
ScriptEngine scriptEngine;
|
ScriptEngine scriptEngine;
|
||||||
Class<?> factoryClass = Class.forName("jdk.nashorn.api.scripting.NashornScriptEngineFactory",
|
|
||||||
true, this.loader);
|
|
||||||
|
|
||||||
if (ConfigScript.EnableBannedClasses) {
|
if (ConfigScript.EnableBannedClasses) {
|
||||||
Class<?> classFilterClass = Class.forName("jdk.nashorn.api.scripting.ClassFilter",
|
try {
|
||||||
true, this.loader);
|
ClassFilter filter = s -> {
|
||||||
|
for (String className : ConfigScript.BannedClasses) {
|
||||||
Object classFilter = Proxy.newProxyInstance(
|
if (s.compareTo(className) == 0) {
|
||||||
classFilterClass.getClassLoader(),
|
return false;
|
||||||
new Class[]{classFilterClass},
|
}
|
||||||
(proxy, method, args) -> {
|
|
||||||
if ("exposeToScripts".equals(method.getName()) && args.length == 1) {
|
|
||||||
String className = (String) args[0];
|
|
||||||
for (String banned : ConfigScript.BannedClasses) {
|
|
||||||
if (className.equals(banned)) return false;
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
};
|
||||||
|
NashornScriptEngineFactory nashornScriptEngineFactory = (NashornScriptEngineFactory) this.nashornFactory;
|
||||||
|
scriptEngine = nashornScriptEngineFactory.getScriptEngine(filter);
|
||||||
|
} catch (Exception e) {
|
||||||
|
scriptEngine = this.nashornFactory.getScriptEngine();
|
||||||
}
|
}
|
||||||
throw new UnsupportedOperationException("Unsupported method: " + method);
|
|
||||||
});
|
|
||||||
|
|
||||||
Method getScriptEngine = factoryClass.getMethod(
|
|
||||||
"getScriptEngine",
|
|
||||||
classFilterClass);
|
|
||||||
|
|
||||||
scriptEngine = (ScriptEngine) getScriptEngine.invoke(this.nashornFactory, classFilter);
|
|
||||||
} else {
|
} else {
|
||||||
Method getScriptEngine = factoryClass.getMethod("getScriptEngine");
|
scriptEngine = this.nashornFactory.getScriptEngine();
|
||||||
scriptEngine = (ScriptEngine) getScriptEngine.invoke(this.nashornFactory);
|
|
||||||
}
|
}
|
||||||
scriptEngine.setBindings(this.manager.getBindings(), ScriptContext.GLOBAL_SCOPE);
|
scriptEngine.setBindings(this.manager.getBindings(), ScriptContext.GLOBAL_SCOPE);
|
||||||
return scriptEngine;
|
return scriptEngine;
|
||||||
} catch (Exception exception) {
|
|
||||||
LogWriter.except(exception);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return manager.getEngineByName(language);
|
return manager.getEngineByName(language);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ScriptEngine getOpenJDKNashornEngine() {
|
|
||||||
ScriptEngine engine;
|
|
||||||
try {
|
|
||||||
// Load factory and class filter
|
|
||||||
Class<?> factoryClass = Class.forName("org.openjdk.nashorn.api.scripting.NashornScriptEngineFactory");
|
|
||||||
Object factory = factoryClass.getConstructor().newInstance();
|
|
||||||
|
|
||||||
// Load ClassFilter interface (from Nashorn 15.6)
|
|
||||||
Class<?> classFilterClass = Class.forName("org.openjdk.nashorn.api.scripting.ClassFilter");
|
|
||||||
|
|
||||||
Object classFilter;
|
|
||||||
if (ConfigScript.EnableBannedClasses) {
|
|
||||||
// Create proxy instance of ClassFilter
|
|
||||||
classFilter = Proxy.newProxyInstance(
|
|
||||||
classFilterClass.getClassLoader(),
|
|
||||||
new Class[]{classFilterClass},
|
|
||||||
(proxy, method, args) -> {
|
|
||||||
if ("exposeToScripts".equals(method.getName()) && args.length == 1) {
|
|
||||||
String className = (String) args[0];
|
|
||||||
for (String banned : ConfigScript.BannedClasses) {
|
|
||||||
if (className.equals(banned)) return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
throw new UnsupportedOperationException("Unsupported method: " + method);
|
|
||||||
});
|
|
||||||
|
|
||||||
Method getEngineMethod = factoryClass.getMethod(
|
|
||||||
"getScriptEngine",
|
|
||||||
String[].class,
|
|
||||||
ClassLoader.class,
|
|
||||||
classFilterClass
|
|
||||||
);
|
|
||||||
|
|
||||||
String[] args = new String[] {
|
|
||||||
"--language=es6",
|
|
||||||
"--optimistic-types=true",
|
|
||||||
"--lazy-compilation=true"
|
|
||||||
};
|
|
||||||
ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
|
||||||
|
|
||||||
engine = (ScriptEngine) getEngineMethod.invoke(
|
|
||||||
factory,
|
|
||||||
(Object) args,
|
|
||||||
loader,
|
|
||||||
classFilter
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
Method getEngineMethod = factoryClass.getMethod("getScriptEngine", String[].class);
|
|
||||||
String[] args = new String[] {
|
|
||||||
"--language=es6",
|
|
||||||
"--optimistic-types=true",
|
|
||||||
"--lazy-compilation=true"
|
|
||||||
};
|
|
||||||
engine = (ScriptEngine) getEngineMethod.invoke(factory, (Object) args);
|
|
||||||
}
|
|
||||||
|
|
||||||
engine.setBindings(this.manager.getBindings(), ScriptContext.GLOBAL_SCOPE);
|
|
||||||
return engine;
|
|
||||||
} catch (Exception ignored) {
|
|
||||||
ignored.printStackTrace();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ public class ModelPartData {
|
|||||||
public byte pattern = 0;
|
public byte pattern = 0;
|
||||||
public boolean playerTexture;
|
public boolean playerTexture;
|
||||||
|
|
||||||
public ResourceLocation location;
|
private ResourceLocation location;
|
||||||
|
|
||||||
public ModelPartData() {
|
public ModelPartData() {
|
||||||
playerTexture = true;
|
playerTexture = true;
|
||||||
|
|||||||
Reference in new issue
Block a user