copyisland.txt 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. event.load("block_click");
  2. event.load("block_break");
  3. event.load("custom_command");
  4. mark_item_type = "minecraft:golden_shovel";
  5. air_item_type = "minecraft:air";
  6. msg("dev", "§bCopyisland §rwurde geladen");
  7. @wait
  8. wait();
  9. ignoreGoto(event);
  10. goto("wait");
  11. @block_break
  12. player_id = player.getId(player);
  13. if(item.getType(entity.getEquip(player, "hand")) == mark_item_type) {
  14. if(perm.has(player, "copyisland")) {
  15. if(!isTheCloningPlayer(player_id)) {
  16. goto("wait");
  17. }
  18. cancel = true;
  19. }
  20. }
  21. goto("wait");
  22. @block_click
  23. player_id = player.getId(player);
  24. if(item.getType(entity.getEquip(player, "hand")) == mark_item_type) {
  25. if(perm.has(player, "copyisland")) {
  26. if(!isTheCloningPlayer(player_id)) {
  27. goto("wait");
  28. }
  29. if(action == "left") {
  30. setPos1(player_id, block_loc);
  31. } elseif(action == "right") {
  32. setPos2(player_id, block_loc);
  33. }
  34. }
  35. }
  36. goto("wait");
  37. @custom_command
  38. if(command == "copyisland" || command == "ci") {
  39. if(player == null) {
  40. goto("wait");
  41. }
  42. player_id = player.getId(player);
  43. if(!perm.has(player, "copyisland")) {
  44. goto("wait");
  45. }
  46. size = list.getSize(args);
  47. if(size == 0) {
  48. player.speak(player, "§3CopyIsland", "/copyisland");
  49. msg(player, "§3 - copy §rSpeichert die Player-Location relativ zur Auswahl");
  50. msg(player, "§3 - paste §rKopiert relativ zur Location, an der 'copy' ausgeführt wurde");
  51. msg(player, "§3 - pos1 §rSetzt Pos1 auf deine aktuelle Position");
  52. msg(player, "§3 - pos2 §rSetzt Pos2 auf deine aktuelle Position");
  53. goto("wait");
  54. }
  55. arg0 = list.getIndex(args, 0);
  56. if(!isTheCloningPlayer(player_id)) {
  57. player.speak(player, "§3CopyIsland", "Copyisland wird von ", player.getNameFromId(cloningplayer), " verwendet");
  58. goto("wait");
  59. }
  60. if(arg0 == "pos1") {
  61. location = entity.getLocation(player);
  62. setPos1(player_id, location);
  63. goto("wait");
  64. }
  65. if(arg0 == "pos2") {
  66. location = entity.getLocation(player);
  67. setPos2(player_id, location);
  68. goto("wait");
  69. }
  70. if(arg0 == "air") {
  71. if(world1 == null || world2 == null) {
  72. player.speak(player, "§3CopyIsland", "Auswahl inkorrekt");
  73. goto("wait");
  74. }
  75. if(x1 > x2) {
  76. helper = x2;
  77. x2 = x1;
  78. x1 = helper;
  79. }
  80. if(y1 > y2) {
  81. helper = y2;
  82. y2 = y1;
  83. y1 = helper;
  84. }
  85. if(z1 > z2) {
  86. helper = z2;
  87. z2 = z1;
  88. z1 = helper;
  89. }
  90. loc = loc.new(world1, x1, y1, z1); //Start-Location
  91. x_length = x2 - x1 + 1; //Kantenlänge x-Achse
  92. y_length = y2 - y1 + 1; //Kantenlänge y-Achse
  93. z_length = z2 - z1 + 1; //Kantenlänge z-Achse
  94. //Zeitberechnung
  95. volume = x_length * y_length * z_length; //Volumen des ausgewählten Bereichs (oder Anzahl der Blöcke)
  96. calc_time = math.round((volume / 30000) * 1.633);
  97. player.speak(player, "§3CopyIsland", "§r", text.number(volume), " §eBlöcke werden gesetzt");
  98. player.speak(player, "§3CopyIsland", "§3Geschätzte Dauer: §r", text.number(calc_time), "§e Sekunden");
  99. start_time = time.getMillis();
  100. x1 = math.roundDown(x1 / 16) * 16;
  101. z1 = math.roundDown(z1 / 16) * 16;
  102. x2 = math.roundDown(x2 / 16) * 16;
  103. z2 = math.roundDown(z2 / 16) * 16;
  104. counter = 0;
  105. for(cx = x1; cx <= x2; cx += 16)
  106. {
  107. for(cz = z1; cz <= z2; cz += 16)
  108. {
  109. for(y = y2; y >= y1; y--)
  110. {
  111. loc.setY(loc, y);
  112. for(x = 0; x < 16; x++)
  113. {
  114. loc.setX(loc, x + cx);
  115. for(z = 0; z < 16; z++)
  116. {
  117. loc.setZ(loc, z + cz);
  118. block.set(loc, "minecraft:air");
  119. counter++;
  120. }
  121. }
  122. }
  123. }
  124. }
  125. player.speak(player, "§3CopyIsland", "§3Done: §r", text.number(counter), "§e blocks affected");
  126. end_time = time.getMillis();
  127. player.speak(player, "§3CopyIsland", "§3Benötigte Zeit: §r", text.number(math.round(((end_time - start_time) / 1000))), "§e Sekunden");
  128. cloningplayer = null;
  129. x1 = null;
  130. y1 = null;
  131. z1 = null;
  132. x2 = null;
  133. y2 = null;
  134. z2 = null;
  135. world1 = null;
  136. world2 = null;
  137. goto("wait");
  138. }
  139. if(arg0 == "copy") {
  140. if(world1 == null || world2 == null) {
  141. player.speak(player, "§3CopyIsland", "Auswahl inkorrekt");
  142. goto("wait");
  143. }
  144. from_loc = entity.getLocation(player);
  145. player.speak(player, "§3CopyIsland", "§rBereit zum Kopieren");
  146. goto("wait");
  147. }
  148. if(arg0 == "paste") {
  149. if(world1 == null || world2 == null) {
  150. player.speak(player, "§3CopyIsland", "Auswahl inkorrekt");
  151. goto("wait");
  152. }
  153. if(from_loc == null) {
  154. player.speak(player, "§3CopyIsland", "Zuerst die Location relativ zur Auswahl setzen /ci copy");
  155. goto("wait");
  156. }
  157. if(x1 > x2) {
  158. helper = x2;
  159. x2 = x1;
  160. x1 = helper;
  161. }
  162. if(y1 > y2) {
  163. helper = y2;
  164. y2 = y1;
  165. y1 = helper;
  166. }
  167. if(z1 > z2) {
  168. helper = z2;
  169. z2 = z1;
  170. z1 = helper;
  171. }
  172. copy_from = loc.new(world1, x1, y1, z1); //Von hier wird der 1.Block kopiert
  173. x_length = x2 - x1 + 1; //Kantenlänge x-Achse
  174. y_length = y2 - y1 + 1; //Kantenlänge y-Achse
  175. z_length = z2 - z1 + 1; //Kantenlänge z-Achse
  176. //Zeitberechnung
  177. volume = x_length * y_length * z_length; //Volumen des ausgewählten Bereichs (oder Anzahl der Blöcke)
  178. calc_time = math.round((volume / 30000) * 1.633);
  179. player.speak(player, "§3CopyIsland", "§r", text.number(volume), " §eBlöcke werden kopiert");
  180. player.speak(player, "§3CopyIsland", "§3Geschätzte Dauer: §r", text.number(calc_time), "§e Sekunden");
  181. start_time = time.getMillis();
  182. //Distanzen zwischen Spieler-Loc von /copy und 1.Block der kopiert wird
  183. x_distance1 = x1 - loc.getCoord(from_loc, "bx");
  184. y_distance1 = y1 - loc.getCoord(from_loc, "by");
  185. z_distance1 = z1 - loc.getCoord(from_loc, "bz");
  186. //Berechnung wohin der 1.Block gesetzt wird (Spieler-Loc von /paste + Distanzen s.o.)
  187. player_loc = entity.getLocation(player); //Paste-Location des Spielers
  188. world_copy_to = loc.getWorld(player_loc);
  189. x_copy_to = x_distance1 + loc.getCoord(player_loc, "bx");
  190. y_copy_to = y_distance1 + loc.getCoord(player_loc, "by");
  191. z_copy_to = z_distance1 + loc.getCoord(player_loc, "bz");
  192. copy_to = loc.new(world_copy_to, x_copy_to, y_copy_to, z_copy_to); //Hier wird der 1.Block gesetzt
  193. counter = 0;
  194. for(x = 0; x < x_length; x++) {
  195. for(y = 0; y < y_length; y++) {
  196. for(z = 0; z < z_length; z++) {
  197. relloc1 = loc.mod(copy_from, x, y, z);
  198. relloc2 = loc.mod(copy_to, x, y, z);
  199. block.clone(relloc1, relloc2);
  200. counter++;
  201. }
  202. }
  203. }
  204. player.speak(player, "§3CopyIsland", "§3Done: §r", text.number(counter), "§e blocks affected");
  205. end_time = time.getMillis();
  206. player.speak(player, "§3CopyIsland", "§3Benötigte Zeit: §r", text.number(math.round(((end_time - start_time) / 1000))), "§e Sekunden");
  207. cloningplayer = null;
  208. x1 = null;
  209. y1 = null;
  210. z1 = null;
  211. x2 = null;
  212. y2 = null;
  213. z2 = null;
  214. world1 = null;
  215. world2 = null;
  216. from_loc = null;
  217. goto("wait");
  218. }
  219. }
  220. goto("wait");
  221. function setPos1(player_id, location) {
  222. $x1 = loc.getCoord(location, "bx");
  223. $y1 = loc.getCoord(location, "by");
  224. $z1 = loc.getCoord(location, "bz");
  225. $world1 = loc.getWorld(location);
  226. player.speak($player, "§3CopyIsland", concat("§3Pos1: ", text.number($x1), ", ", text.number($y1), ", ", text.number($z1)));
  227. return;
  228. }
  229. function setPos2(player_id, location) {
  230. $x2 = loc.getCoord(location, "bx");
  231. $y2 = loc.getCoord(location, "by");
  232. $z2 = loc.getCoord(location, "bz");
  233. $world2 = loc.getWorld(location);
  234. player.speak($player, "§3CopyIsland", concat("§3Pos2: ", text.number($x2), ", ", text.number($y2), ", ", text.number($z2)));
  235. return;
  236. }
  237. function isTheCloningPlayer(player_id) {
  238. if($cloningplayer == null) {
  239. $cloningplayer = player_id;
  240. return true;
  241. } elseif(player_id == $cloningplayer) {
  242. return true;
  243. }
  244. return false;
  245. }