Skip to content

Instantly share code, notes, and snippets.

@leetrout
Created February 26, 2023 04:58
Show Gist options
  • Save leetrout/ef6cd27fe6661c279ac30ce61faae5bb to your computer and use it in GitHub Desktop.
Save leetrout/ef6cd27fe6661c279ac30ce61faae5bb to your computer and use it in GitHub Desktop.
Minecraft WorldEdit debug script
/**
* Small helper script to debug via printing in WorldEdit CraftScript.
* Save this file as debug.js in your WorldEdit config folder:
* e.g. config/worldedit/craftscript/debug.js
*
* Use in the console:
* /cs debug
* /cs debug player
*
* With no arguments this script will print all globals.
*
* With one argument this script will print the properties
* of the object.
*/
var global = this;
function allProps(someObj) {
Object.getOwnPropertyNames(someObj)
.sort()
.map((x) => context.print(x));
}
function localProps(someObj) {
Object.keys(someObj)
.sort()
.map((x) => context.print(x));
}
function main() {
context.print("");
context.print("Debug script for CraftScript");
context.print("--------------------------------");
if (argv.length > 1) {
var x = argv[1];
var obj = global[x];
context.print("Inspecting " + x + "(" + obj + ")");
localProps(obj);
} else {
allProps(global);
}
context.print("--------------------------------");
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment