Skip to content

Commit

Permalink
add ScriptEvent encoding for weird symbols to prevent bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Dec 9, 2019
1 parent c392128 commit 49c56f4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,14 @@ else if (evt.str.contains("@")) {
continue;
}
for (StringHolder evt1 : config.getKeys(false)) {
String evt = evt1.str.substring(3);
paths.add(new ScriptPath(container, evt));
String evt = evt1.str.substring(3).replace("&dot", ".").replace("&amp", "&");
ScriptPath path = new ScriptPath(container, evt);
path.set = path.container.getSetFor("events." + evt1);
if (path.set == null) {
Debug.echoError("Script path '" + path + "' is invalid.");
continue;
}
paths.add(path);
}
}
for (ScriptEvent event : events) {
Expand Down Expand Up @@ -425,9 +431,6 @@ public void run(ScriptPath path) {
Debug.echoDebug(path.container, "<Y>Context '<A>" + obj.getKey() + "<Y>' = '<A>" + obj.getValue().identify() + "<Y>'");
}
}
if (path.set == null) {
path.set = path.container.getSetFor("events.on " + path.event);
}
List<ScriptEntry> entries = ScriptContainer.cleanDup(getScriptEntryData(), path.set);
ScriptQueue queue = new InstantQueue(path.container.getName()).addEntries(entries);
HashMap<String, ObjectTag> oldStyleContext = getContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ public static void reloadScripts() {
ScriptRegistry.buildCoreYamlScriptContainers(_yamlScripts);
}

public static YamlConfiguration _gs() {
return getScripts();
}

private static YamlConfiguration getScripts() {
public static YamlConfiguration getScripts() {
if (_yamlScripts == null) {
reloadScripts();
}
Expand Down Expand Up @@ -113,10 +109,18 @@ else if (!trimmedLine.startsWith("#")) {
}
else {
String curLine = lines[lineNum].replace('\0', ' ');
if (!trimmedLine.endsWith(":") && trimmedLine.startsWith("-")) {
boolean endsColon = trimmedLine.endsWith(":");
boolean startsDash = trimmedLine.startsWith("-");
if (!endsColon && startsDash) {
curLine = curLine.replace(": ", "<&co> ");
curLine = curLine.replace("#", "<&ns>");
}
else if (endsColon && !startsDash) {
if (curLine.contains(".")) {
curLine = curLine.replace("&", "&amp").replace(".", "&dot");
Debug.log("Originally " + trimmedLine + " became " + curLine);
}
}
if (trimmedLine.startsWith("- ") && !trimmedLine.startsWith("- \"") && !trimmedLine.startsWith("- '")) {
int dashIndex = curLine.indexOf('-');
curLine = curLine.substring(0, dashIndex + 1) + " " + ScriptBuilder.LINE_PREFIX_CHAR + (lineNum + 1) + ScriptBuilder.LINE_PREFIX_CHAR + curLine.substring(dashIndex + 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static void attemptLoadSingle(String scriptName, boolean shouldErrorOnTyp
}
try {
scriptContainers.put(scriptName, (ScriptContainer) typeClass.getConstructor(YamlConfiguration.class, String.class)
.newInstance(ScriptHelper._gs().getConfigurationSection(scriptName), scriptName));
.newInstance(ScriptHelper.getScripts().getConfigurationSection(scriptName), scriptName));
}
catch (Exception e) {
Debug.echoError(e);
Expand Down

0 comments on commit 49c56f4

Please sign in to comment.