copyisland.txt 7.3 KB

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