Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pluginManager.register("Relative Blocks Beta",null,null,function(lib,storage){
- for(var i = 0; i < lib.beforeCommands.length(); i++) {
- var command = lib.beforeCommands.get(i);
- while(command.contains("$pos")) {
- if(storage == undefined) {
- storage = {};
- }
- var declarationStart = command.indexOf("$pos");
- var declarationEnd = declarationStart + command.substring(declarationStart).indexOf(";")+1;
- var replacementValue = "";
- if(declarationEnd <= declarationStart) {
- lib.throw("Error: [RELATIVE] Invalid position declaration in before command. Expected semicolon.","rgba(255,63,63,.75)");
- lib.break();
- return null;
- }
- var declaration = command.substring(declarationStart+4,declarationEnd-1).trim();
- var args = declaration.split(" ");
- var name = args[0];
- if(["set","add","get"].contains(args[1])) {
- if(args[1] == "set") {
- _set(name);
- } else if(args[1] == "add") {
- if(!["x","y","z"].contains(args[2].toLowerCase())) {
- lib.throw("Error: [RELATIVE] Invalid addition operation in before command. Expected \"x\", \"y\" or \"z\", but instead got \"" + args[2] + "\".","rgba(255,63,63,.75)");
- lib.break();
- return null;
- }
- if(isNaN(parseFloat(args[3]))) {
- lib.throw("Error: [RELATIVE] Invalid addition operation in before command. Expected a number, but instead got \"" + args[3] + "\".","rgba(255,63,63,.75)");
- lib.break();
- return null;
- }
- if(_add(name,args[2].toLowerCase(),parseFloat(args[3])) == null) {
- return null;
- }
- } else if(args[1] == "get") {
- if(_get(name) == null) {
- return null;
- } else {
- replacementValue = _get(name);
- }
- }
- } else {
- lib.throw("Error: [RELATIVE] Invalid position operation in before command. Expected \"set\", \"get\" or \"add\", but instead got \"" + args[1] + "\".","rgba(255,63,63,.75)");
- lib.break();
- return null;
- }
- command = (command.substring(0,declarationStart) + replacementValue + command.substring(declarationEnd)).trim()
- lib.beforeCommands.set(i,command);
- function _set(name) {
- storage[name] = {};
- storage[name].x = 0;
- storage[name].y = -2;
- storage[name].z = 0;
- replacementValue = "";
- }
- function _add(name,axis,offset) {
- if(name in storage) {
- storage[name][axis] += offset;
- replacementValue = "";
- return true;
- } else {
- lib.throw("Error: [RELATIVE] Could not find position " + name + ". Position not declared.","rgba(255,63,63,.75)");
- lib.break();
- return null;
- }
- }
- function _get(name) {
- if(name in storage) {
- return ("~" + (storage[name].x) + " ~" + (storage[name].y) + " ~" + (storage[name].z)).replaceAll("~0","~");
- } else {
- lib.throw("Error: [RELATIVE] Could not find position " + name + ". Position not declared.","rgba(255,63,63,.75)");
- lib.break();
- return null;
- }
- }
- }
- }
- for(var i = 0; i < lib.afterCommands.length(); i++) {
- var command = lib.afterCommands.get(i);
- while(command.contains("$pos")) {
- if(storage == undefined) {
- storage = {};
- }
- var declarationStart = command.indexOf("$pos");
- var declarationEnd = declarationStart + command.substring(declarationStart).indexOf(";")+1;
- var replacementValue = "";
- if(declarationEnd <= declarationStart) {
- lib.throw("Error: [RELATIVE] Invalid position declaration in after command. Expected semicolon.","rgba(255,63,63,.75)");
- lib.break();
- return null;
- }
- var declaration = command.substring(declarationStart+4,declarationEnd-1).trim();
- var args = declaration.split(" ");
- var name = args[0];
- if(["set","add","get"].contains(args[1])) {
- if(args[1] == "set") {
- _set(name);
- } else if(args[1] == "add") {
- if(!["x","y","z"].contains(args[2].toLowerCase())) {
- lib.throw("Error: [RELATIVE] Invalid addition operation in after command. Expected \"x\", \"y\" or \"z\", but instead got \"" + args[2] + "\".","rgba(255,63,63,.75)");
- lib.break();
- return null;
- }
- if(isNaN(parseFloat(args[3]))) {
- lib.throw("Error: [RELATIVE] Invalid addition operation in after command. Expected a number, but instead got \"" + args[3] + "\".","rgba(255,63,63,.75)");
- lib.break();
- return null;
- }
- if(_add(name,args[2].toLowerCase(),parseFloat(args[3])) == null) {
- return null;
- }
- } else if(args[1] == "get") {
- if(_get(name) == null) {
- return null;
- } else {
- replacementValue = _get(name);
- }
- }
- } else {
- lib.throw("Error: [RELATIVE] Invalid position operation in after command. Expected \"set\", \"get\" or \"add\", but instead got \"" + args[1] + "\".","rgba(255,63,63,.75)");
- lib.break();
- return null;
- }
- command = (command.substring(0,declarationStart) + replacementValue + command.substring(declarationEnd)).trim()
- lib.afterCommands.set(i,command);
- function _set(name) {
- storage[name] = {};
- storage[name].x = 0;
- storage[name].y = -2;
- storage[name].z = 0;
- replacementValue = "";
- }
- function _add(name,axis,offset) {
- if(name in storage) {
- storage[name][axis] += offset;
- replacementValue = "";
- return true;
- } else {
- lib.throw("Error: [RELATIVE] Could not find position " + name + ". Position not declared.","rgba(255,63,63,.75)");
- lib.break();
- return null;
- }
- }
- function _get(name) {
- if(name in storage) {
- return ("~" + (storage[name].x) + " ~" + (storage[name].y) + " ~" + (storage[name].z)).replaceAll("~0","~");
- } else {
- lib.throw("Error: [RELATIVE] Could not find position " + name + ". Position not declared.","rgba(255,63,63,.75)");
- lib.break();
- return null;
- }
- }
- }
- }
- },function(lib, storage){
- var command = lib.getBlock().command + " ";
- while(command.contains("$pos")) {
- if(storage == undefined) {
- storage = {};
- }
- var declarationStart = command.indexOf("$pos");
- var declarationEnd = declarationStart + command.substring(declarationStart).indexOf(";")+1;
- var replacementValue = "";
- if(declarationEnd <= declarationStart) {
- lib.throw("Error: [RELATIVE] Invalid position declaration at line " + lib.getLineNumber().toString() + ". Expected semicolon.","rgba(255,63,63,.75)");
- lib.break();
- return null;
- }
- var declaration = command.substring(declarationStart+4,declarationEnd-1).trim();
- var args = declaration.split(" ");
- var name = args[0];
- if(["set","add","get"].contains(args[1])) {
- if(args[1] == "set") {
- _set(name);
- } else if(args[1] == "add") {
- if(!["x","y","z"].contains(args[2].toLowerCase())) {
- lib.throw("Error: [RELATIVE] Invalid addition operation at line " + lib.getLineNumber().toString() + ". Expected \"x\", \"y\" or \"z\", but instead got \"" + args[2] + "\".","rgba(255,63,63,.75)");
- lib.break();
- return null;
- }
- if(isNaN(parseFloat(args[3]))) {
- lib.throw("Error: [RELATIVE] Invalid addition operation at line " + lib.getLineNumber().toString() + ". Expected a number, but instead got \"" + args[3] + "\".","rgba(255,63,63,.75)");
- lib.break();
- return null;
- }
- if(_add(name,args[2].toLowerCase(),parseFloat(args[3])) == null) {
- return null;
- }
- } else if(args[1] == "get") {
- if(_get(name) == null) {
- return null;
- } else {
- replacementValue = _get(name);
- }
- }
- } else {
- lib.throw("Error: [RELATIVE] Invalid position operation at line " + lib.getLineNumber().toString() + ". Expected \"set\", \"get\" or \"add\", but instead got \"" + args[1] + "\".","rgba(255,63,63,.75)");
- lib.break();
- return null;
- }
- command = (command.substring(0,declarationStart) + replacementValue + command.substring(declarationEnd)).trim()
- lib.setCommand(command);
- function _set(name) {
- storage[name] = {};
- storage[name].x = lib.getBlock().pos.x;
- storage[name].y = lib.getBlock().pos.y;
- storage[name].z = lib.getBlock().pos.z;
- replacementValue = "";
- }
- function _add(name,axis,offset) {
- if(name in storage) {
- storage[name][axis] += offset;
- replacementValue = "";
- return true;
- } else {
- lib.throw("Error: [RELATIVE] Could not find position " + name + ". Line " + lib.getLineNumber().toString() + ". Position not declared.","rgba(255,63,63,.75)");
- lib.break();
- return null;
- }
- }
- function _get(name) {
- if(name in storage) {
- return ("~" + (storage[name].x - lib.getBlock().pos.x) + " ~" + (storage[name].y - lib.getBlock().pos.y) + " ~" + (storage[name].z - lib.getBlock().pos.z)).replaceAll("~0","~");
- } else {
- lib.throw("Error: [RELATIVE] Could not find position " + name + ". Line " + lib.getLineNumber().toString() + ". Position not declared.","rgba(255,63,63,.75)");
- lib.break();
- return null;
- }
- }
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment