@SuppressWarnings("deprecation") public static List<Block> getBorderBlocks(NovaRegion region) { List<Block> blocks = new ArrayList<>(); Location l1 = region.getCorner(0); Location l2 = region.getCorner(1); World world = region.getWorld(); int x; int z; int xs; int zs; int x1 = l1.getBlockX(); int x2 = l2.getBlockX(); int z1 = l1.getBlockZ(); int z2 = l2.getBlockZ(); int t; int dif_x = Math.abs(x1 - x2) + 1; int dif_z = Math.abs(z1 - z2) + 1; if (l1.getBlockX() < l2.getBlockX()) { xs = l1.getBlockX(); } else { xs = l2.getBlockX(); } if (l1.getBlockZ() < l2.getBlockZ()) { zs = l1.getBlockZ(); } else { zs = l2.getBlockZ(); } for (t = 0; t < dif_x; t++) { x = xs + t; int highest1 = world.getHighestBlockYAt(x, z1) - 1; int highest2 = world.getHighestBlockYAt(x, z2) - 1; blocks.add(world.getBlockAt(x, highest1, z1)); blocks.add(world.getBlockAt(x, highest2, z2)); } for (t = 0; t < dif_z; t++) { z = zs + t; int highest1 = world.getHighestBlockYAt(x1, z) - 1; int highest2 = world.getHighestBlockYAt(x2, z) - 1; blocks.add(world.getBlockAt(x1, highest1, z)); blocks.add(world.getBlockAt(x2, highest2, z)); } return blocks; }
public static int distanceBetweenRegionsSide(NovaRegion region1, Location l1, Location l2) { int distance; int[] x1 = new int[2]; int[] x2 = new int[2]; int[] z1 = new int[2]; int[] z2 = new int[2]; Location[] c1 = new Location[2]; Location[] c2 = new Location[2]; c1[0] = region1.getCorner(0); c1[1] = region1.getCorner(1); // c2[0] = region2.getCorner(0); // c2[1] = region2.getCorner(1); c2[0] = l1; c2[1] = l2; x1[0] = c1[0].getBlockX(); x1[1] = c1[1].getBlockX(); x2[0] = c2[0].getBlockX(); x2[1] = c2[1].getBlockX(); z1[0] = c1[0].getBlockZ(); z1[1] = c1[1].getBlockZ(); z2[0] = c2[0].getBlockZ(); z2[1] = c2[1].getBlockZ(); boolean x_inside = x1[0] < x2[0] && x2[1] < x1[1]; if (x_inside) { int dif = Math.abs(x1[0] - x2[0]); Bukkit.getLogger().info("dif=" + dif); distance = dif; dif = Math.abs(x1[1] - x2[1]); Bukkit.getLogger().info("dif=" + dif); if (distance > dif || distance == -1) distance = dif; } else { int dif = Math.abs(z1[0] - z2[0]); Bukkit.getLogger().info("dif=" + dif); distance = dif; dif = Math.abs(z1[1] - z2[1]); Bukkit.getLogger().info("dif=" + dif); if (distance > dif || distance == -1) distance = dif; } return distance; }
public void lookAtPoint(final Location point) { if (this.getEntity().getBukkitEntity().getWorld() != point.getWorld()) return; final Location npcLoc = ((LivingEntity) this.getEntity().getBukkitEntity()).getEyeLocation(); final double xDiff = point.getX() - npcLoc.getX(); final double yDiff = point.getY() - npcLoc.getY(); final double zDiff = point.getZ() - npcLoc.getZ(); final double DistanceXZ = Math.sqrt(xDiff * xDiff + zDiff * zDiff); final double DistanceY = Math.sqrt(DistanceXZ * DistanceXZ + yDiff * yDiff); double newYaw = Math.acos(xDiff / DistanceXZ) * 180 / Math.PI; final double newPitch = Math.acos(yDiff / DistanceY) * 180 / Math.PI - 90; if (zDiff < 0.0) newYaw = newYaw + Math.abs(180 - newYaw) * 2; this.setYaw((float) (newYaw - 90)); this.setPitch((float) newPitch); }
@SuppressWarnings("deprecation") public static void sendSquare( Player player, Location l1, Location l2, Material material, byte data) { if (player == null || l1 == null || l2 == null) { return; } Material material1 = null; Material material2 = null; Byte data1 = null; Byte data2 = null; if (material != null) { material1 = material2 = material; data1 = data2 = data; } int x; int z; int xs; int zs; int x1 = l1.getBlockX(); int x2 = l2.getBlockX(); int z1 = l1.getBlockZ(); int z2 = l2.getBlockZ(); int t; int dif_x = Math.abs(x1 - x2) + 1; int dif_z = Math.abs(z1 - z2) + 1; if (l1.getBlockX() < l2.getBlockX()) { xs = l1.getBlockX(); } else { xs = l2.getBlockX(); } if (l1.getBlockZ() < l2.getBlockZ()) { zs = l1.getBlockZ(); } else { zs = l2.getBlockZ(); } for (t = 0; t < dif_x; t++) { x = xs + t; int highest1 = player.getWorld().getHighestBlockYAt(x, z1) - 1; int highest2 = player.getWorld().getHighestBlockYAt(x, z2) - 1; Location loc1 = player.getWorld().getBlockAt(x, highest1, z1).getLocation(); Location loc2 = player.getWorld().getBlockAt(x, highest2, z2).getLocation(); if (material == null) { material1 = player.getWorld().getBlockAt(loc1).getType(); material2 = player.getWorld().getBlockAt(loc2).getType(); data1 = player.getWorld().getBlockAt(loc1).getData(); data2 = player.getWorld().getBlockAt(loc2).getData(); } player.sendBlockChange(loc1, material1, data1); player.sendBlockChange(loc2, material2, data2); } for (t = 0; t < dif_z; t++) { z = zs + t; int highest1 = player.getWorld().getHighestBlockYAt(x1, z) - 1; int highest2 = player.getWorld().getHighestBlockYAt(x2, z) - 1; Location loc1 = player.getWorld().getBlockAt(x1, highest1, z).getLocation(); Location loc2 = player.getWorld().getBlockAt(x2, highest2, z).getLocation(); if (material == null) { material1 = player.getWorld().getBlockAt(loc1).getType(); material2 = player.getWorld().getBlockAt(loc2).getType(); data1 = player.getWorld().getBlockAt(loc1).getData(); data2 = player.getWorld().getBlockAt(loc2).getData(); } player.sendBlockChange(loc1, material1, data1); player.sendBlockChange(loc2, material2, data2); } }
public static int distanceBetweenRegions2(NovaRegion region1, Location l1, Location l2) { float millis = System.nanoTime(); double distance = -1; int[] x1 = new int[2]; int[] x2 = new int[2]; int[] z1 = new int[2]; int[] z2 = new int[2]; Location[] c1 = new Location[2]; Location[] c2 = new Location[2]; c1[0] = region1.getCorner(0); c1[1] = region1.getCorner(1); // c2[0] = region2.getCorner(0); // c2[1] = region2.getCorner(1); c2[0] = l1; c2[1] = l2; x1[0] = c1[0].getBlockX(); x1[1] = c1[1].getBlockX(); x2[0] = c2[0].getBlockX(); x2[1] = c2[1].getBlockX(); z1[0] = c1[0].getBlockZ(); z1[1] = c1[1].getBlockZ(); z2[0] = c2[0].getBlockZ(); z2[1] = c2[1].getBlockZ(); boolean x_out_left = x2[0] < x1[0] && x2[1] < x1[0]; boolean x_out_right = x1[1] < x2[0] && x1[1] < x2[1]; boolean x_out = x_out_left || x_out_right; Bukkit.getLogger().info("-----"); Bukkit.getLogger().info("x_out=" + x_out); boolean z_out_left = z2[0] < z1[0] && z2[1] < z1[0]; boolean z_out_right = z1[1] < z2[0] && z1[1] < z2[1]; boolean z_out = z_out_left || z_out_right; Bukkit.getLogger().info("z_out=" + z_out); boolean out = x_out && z_out; Bukkit.getLogger().info("out=" + out); Bukkit.getLogger().info("x1|0=" + x1[0]); Bukkit.getLogger().info("x1|1=" + x1[1]); Bukkit.getLogger().info("z1|0=" + z1[0]); Bukkit.getLogger().info("z1|1=" + z1[1]); Bukkit.getLogger().info("x2|0=" + x2[0]); Bukkit.getLogger().info("x2|1=" + x2[1]); Bukkit.getLogger().info("z2|0=" + z2[0]); Bukkit.getLogger().info("z2|1=" + z2[1]); World world = region1.getWorld(); List<Location> corners1 = new ArrayList<>(); List<Location> corners2 = new ArrayList<>(); corners1.add(new Location(world, x1[0], 0, x1[0])); corners1.add(new Location(world, x1[0], 0, x1[1])); corners1.add(new Location(world, x1[1], 0, x1[1])); corners1.add(new Location(world, x1[1], 0, x1[0])); corners2.add(new Location(world, x2[0], 0, x2[0])); corners2.add(new Location(world, x2[0], 0, x2[1])); corners2.add(new Location(world, x2[1], 0, x2[1])); corners2.add(new Location(world, x2[1], 0, x2[0])); // corners distances if (out) { Bukkit.getLogger().info("rectangle1 corners=" + corners1.size()); Bukkit.getLogger().info("rectangle2 corners=" + corners2.size()); for (Location corner1 : corners1) { // setCorner(region1.getGuild().getPlayers().get(0).getPlayer(),corner1,Material.BRICK); for (Location corner2 : corners2) { // Bukkit.getLogger().info("2("+cx2+","+cz2+")"); // setCorner(region1.getGuild().getPlayers().get(0).getPlayer(),corner2,Material.BRICK); double cacheDistance = corner2.distance(corner1); if (distance > cacheDistance || distance == -1) { Bukkit.getLogger().info("Changed distance. " + distance + " -> " + cacheDistance); distance = cacheDistance; } } } } else { Bukkit.getLogger().info("side by side!"); boolean x_inside = x1[0] < x2[0] && x2[1] < x1[1]; if (x_inside) { Bukkit.getLogger().info("x_inside"); int dif = Math.abs(x1[0] - x2[0]); Bukkit.getLogger().info("dif=" + dif); distance = dif; dif = Math.abs(x1[1] - x2[1]); Bukkit.getLogger().info("dif=" + dif); if (distance > dif || distance == -1) distance = dif; } else { Bukkit.getLogger().info("z_inside"); int dif = Math.abs(z1[0] - z2[0]); Bukkit.getLogger().info("dif=" + dif); distance = dif; dif = Math.abs(z1[1] - z2[1]); Bukkit.getLogger().info("dif=" + dif); if (distance > dif || distance == -1) distance = dif; } } Bukkit.getLogger().info("distance=" + Math.round(distance)); Bukkit.getLogger().info("Time: " + ((System.nanoTime() - millis)) + "ns"); return Integer.parseInt(Math.round(distance) + ""); }