forked from StarOpenSource/Engine
Document processCrashContent, add List support
This commit is contained in:
parent
c984974252
commit
1a56f42287
1 changed files with 56 additions and 25 deletions
|
@ -25,6 +25,7 @@ import de.staropensource.sosengine.base.classes.Placeholder;
|
||||||
import de.staropensource.sosengine.base.events.EngineCrashEvent;
|
import de.staropensource.sosengine.base.events.EngineCrashEvent;
|
||||||
import de.staropensource.sosengine.base.events.EngineSoftCrashEvent;
|
import de.staropensource.sosengine.base.events.EngineSoftCrashEvent;
|
||||||
import de.staropensource.sosengine.base.internal.placeholders.crashhandler.*;
|
import de.staropensource.sosengine.base.internal.placeholders.crashhandler.*;
|
||||||
|
import de.staropensource.sosengine.base.types.EngineState;
|
||||||
import de.staropensource.sosengine.base.types.logging.LogLevel;
|
import de.staropensource.sosengine.base.types.logging.LogLevel;
|
||||||
import de.staropensource.sosengine.base.utility.PlaceholderEngine;
|
import de.staropensource.sosengine.base.utility.PlaceholderEngine;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
@ -180,49 +181,79 @@ Dear developer: FIX YOUR GODDAMN SHIT! Please check if your code or 3rd party su
|
||||||
/*
|
/*
|
||||||
* Note: This entire method causes a compilation warning as we are using "unchecked or unsecure operations".
|
* Note: This entire method causes a compilation warning as we are using "unchecked or unsecure operations".
|
||||||
* We can safely ignore this as this method
|
* We can safely ignore this as this method
|
||||||
* 1. checks data types as best as it can,
|
* 1. checks data types before using them,
|
||||||
* 2. only works on a String and not on a File or something which could cause damage, and
|
* 2. only works on Strings, Lists and LinkedHashMaps and not on Files or something which could cause damage, and
|
||||||
* 3. we can trust our own engine and possibly subsystems not doing shit in here.
|
* 3. we can trust our own engine and possibly subsystems not doing shit in here.
|
||||||
* As a subsystem developer you'll likely want useful crash information.
|
* As a subsystem developer you'll likely want useful crash information.
|
||||||
*
|
*
|
||||||
* But hey, if someone breaks this method (which may be possible idk didn't test it) then congrats!
|
* But hey, if someone breaks this method (which may be possible idk didn't test it) then congrats!
|
||||||
*/
|
*/
|
||||||
private static synchronized @NotNull String processCrashContent(@NotNull LinkedHashMap<Object, Object> map, int indentationSize) {
|
private static @NotNull String processCrashContent(@NotNull LinkedHashMap<Object, Object> map, int indentationSize) {
|
||||||
StringBuilder content = new StringBuilder();
|
StringBuilder content = new StringBuilder();
|
||||||
|
|
||||||
for (Object key : map.keySet()) {
|
for (Object key : map.keySet()) {
|
||||||
|
// Ensure key is of type String
|
||||||
if (!(key instanceof String))
|
if (!(key instanceof String))
|
||||||
// Invalid content key, skip
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!(map.get(key) instanceof LinkedHashMap<?, ?> || map.get(key) instanceof String))
|
// Ensure value is of type String, List or LinkedHashMap
|
||||||
|
if (!(map.get(key) instanceof String
|
||||||
|
|| map.get(key) instanceof List<?>
|
||||||
|
|| map.get(key) instanceof LinkedHashMap<?, ?>))
|
||||||
// Invalid content value, skip
|
// Invalid content value, skip
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/*
|
// Add newline
|
||||||
* I'm too lazy to describe what you are seeing down below,
|
|
||||||
* so uuhhh just try breaking it and see what happens.
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (!content.isEmpty())
|
if (!content.isEmpty())
|
||||||
content.append("\n");
|
content.append("\n");
|
||||||
|
|
||||||
if (map.get(key) == null) {
|
// Indent key
|
||||||
if (indentationSize == 0) content.append("\n");
|
if (indentationSize == 0)
|
||||||
else content.append(" ".repeat(indentationSize)).append("-> ");
|
content.append("\n");
|
||||||
content.append(key);
|
else
|
||||||
} else if (map.get(key) instanceof String) {
|
content
|
||||||
if (indentationSize == 0) content.append("\n");
|
.append(" ".repeat(indentationSize))
|
||||||
else content.append(" ".repeat(indentationSize)).append("-> ");
|
.append("-> ");
|
||||||
content.append(key).append(": ").append(map.get(key));
|
|
||||||
} else {
|
|
||||||
if (indentationSize == 0) content.append("\n");
|
|
||||||
else content.append(" ".repeat(indentationSize)).append("-> ");
|
|
||||||
content.append(key).append("\n");
|
|
||||||
|
|
||||||
//noinspection unchecked
|
if (map.get(key) == null)
|
||||||
content.append(processCrashContent((LinkedHashMap<Object, Object>) map.get(key), indentationSize + 1));
|
// Append key name, there's no content
|
||||||
|
// Format: %key%
|
||||||
|
content.append(key);
|
||||||
|
else if (map.get(key) instanceof String)
|
||||||
|
// Append key and it's value
|
||||||
|
// Format: %key%: %value%
|
||||||
|
content
|
||||||
|
.append(key)
|
||||||
|
.append(": ")
|
||||||
|
.append(map.get(key));
|
||||||
|
else if (map.get(key) instanceof List<?>) {
|
||||||
|
// Append key and list the list's contents
|
||||||
|
content.append(key);
|
||||||
|
|
||||||
|
for (Object item : (List<?>) map.get(key)) {
|
||||||
|
if (item instanceof String)
|
||||||
|
item = ((String) item)
|
||||||
|
.replace("\\", "\\\\")
|
||||||
|
.replace("\n", "\\n")
|
||||||
|
.replace("\"", "\\\"");
|
||||||
|
|
||||||
|
content
|
||||||
|
.append("\n")
|
||||||
|
.append(" ".repeat(indentationSize))
|
||||||
|
.append(" -> ")
|
||||||
|
.append(item);
|
||||||
}
|
}
|
||||||
|
} else
|
||||||
|
// So this one processes a map recursively
|
||||||
|
// Format:
|
||||||
|
// -> %parent_key%
|
||||||
|
// -> %child_key0%: %child_value0%
|
||||||
|
// -> %child_key1%
|
||||||
|
// -> %nested_key0%: %nested_value0%
|
||||||
|
// -> %nested_key1%: %nested_value1%
|
||||||
|
// -> %child_key2%: %child_value1%
|
||||||
|
//noinspection unchecked
|
||||||
|
content.append(key).append("\n").append(processCrashContent((LinkedHashMap<Object, Object>) map.get(key), indentationSize + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
return content.toString();
|
return content.toString();
|
||||||
|
@ -234,7 +265,7 @@ Dear developer: FIX YOUR GODDAMN SHIT! Please check if your code or 3rd party su
|
||||||
* @return crash content string
|
* @return crash content string
|
||||||
* @since v1-alpha0
|
* @since v1-alpha0
|
||||||
*/
|
*/
|
||||||
public static synchronized String processCrashContent() {
|
public static String processCrashContent() {
|
||||||
return processCrashContent(crashContent, 0);
|
return processCrashContent(crashContent, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue