hawkeye_old.txt 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. /hawkeye search <parameters>
  3. Parameters Examples:
  4. p:marvinius,MentorMentos
  5. t:30d,4h,20m
  6. r:10
  7. e:block_break,block_place
  8. */
  9. event.load("block_break");
  10. event.load("block_place");
  11. event.load("block_click");
  12. prefix_hawkeye = "§cHawkeye";
  13. chests_tag = block.getTag("forge:chests/wooden");
  14. wall_signs_tag = block.getTag("minecraft:wall_signs");
  15. standing_signs_tag = block.getTag("minecraft:standing_signs");
  16. stairs_tag = block.getTag("minecraft:stairs");
  17. slabs_tag = block.getTag("minecraft:slabs");
  18. buttons_tag = block.getTag("minecraft:buttons");
  19. face_prop = block.getProperty("face");
  20. facing_prop = block.getProperty("facing");
  21. facing_except_up_prop = block.getProperty("facing_except_up");
  22. horizontal_facing_prop = block.getProperty("horizontal_facing");
  23. half_prop = block.getProperty("half");
  24. stair_shape_prop = block.getProperty("stair_shape");
  25. slab_type_prop = block.getProperty("slab_type");
  26. rotation_prop = block.getProperty("rotation");
  27. chest_type_prop = block.getProperty("chest_type");
  28. extended_prop = block.getProperty("extended");
  29. databank.workerExecute(databank.prepare("CREATE TABLE IF NOT EXISTS hawkeye(id INT NOT NULL PRIMARY KEY, player_id INT NOT NULL, event VARCHAR(25) NOT NULL, world VARCHAR(15) NOT NULL, x INT NOT NULL, y INT NOT NULL, z INT NOT NULL, time BIGINT NOT NULL);"));
  30. databank.workerExecute(databank.prepare("CREATE TABLE IF NOT EXISTS hawkeye_data(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, hawkeye_id INT NOT NULL, name VARCHAR(20) NOT NULL, value VARCHAR(100) NOT NULL, FOREIGN KEY (hawkeye_id) REFERENCES hawkeye(id) ON DELETE RESTRICT);"));
  31. hawkeye.deleteOlderThanThreeWeeks();
  32. msg("dev", "§bHawkeye §rloaded.");
  33. @wait
  34. wait();
  35. if(event == "block_place") {
  36. item = living.getEquip(player, "hand");
  37. if(hawkeye.isTool(item)) {
  38. if(!perm.has(player, "hawkeye")) {
  39. perm.no(player, "hawkeye");
  40. goto("wait");
  41. }
  42. cancel = true;
  43. list = hawkeye.getData(null, null, block_loc, 1, null, null, "DESC");
  44. if(list.getSize(list) == 0) {
  45. msg.prefix(player, prefix_hawkeye, "No results found.");
  46. goto("wait");
  47. }
  48. hawkeye.setDataList(player, list);
  49. hawkeye.print(player, list, 1);
  50. goto("wait");
  51. }
  52. }
  53. if(event == "block_click") {
  54. item = living.getEquip(player, "hand");
  55. if(action == "left" && hawkeye.isTool(item)) {
  56. if(!perm.has(player, "hawkeye")) {
  57. perm.no(player, "hawkeye");
  58. goto("wait");
  59. }
  60. cancel = true;
  61. list = hawkeye.getData(null, null, block_loc, 1, null, null, "DESC");
  62. if(list.getSize(list) == 0) {
  63. msg.prefix(player, prefix_hawkeye, "No results found.");
  64. goto("wait");
  65. }
  66. hawkeye.setDataList(player, list);
  67. hawkeye.print(player, list, 1);
  68. }
  69. goto("wait");
  70. }
  71. world_name = world.getName(loc.getWorld(block_loc));
  72. if(world.isSurvName(world_name)) {
  73. if(event == "block_break" || event == "block_place") {
  74. if(!cancel) {
  75. id = hawkeye.getNextId();
  76. hawkeye.addBlockEvent(id, event, player, block_loc);
  77. hawkeye.addBlockDetail(id, "block_type", block_type);
  78. if(block_type == "minecraft:piston" || block_type == "minecraft:sticky_piston") {
  79. hawkeye.addBlockState(id, block_loc, "facing", facing_prop);
  80. hawkeye.addBlockState(id, block_loc, "extended", extended_prop);
  81. }
  82. elseif(block.hasTag(chests_tag, block)) {
  83. hawkeye.addBlockState(id, block_loc, "facing", horizontal_facing_prop);
  84. hawkeye.addBlockState(id, block_loc, "chest", chest_type_prop);
  85. }
  86. elseif(block.hasTag(standing_signs_tag, block)) {
  87. hawkeye.addBlockState(id, block_loc, "rotation", rotation_prop);
  88. }
  89. elseif(block.hasTag(buttons_tag, block)) {
  90. hawkeye.addBlockState(id, block_loc, "facing", horizontal_facing_prop);
  91. hawkeye.addBlockState(id, block_loc, "face", face_prop);
  92. }
  93. elseif(block_type == "minecraft:hopper") {
  94. hawkeye.addBlockState(id, block_loc, "facing", facing_except_up_prop);
  95. }
  96. elseif(block.hasTag(wall_signs_tag, block)) {
  97. hawkeye.addBlockState(id, block_loc, "facing", horizontal_facing_prop);
  98. }
  99. elseif(block.hasTag(slabs_tag, block)) {
  100. hawkeye.addBlockState(id, block_loc, "type", slab_type_prop);
  101. }
  102. elseif(block.hasTag(stairs_tag, block)) {
  103. hawkeye.addBlockState(id, block_loc, "facing", horizontal_facing_prop);
  104. hawkeye.addBlockState(id, block_loc, "half", half_prop);
  105. hawkeye.addBlockState(id, block_loc, "shape", stair_shape_prop);
  106. }
  107. }
  108. }
  109. }
  110. goto("wait");
  111. function hawkeye.addBlockState(id, block_loc, state_name, state_prop) {
  112. state = block.property.getValue(block_loc, state_prop);
  113. if(state != null) {
  114. hawkeye.addBlockDetail(id, state_name, state);
  115. }
  116. }
  117. function hawkeye.addBlockEvent(id, event, player, location) {
  118. stmt = databank.prepare("INSERT INTO hawkeye (id, player_id, event, world, x, y, z, time) VALUES (?,?,?,?,?,?,?,?)");
  119. modTimer(-5);
  120. databank.setInt(stmt, 1, id);
  121. databank.setInt(stmt, 2, player.getId(player));
  122. databank.setString(stmt, 3, event);
  123. databank.setString(stmt, 4, world.getName(loc.getWorld(location)));
  124. databank.setInt(stmt, 5, loc.getX(location));
  125. databank.setInt(stmt, 6, loc.getY(location));
  126. databank.setInt(stmt, 7, loc.getZ(location));
  127. databank.setLong(stmt, 8, time.getMillis());
  128. databank.workerExecute(stmt);
  129. }
  130. function hawkeye.addBlockDetail(hawkeye_id, name, value) {
  131. stmt = databank.prepare("INSERT INTO hawkeye_data (hawkeye_id, name, value) VALUES (?,?,?)");
  132. modTimer(-5);
  133. databank.setInt(stmt, 1, hawkeye_id);
  134. databank.setString(stmt, 2, name);
  135. databank.setString(stmt, 3, value);
  136. databank.workerExecute(stmt);
  137. }
  138. function hawkeye.getNextId() {
  139. id = 0;
  140. stmt = databank.prepare("SELECT MAX(id) FROM hawkeye;");
  141. result = databank.execute(stmt);
  142. if(databank.next(result)) {
  143. id = databank.getInt(result, 1);
  144. }
  145. databank.close(result);
  146. databank.close(stmt);
  147. return id + 1;
  148. }
  149. function hawkeye.deleteOlderThanThreeWeeks() {
  150. three_weeks_before = time.getMillis() - 21 * 24 * 60 * 60 * 1000;
  151. stmt = databank.prepare("DELETE FROM hawkeye_data WHERE hawkeye_id IN(SELECT id FROM hawkeye WHERE time < ?);");
  152. databank.setLong(stmt, 1, three_weeks_before);
  153. databank.workerExecute(stmt);
  154. stmt2 = databank.prepare("DELETE FROM hawkeye WHERE time < ?;");
  155. databank.setLong(stmt2, 1, three_weeks_before);
  156. databank.workerExecute(stmt2);
  157. }
  158. function hawkeye.isTool(item) {
  159. lore = item.getLore(item);
  160. if(list.getSize(lore) > 0) {
  161. return list.getIndex(lore, 0) == "Hawkeye Tool";
  162. }
  163. return false;
  164. }