获取给定区域内的所有正方形

时间:2016-07-20 14:39:35

标签: java sqlite find area

enter image description here

图片说明: 我想在蓝色区域中获取所有灰色框,但不是

之外的灰色框

中心点位于x,z位置,蓝色边框距离中心点x半径

这是用于检查位置是否在声明内的sqlite查询

SELECT uuid,world,x1,z1,x2,z2 FROM `claims` WHERE %s = `world` AND x >= `x1` AND z >= `z1` AND x < `x2` AND z < `z2` LIMIT 1

这是我的查找方法:

public static List<Claim> find(Location loc, int radius) throws Exception {
    int x1 = loc.getBlockX() + radius, z1 = loc.getBlockZ() + radius;
    int x2 = loc.getBlockX() - radius, z2 = loc.getBlockZ() - radius;
    List<Row> rows = database.getRows(String.format("SELECT uuid,world,x1,z1,x2,z2 FROM `claims` WHERE %s = `world` AND /*TODO find solution*/", loc.getWorld().getName()));
    List<Claim> claims = new ArrayList<>();
    for (Row r : rows) {
        World w = Bukkit.getWorld(UUID.fromString("world"));
        claims.add(new Claim(UUID.fromString(r.getString("uuid")), new Location(w, r.getInt("x1"), 0, r.getInt("z1")), new Location(w, r.getInt("x2"), 0, r.getInt("z2"))));
    }
    return claims;
}

检查每个位置的索赔效率并不高,查看更大的半径甚至可能导致大量滞后

enter image description here

0 个答案:

没有答案