Example #1
0
  public double getDistance2(Player player1, Player player2) {
    Location loc1 = player1.getLocation();
    Location loc2 = player1.getLocation();

    return Math.sqrt(
        Math.pow(loc1.getX() - loc2.getX(), 2.0D)
            + Math.pow(loc1.getY() - loc2.getY(), 2.0D)
            + Math.pow(loc1.getZ() - loc2.getZ(), 2.0D));
  }
  @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;
  }
Example #4
0
 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);
 }
Example #5
0
 public ItemStack setEnchantments(ItemStack item, String enchants) {
   ItemStack i = item.clone();
   if (enchants.isEmpty()) return i;
   String[] ln = enchants.split(",");
   for (String ec : ln) {
     if (ec.isEmpty()) continue;
     Color clr = colorByName(ec);
     if (clr != null) {
       if (isIdInList(item.getTypeId(), "298,299,300,301")) {
         LeatherArmorMeta meta = (LeatherArmorMeta) i.getItemMeta();
         meta.setColor(clr);
         i.setItemMeta(meta);
       }
     } else {
       String ench = ec;
       int level = 1;
       if (ec.contains(":")) {
         ench = ec.substring(0, ec.indexOf(":"));
         level = Math.max(1, getMinMaxRandom(ec.substring(ench.length() + 1)));
       }
       Enchantment e = Enchantment.getByName(ench.toUpperCase());
       if (e == null) continue;
       i.addUnsafeEnchantment(e, level);
     }
   }
   return i;
 }
Example #6
0
 @Override
 public int getNoDamageTicks() {
   if (getHandle().field_71145_cl > 0) {
     return Math.max(getHandle().field_71145_cl, getHandle().field_70172_ad);
   } else {
     return getHandle().field_70172_ad;
   }
 }
Example #7
0
  private double calculateEnchantedDamage(double basicDamage, GlowLivingEntity entity) {
    int level = 0; // TODO: calculate explosion protection level of entity's equipment

    if (level > 0) {
      float sub = level * 0.15f;
      double damage = basicDamage * sub;
      damage = Math.floor(damage);
      return basicDamage - damage;
    }

    return basicDamage;
  }
Example #8
0
 @Override
 public List<Player> matchPlayer(String string) {
   List<Player> matches = new ArrayList<Player>();
   for (Player player : players) {
     if (player
         .getName()
         .substring(0, Math.min(player.getName().length(), string.length()))
         .equalsIgnoreCase(string)) {
       matches.add(player);
     }
   }
   return matches;
 }
Example #9
0
  private boolean isProtected(Location location) {
    Chunk chunk = location.getChunk();
    World world = location.getWorld();

    WorldConfig worldConfig = plugin.getConfig(world);

    int gridX = (int) (Math.floor(chunk.getX() / 10.0d) * 10);
    int gridZ = (int) (Math.floor(chunk.getZ() / 10.0d) * 10);

    DungeonProperties properties = new DungeonProperties(world, worldConfig, gridX, gridZ);

    if (properties.isInChunk(chunk)) {
      int yMin = 0;
      int yMax = 0;

      for (int y = 0; y < world.getMaxHeight(); ++y) {
        if ((chunk.getBlock(8, y, 8).getData() & (byte) 0x8) == 0x8) {
          yMin = y;
          break;
        }
      }

      for (int y = world.getMaxHeight(); y > 0; --y) {
        if ((chunk.getBlock(8, y, 8).getData() & (byte) 0x8) == 0x8) {
          yMax = y;
          break;
        }
      }

      double y = location.getY();

      return (y >= yMin && y <= yMax);
    }

    return false;
  }
Example #10
0
  public ItemStack parseItemStack(String itemstr) {
    if (itemstr.isEmpty()) return null;

    String istr = itemstr;
    String enchant = "";
    String name = "";

    if (istr.contains("$")) {
      name = istr.substring(0, istr.indexOf("$"));
      istr = istr.substring(name.length() + 1);
    }
    if (istr.contains("@")) {
      enchant = istr.substring(istr.indexOf("@") + 1);
      istr = istr.substring(0, istr.indexOf("@"));
    }
    int id = -1;
    int amount = 1;
    short data = 0;
    String[] si = istr.split("\\*");

    if (si.length > 0) {
      if (si.length == 2) amount = Math.max(getMinMaxRandom(si[1]), 1);
      String ti[] = si[0].split(":");
      if (ti.length > 0) {
        if (ti[0].matches("[0-9]*")) id = Integer.parseInt(ti[0]);
        else {
          Material m = Material.getMaterial(ti[0].toUpperCase());
          if (m == null) {
            logOnce("wrongitem" + ti[0], "Could not parse item material name (id) " + ti[0]);
            return null;
          }
          id = m.getId();
        }
        if ((ti.length == 2) && (ti[1]).matches("[0-9]*")) data = Short.parseShort(ti[1]);
        ItemStack item = new ItemStack(id, amount, data);
        if (!enchant.isEmpty()) {
          item = setEnchantments(item, enchant);
        }
        if (!name.isEmpty()) {
          ItemMeta im = item.getItemMeta();
          im.setDisplayName(ChatColor.translateAlternateColorCodes('&', name.replace("_", " ")));
          item.setItemMeta(im);
        }
        return item;
      }
    }
    return null;
  }
Example #11
0
 public static void addSeconds(final Player player, final int seconds) {
   if (!b******g.fdsjfhkdsjfdsjhk().getServerHandler().isEOTW()
       && DTRBitmaskType.SAFE_ZONE.appliesAt(player.getLocation())) {
     return;
   }
   if (isTagged(player)) {
     final int secondsTaggedFor =
         (int)
             ((SpawnTagHandler.spawnTags.get(player.getName()) - System.currentTimeMillis())
                 / 1000L);
     final int newSeconds = Math.min(secondsTaggedFor + seconds, 60);
     SpawnTagHandler.spawnTags.put(
         player.getName(), System.currentTimeMillis() + newSeconds * 1000L);
   } else {
     player.sendMessage(
         ChatColor.YELLOW + "You have been spawn-tagged for §c" + seconds + " §eseconds!");
     SpawnTagHandler.spawnTags.put(player.getName(), System.currentTimeMillis() + seconds * 1000L);
   }
 }
Example #12
0
 public List<Block> getBlocks() {
   List<Block> blocks = new ArrayList<Block>();
   if (loc1 == null || loc2 == null) return blocks;
   for (int x = (int) Math.min(loc1.getX(), loc2.getX());
       x <= (int) Math.max(loc1.getX(), loc2.getX());
       x++) {
     for (int y = (int) Math.min(loc1.getY(), loc2.getY());
         y <= (int) Math.max(loc1.getY(), loc2.getY());
         y++) {
       for (int z = (int) Math.min(loc1.getZ(), loc2.getZ());
           z <= (int) Math.max(loc1.getZ(), loc2.getZ());
           z++) {
         if (loc1.getWorld().getBlockAt(x, y, z).getType() == Material.AIR) {
           blocks.add(loc1.getWorld().getBlockAt(x, y, z));
         }
       }
     }
   }
   return blocks;
 }
Example #13
0
 @Override
 public void setMaxHealth(double amount) {
   super.setMaxHealth(amount);
   this.health = Math.min(this.health, health);
   getHandle().func_71118_n();
 }
Example #14
0
 public Long timeToTicks(Long time) {
   // 1000 ms = 20 ticks
   return Math.max(1, (time / 50));
 }
Example #15
0
  @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);
    }
  }
Example #16
0
  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) + "");
  }