Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pluginManager.register("NPCKit", function(lib) {
- var usage = "/npc <create|say|teleportTo|stop> ...";
- var usageCreate = "/npc create <NPC name> <Entity ID> [Command to run on click]";
- var usageSay = "/npc say <NPC name> <Text>";
- var usageTP = "/npc teleportTo <x> <y> <z>";
- var errorColor = "rgb(255,0,0)";
- var command = lib.getBlock().command + " ";
- var type = lib.getBlock().type;
- var conditional = lib.getBlock().conditional;
- var auto = lib.getBlock().auto;
- if(command.indexOf("/npc ") == 0 || command.indexOf("npc") == 0) {
- //Is a /npc command
- command = command.substring(0,command.length-1)
- var args = command.split(" ");
- //Split the string between spaces, and get an array out of it.
- if(args.length <= 1) {
- lib.break();
- lib.throw("Error: No arguments found for /npc command. Usage: " + usage + "\n(At line " + lib.getLineNumber() + ")", errorColor);
- }
- if(args.length >= 1 && args[1] == "create") {
- if(args[2] != null && args[2].length >= 1) {
- if(args[3] != null) {
- lib.newBefore("/give @p minecraft:spawn_egg 1 0 {display:{Name:\"" + args[2] + "\"},EntityTag:{id:\"" + args[3] + "\",Tags:[\"" + args[2] + "\"],Offers:{Recipes:[]},NoAI:1b,IsBaby:0b}}");
- if(args[4] != null) {
- var clickCMD = args.slice(4).join(" ");
- lib.newBefore("/scoreboard objectives add npcClick stat.talkedToVillager");
- lib.newCommand("/execute @a[score_npcClick_min=1] ~ ~ ~ /execute @e[tag=" + args[2] + "] ~ ~ ~ /execute @a[r=5,score_npcClick_min=1] ~ ~ ~ /execute @e[tag=" + args[2] + ",c=1] ~ ~ ~ " + clickCMD, type, conditional, auto);
- }
- } else {
- lib.break();
- lib.throw("Error: No entity ID found.\n(At line " + lib.getLineNumber() + ")", errorColor);
- }
- } else {
- lib.break();
- lib.throw("Error: No NPC name found.\n(At line " + lib.getLineNumber() + ")", errorColor);
- }
- lib.skip();
- }
- if(args.length >= 1 && args[1] == "say") {
- if(args[2] == null) {
- lib.break();
- lib.throw("Error: No NPC name found.\n(At line " + lib.getLineNumber() + ")", errorColor);
- } else {
- var sayString = args.slice(3).join(" ");
- lib.setCommand("/execute @e[tag=" + args[2] + "] ~ ~ ~ /say " + sayString);
- }
- }
- if(args.length >= 1 && args[1] == "teleportTo") {
- if(args[2] == null) {
- lib.break();
- lib.throw("Error: No NPC name found.\n(At line " + lib.getLineNumber() + ")", errorColor);
- } else if(args[3] == null) {
- lib.break();
- lib.throw("Error: No X coordinate found.\n(At line " + lib.getLineNumber() + ")", errorColor);
- } else if(args[4] == null) {
- lib.break();
- lib.throw("Error: No Y coordinate found.\n(At line " + lib.getLineNumber() + ")", errorColor);
- } else if(args[5] == null) {
- lib.break();
- lib.throw("Error: No Z coordinate found.\n(At line " + lib.getLineNumber() + ")", errorColor);
- } else {
- lib.setCommand("/tp @e[tag=" + args[2] + "] " + args[3] + " " + args[4] + " " + args[5]);
- }
- }
- if(args.length >= 1 && args[1] == "stop") {
- lib.setCommand("/scoreboard players reset @a[score_npcClick_min=1] npcClick");
- }
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment