Ejemplo n.º 1
0
 private double getDistanceTo(double x, double y, double z, Player player) {
   double x2 = player.getX();
   double y2 = player.getY();
   double z2 = player.getZ();
   double xResult = java.lang.Math.pow(java.lang.Math.max(x, x2) - java.lang.Math.min(x, x2), 2);
   double yResult = java.lang.Math.pow(java.lang.Math.max(y, y2) - java.lang.Math.min(y, y2), 2);
   double zResult = java.lang.Math.pow(java.lang.Math.max(z, z2) - java.lang.Math.min(z, z2), 2);
   return java.lang.Math.sqrt(xResult + yResult + zResult);
 }
 private static int readInputStreamWithTimeout(InputStream is, byte[] b, int timeoutMillis)
     throws IOException {
   try {
     int bufferOffset = 0;
     long maxTimeMillis = System.currentTimeMillis() + timeoutMillis;
     while (System.currentTimeMillis() < maxTimeMillis && bufferOffset < b.length) {
       int readLength = java.lang.Math.min(is.available(), b.length - bufferOffset);
       int readResult = is.read(b, bufferOffset, readLength);
       if (readResult == -1) break;
       bufferOffset += readResult;
     }
     return bufferOffset;
   } catch (IOException ex) {
     Loggers.SERVER.error("Error reading stream. Stream closed: " + ex);
     return -1;
   }
 }