mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-19 11:59:26 +00:00
added a config that determines the order loaded scripts are run in
This commit is contained in:
1 parent
43bf4d3427
commit
7044d8ed63
3 files changed
+27
-9
No files matched your search
@@ -616,6 +616,10 @@ public class ProfileController implements IProfileHandler {
|
||||
ISlot slot = profile.getSlots().get(profile.getCurrentSlotId());
|
||||
if (slot == null)
|
||||
return;
|
||||
|
||||
PlayerData pdata = PlayerData.get(player);
|
||||
pdata.profileSlot = profile.getCurrentSlotId();
|
||||
|
||||
for (IProfileData profileData : profileTypes.values()) {
|
||||
NBTTagCompound data;
|
||||
if (slot.getComponents().containsKey(profileData.getTagName()))
|
||||
@@ -628,10 +632,6 @@ public class ProfileController implements IProfileHandler {
|
||||
profileData.save(player);
|
||||
}
|
||||
|
||||
PlayerData pdata = PlayerData.get(player);
|
||||
pdata.profileSlot = profile.getCurrentSlotId();
|
||||
pdata.save();
|
||||
|
||||
if (ConfigMain.AttributesEnabled)
|
||||
AttributeController.getTracker(player).recalcAttributes(player);
|
||||
}
|
||||
|
||||
@@ -55,6 +55,9 @@ public class ConfigScript {
|
||||
public static Property EnableBannedClassesProperty;
|
||||
public static boolean EnableBannedClasses = false;
|
||||
|
||||
public static Property RunLoadedScriptsFirstProperty;
|
||||
public static boolean RunLoadedScriptsFirst = true;
|
||||
|
||||
public static Property BannedClassesProperty;
|
||||
public final static HashSet<String> BannedClasses = new HashSet<>();
|
||||
|
||||
@@ -108,6 +111,12 @@ public class ConfigScript {
|
||||
EnableBannedClassesProperty = config.get(CUSTOMIZATION, "Enable Banned Classes", false, "Enables the Banned Classes Functionality");
|
||||
EnableBannedClasses = EnableBannedClassesProperty.getBoolean(false);
|
||||
|
||||
RunLoadedScriptsFirstProperty = config.get(CUSTOMIZATION, "Run Loaded Scripts First", true,
|
||||
"If scripts have been loaded from the scripting GUI, the script engine will evaluates them by\n" +
|
||||
"merging your loaded scripts with your main script, then running the combined script.\n" +
|
||||
"This config determines the order in while the loaded scripts are merged with your main scripts: before (true), or after (false).");
|
||||
RunLoadedScriptsFirst = RunLoadedScriptsFirstProperty.getBoolean(true);
|
||||
|
||||
BannedClassesProperty = config.get(CUSTOMIZATION, "Banned Classes", "java.net.URL,java.net.URI",
|
||||
"Comma separated list of classes that cannot be used in scripts through Java.for().\n" +
|
||||
"Classes must be fully written out with library names preceding them.\n" +
|
||||
|
||||
@@ -93,22 +93,31 @@ public class ScriptContainer {
|
||||
if (!this.evaluated) {
|
||||
// build includes first
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String loc : this.scripts) {
|
||||
String code = ScriptController.Instance.scripts.get(loc);
|
||||
if (code != null && !code.isEmpty()) {
|
||||
sb.append(code).append("\n");
|
||||
}
|
||||
if (ConfigScript.RunLoadedScriptsFirst) {
|
||||
this.appendExternalScripts(sb);
|
||||
}
|
||||
// then your per‐hook script
|
||||
if (this.script != null && !this.script.isEmpty()) {
|
||||
sb.append(this.script).append("\n");
|
||||
}
|
||||
if (!ConfigScript.RunLoadedScriptsFirst) {
|
||||
this.appendExternalScripts(sb);
|
||||
}
|
||||
this.fullscript = sb.toString();
|
||||
this.unknownFunctions = new HashSet<>();
|
||||
}
|
||||
return this.fullscript;
|
||||
}
|
||||
|
||||
private void appendExternalScripts(StringBuilder sb) {
|
||||
for (String loc : this.scripts) {
|
||||
String code = ScriptController.Instance.scripts.get(loc);
|
||||
if (code != null && !code.isEmpty()) {
|
||||
sb.append(code).append("\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void run(ScriptEngine engine) {
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
|
||||
Reference in new issue
Block a user