123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- /*
- /hawkeye search <parameters>
- Parameters Examples:
- p:marvinius,MentorMentos
- t:30d,4h,20m
- r:10
- e:block_break,block_place
- */
- event.load("block_break");
- event.load("block_place");
- event.load("block_click");
- prefix_hawkeye = "§cHawkeye";
- chests_tag = block.getTag("forge:chests/wooden");
- wall_signs_tag = block.getTag("minecraft:wall_signs");
- standing_signs_tag = block.getTag("minecraft:standing_signs");
- stairs_tag = block.getTag("minecraft:stairs");
- slabs_tag = block.getTag("minecraft:slabs");
- buttons_tag = block.getTag("minecraft:buttons");
- face_prop = block.getProperty("face");
- facing_prop = block.getProperty("facing");
- facing_except_up_prop = block.getProperty("facing_except_up");
- horizontal_facing_prop = block.getProperty("horizontal_facing");
- half_prop = block.getProperty("half");
- stair_shape_prop = block.getProperty("stair_shape");
- slab_type_prop = block.getProperty("slab_type");
- rotation_prop = block.getProperty("rotation");
- chest_type_prop = block.getProperty("chest_type");
- extended_prop = block.getProperty("extended");
- 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);"));
- 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);"));
- hawkeye.deleteOlderThanThreeWeeks();
- msg("dev", "§bHawkeye §rloaded.");
- @wait
- wait();
- if(event == "block_place") {
- item = living.getEquip(player, "hand");
- if(hawkeye.isTool(item)) {
- if(!perm.has(player, "hawkeye")) {
- perm.no(player, "hawkeye");
- goto("wait");
- }
- cancel = true;
- list = hawkeye.getData(null, null, block_loc, 1, null, null, "DESC");
- if(list.getSize(list) == 0) {
- msg.prefix(player, prefix_hawkeye, "No results found.");
- goto("wait");
- }
- hawkeye.setDataList(player, list);
- hawkeye.print(player, list, 1);
- goto("wait");
- }
- }
- if(event == "block_click") {
- item = living.getEquip(player, "hand");
- if(action == "left" && hawkeye.isTool(item)) {
- if(!perm.has(player, "hawkeye")) {
- perm.no(player, "hawkeye");
- goto("wait");
- }
- cancel = true;
- list = hawkeye.getData(null, null, block_loc, 1, null, null, "DESC");
- if(list.getSize(list) == 0) {
- msg.prefix(player, prefix_hawkeye, "No results found.");
- goto("wait");
- }
- hawkeye.setDataList(player, list);
- hawkeye.print(player, list, 1);
- }
- goto("wait");
- }
- world_name = world.getName(loc.getWorld(block_loc));
- if(world.isSurvName(world_name)) {
- if(event == "block_break" || event == "block_place") {
- if(!cancel) {
- id = hawkeye.getNextId();
- hawkeye.addBlockEvent(id, event, player, block_loc);
- hawkeye.addBlockDetail(id, "block_type", block_type);
- if(block_type == "minecraft:piston" || block_type == "minecraft:sticky_piston") {
- hawkeye.addBlockState(id, block_loc, "facing", facing_prop);
- hawkeye.addBlockState(id, block_loc, "extended", extended_prop);
- }
- elseif(block.hasTag(chests_tag, block)) {
- hawkeye.addBlockState(id, block_loc, "facing", horizontal_facing_prop);
- hawkeye.addBlockState(id, block_loc, "chest", chest_type_prop);
- }
- elseif(block.hasTag(standing_signs_tag, block)) {
- hawkeye.addBlockState(id, block_loc, "rotation", rotation_prop);
- }
- elseif(block.hasTag(buttons_tag, block)) {
- hawkeye.addBlockState(id, block_loc, "facing", horizontal_facing_prop);
- hawkeye.addBlockState(id, block_loc, "face", face_prop);
- }
- elseif(block_type == "minecraft:hopper") {
- hawkeye.addBlockState(id, block_loc, "facing", facing_except_up_prop);
- }
- elseif(block.hasTag(wall_signs_tag, block)) {
- hawkeye.addBlockState(id, block_loc, "facing", horizontal_facing_prop);
- }
- elseif(block.hasTag(slabs_tag, block)) {
- hawkeye.addBlockState(id, block_loc, "type", slab_type_prop);
- }
- elseif(block.hasTag(stairs_tag, block)) {
- hawkeye.addBlockState(id, block_loc, "facing", horizontal_facing_prop);
- hawkeye.addBlockState(id, block_loc, "half", half_prop);
- hawkeye.addBlockState(id, block_loc, "shape", stair_shape_prop);
- }
- }
- }
- }
- goto("wait");
- function hawkeye.addBlockState(id, block_loc, state_name, state_prop) {
- state = block.property.getValue(block_loc, state_prop);
- if(state != null) {
- hawkeye.addBlockDetail(id, state_name, state);
- }
- }
- function hawkeye.addBlockEvent(id, event, player, location) {
- stmt = databank.prepare("INSERT INTO hawkeye (id, player_id, event, world, x, y, z, time) VALUES (?,?,?,?,?,?,?,?)");
- modTimer(-5);
- databank.setInt(stmt, 1, id);
- databank.setInt(stmt, 2, player.getId(player));
- databank.setString(stmt, 3, event);
- databank.setString(stmt, 4, world.getName(loc.getWorld(location)));
- databank.setInt(stmt, 5, loc.getX(location));
- databank.setInt(stmt, 6, loc.getY(location));
- databank.setInt(stmt, 7, loc.getZ(location));
- databank.setLong(stmt, 8, time.getMillis());
- databank.workerExecute(stmt);
- }
- function hawkeye.addBlockDetail(hawkeye_id, name, value) {
- stmt = databank.prepare("INSERT INTO hawkeye_data (hawkeye_id, name, value) VALUES (?,?,?)");
- modTimer(-5);
- databank.setInt(stmt, 1, hawkeye_id);
- databank.setString(stmt, 2, name);
- databank.setString(stmt, 3, value);
- databank.workerExecute(stmt);
- }
- function hawkeye.getNextId() {
- id = 0;
- stmt = databank.prepare("SELECT MAX(id) FROM hawkeye;");
- result = databank.execute(stmt);
- if(databank.next(result)) {
- id = databank.getInt(result, 1);
- }
- databank.close(result);
- databank.close(stmt);
- return id + 1;
- }
- function hawkeye.deleteOlderThanThreeWeeks() {
- three_weeks_before = time.getMillis() - 21 * 24 * 60 * 60 * 1000;
- stmt = databank.prepare("DELETE FROM hawkeye_data WHERE hawkeye_id IN(SELECT id FROM hawkeye WHERE time < ?);");
- databank.setLong(stmt, 1, three_weeks_before);
- databank.workerExecute(stmt);
- stmt2 = databank.prepare("DELETE FROM hawkeye WHERE time < ?;");
- databank.setLong(stmt2, 1, three_weeks_before);
- databank.workerExecute(stmt2);
- }
- function hawkeye.isTool(item) {
- lore = item.getLore(item);
- if(list.getSize(lore) > 0) {
- return list.getIndex(lore, 0) == "Hawkeye Tool";
- }
- return false;
- }
|