Energyxxer

Untitled

Oct 22nd, 2016
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1. pluginManager.register("NPCKit", function(lib) {
  2.  
  3. var usage = "/npc <create|say|teleportTo> ...";
  4. var usageCreate = "/npc create <NPC name> <Entity ID> [Command to run on click]";
  5. var usageSay = "/npc say <NPC name> <Text>";
  6. var usageTP = "/npc teleportTo <x> <y> <z>";
  7. var errorColor = "rgb(255,0,0)";
  8.  
  9. var command = lib.getBlock().command + " ";
  10.  
  11. var type = lib.getBlock().type;
  12. var conditional = lib.getBlock().conditional;
  13. var auto = lib.getBlock().auto;
  14.  
  15. if(command.indexOf("/npc ") == 0 || command.indexOf("npc") == 0) {
  16. //Is a /npc command
  17. command = command.substring(0,command.length-1);
  18. var args = command.split(" ");
  19. //Split the string between spaces, and get an array out of it.
  20.  
  21. if(args.length <= 1) {
  22. lib.break();
  23. lib.throw("Error: No arguments found for /npc command. Usage: " + usage + "\n(At line " + lib.getLineNumber() + ")", errorColor);
  24. }
  25.  
  26. if(args.length >= 1 && args[1] == "create") {
  27. if(args[2] != null && args[2].length >= 1) {
  28. if(args[3] != null) {
  29. lib.newBefore("/give @p minecraft:spawn_egg 1 0 {display:{Name:\"" + args[2] + "\"},EntityTag:{id:\"" + args[3] + "\",Tags:[\"" + args[2] + "\"],Offers:{Recipes:[]}}}");
  30. if(args[4] != null) {
  31. var uid = args[2].hashCode().toString().replace("-","_");
  32. var clickCMD = args.slice(4).join(" ");
  33. console.log(clickCMD);
  34. lib.newBefore("/scoreboard objectives add " + uid + "c stat.talkedToVillager");
  35. lib.newCommand("/execute @a[score_" + uid + "c_min=1] ~ ~ ~ /execute @e[tag=" + args[2] + "] ~ ~ ~ /execute @a[r=5,score_" + uid + "c_min=1] ~ ~ ~ /execute @e[tag=" + args[2] + ",c=1] ~ ~ ~ " + clickCMD, type, conditional, auto);
  36. lib.newCommand("/scoreboard players reset @a[score_" + uid + "c_min=1] " + uid + "c", "Chain", false, true);
  37. }
  38. } else {
  39. lib.break();
  40. lib.throw("Error: No entity ID found.\n(At line " + lib.getLineNumber() + ")", errorColor);
  41. }
  42. } else {
  43. lib.break();
  44. lib.throw("Error: No NPC name found.\n(At line " + lib.getLineNumber() + ")", errorColor);
  45. }
  46. lib.skip();
  47. }
  48.  
  49. if(args.length >= 1 && args[1] == "say") {
  50. if(args[2] == null) {
  51. lib.break();
  52. lib.throw("Error: No NPC name found.\n(At line " + lib.getLineNumber() + ")", errorColor);
  53. } else {
  54. var sayString = args.slice(3).join(" ");
  55. lib.setCommand("/execute @e[tag=" + args[2] + "] ~ ~ ~ /say " + sayString);
  56. }
  57. }
  58.  
  59. if(args.length >= 1 && args[1] == "teleportTo") {
  60. if(args[2] == null) {
  61. lib.break();
  62. lib.throw("Error: No NPC name found.\n(At line " + lib.getLineNumber() + ")", errorColor);
  63. } else if(args[3] == null) {
  64. lib.break();
  65. lib.throw("Error: No X coordinate found.\n(At line " + lib.getLineNumber() + ")", errorColor);
  66. } else if(args[4] == null) {
  67. lib.break();
  68. lib.throw("Error: No Y coordinate found.\n(At line " + lib.getLineNumber() + ")", errorColor);
  69. } else if(args[5] == null) {
  70. lib.break();
  71. lib.throw("Error: No Z coordinate found.\n(At line " + lib.getLineNumber() + ")", errorColor);
  72. } else {
  73. lib.setCommand("/tp @e[tag=" + args[2] + "] " + args[3] + " " + args[4] + " " + args[5]);
  74. }
  75. }
  76. }
  77.  
  78. });
Advertisement
Add Comment
Please, Sign In to add comment