public static void sendMavlinkMessage(MavLinkDrone drone, MavlinkMessageWrapper messageWrapper) {
    if (drone == null || messageWrapper == null) return;

    MAVLinkMessage message = messageWrapper.getMavLinkMessage();
    if (message == null) return;

    message.compid = drone.getCompid();
    message.sysid = drone.getSysid();

    // Set the target system and target component for MAVLink messages that support those
    // attributes.
    try {
      Class<?> tempMessage = message.getClass();
      Field target_system = tempMessage.getDeclaredField("target_system");
      Field target_component = tempMessage.getDeclaredField("target_component");

      target_system.setByte(message, (byte) message.sysid);
      target_component.setByte(message, (byte) message.compid);
    } catch (NoSuchFieldException
        | SecurityException
        | IllegalAccessException
        | IllegalArgumentException
        | ExceptionInInitializerError e) {
      Timber.e(e, e.getMessage());
    }

    drone.getMavClient().sendMavMessage(message, null);
  }
  private void bindActionHandlers(Object view, Object... viewModels)
      throws IllegalAccessException, UnsupportedOperationException {
    for (Field field : view.getClass().getDeclaredFields()) {
      BindAction bindActionAnnotation = field.getAnnotation(BindAction.class);
      if (bindActionAnnotation == null) {
        continue;
      }

      if (!Modifier.isPublic(field.getModifiers())) {
        field.setAccessible(true);
      }

      final Object fieldInstance = field.get(view);

      String[] sourceNames = bindActionAnnotation.source();
      Object[] sources = new Object[sourceNames.length];

      try {
        for (int i = 0; i < bindActionAnnotation.source().length; i++) {
          Field sourceField = view.getClass().getDeclaredField(sourceNames[i]);
          sourceField.setAccessible(true);
          sources[i] = sourceField.get(view);
        }
      } catch (NoSuchFieldException | SecurityException e) {
        throw new UnsupportedOperationException(e.getMessage());
      }

      bindActionHandler(fieldInstance, bindActionAnnotation.value(), sources, viewModels);
    }
  }
Beispiel #3
0
  @SuppressWarnings("unchecked")
  public static EntityTrackerEntry registerEntityTracker(
      Entity entity, int trackingRange, int updateFrequency, boolean sendVelocityUpdates) {
    WorldServer worldServer = getWorld(entity);
    CustomEntityTrackerEntry tracker =
        new CustomEntityTrackerEntry(entity, trackingRange, updateFrequency, sendVelocityUpdates);

    try {
      Field field = worldServer.tracker.getClass().getDeclaredField("c");
      if (!field.isAccessible()) {
        field.setAccessible(true);
      }

      Set<EntityTrackerEntry> list = (Set<EntityTrackerEntry>) field.get(worldServer.tracker);

      if (worldServer.tracker.trackedEntities.b(entity.getId())) { // if contains entity tracker
        // go to delete
        EntityTrackerEntry oldTracker = worldServer.tracker.trackedEntities.d(entity.getId());
        list.remove(oldTracker);
        oldTracker.a();
      }

      list.add(tracker);
      worldServer.tracker.trackedEntities.a(entity.getId(), tracker);
      tracker.scanPlayers(worldServer.players);
    } catch (NoSuchFieldException
        | SecurityException
        | IllegalArgumentException
        | IllegalAccessException e) {
      e.printStackTrace();
    }
    return tracker;
  }
Beispiel #4
0
  private void readObject(java.io.ObjectInputStream in) throws IOException {
    float x = in.readFloat();
    float y = in.readFloat();
    float z = in.readFloat();
    String world = in.readUTF();
    World w = Spout.getEngine().getWorld(world, true);
    try {
      Field field;

      field = Vector3f.class.getDeclaredField("x");
      field.setAccessible(true);
      field.set(this, x);

      field = Vector3f.class.getDeclaredField("y");
      field.setAccessible(true);
      field.set(this, y);

      field = Vector3f.class.getDeclaredField("z");
      field.setAccessible(true);
      field.set(this, z);

      field = Point.class.getDeclaredField("world");
      field.setAccessible(true);
      field.set(this, w);
    } catch (NoSuchFieldException
        | SecurityException
        | IllegalArgumentException
        | IllegalAccessException e) {
      if (Spout.debugMode()) {
        e.printStackTrace();
      }
    }
  }
Beispiel #5
0
 private Object obtemValor(Object o, String field) {
   for (String s : field.split("\\.")) {
     try {
       Field f = o.getClass().getDeclaredField(s);
       f.setAccessible(true);
       o = f.get(o);
     } catch (NoSuchFieldException
         | SecurityException
         | IllegalArgumentException
         | IllegalAccessException e1) {
       // TODO Auto-generated catch block
       e1.printStackTrace();
     }
   }
   return o;
 }
 @Around("execution(public java.lang.String *.getCounter(..))")
 public Object logBefore(ProceedingJoinPoint joinPoint) throws Throwable {
   String msg = "(null) -> ";
   Object target = joinPoint.getTarget();
   try {
     Field counterField = target.getClass().getDeclaredField("counter");
     int counter = (int) counterField.get(target);
     msg = String.valueOf(counter) + " -> ";
   } catch (NoSuchFieldException
       | SecurityException
       | IllegalArgumentException
       | IllegalAccessException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   String s = (String) joinPoint.proceed();
   return msg + s;
 }
  public static Action createByClass(String className, HashMap<String, String> params) {

    Action a = null;

    try {
      Class<?> c = ClassReflection.forName(className);
      a = (Action) ClassReflection.newInstance(c);

      if (params != null) {
        //				a.setParams(params);

        for (String key : params.keySet()) {
          String value = params.get(key);

          try {
            ActionUtils.setParam(a, key, value);
          } catch (NoSuchFieldException
              | SecurityException
              | IllegalArgumentException
              | IllegalAccessException e) {
            EngineLogger.error(
                "Error Setting Action Param - Action:"
                    + className
                    + " Param: "
                    + key
                    + " Value: "
                    + value
                    + " Msg: NOT FOUND "
                    + e.getMessage());
          }
        }
      }
    } catch (ReflectionException e) {
      EngineLogger.error(e.getMessage());
    }

    return a;
  }
  private static String getAddress(RestChannel channel) {
    String remoteHost = null;

    try {
      NettyHttpChannel obj = (NettyHttpChannel) channel;
      Field f;
      f = obj.getClass().getDeclaredField("channel");
      f.setAccessible(true);
      SocketChannel sc = (SocketChannel) f.get(obj);
      InetSocketAddress remoteHostAddr = sc.getRemoteAddress();
      remoteHost = remoteHostAddr.getAddress().getHostAddress();
      // Make sure we recognize localhost even when IPV6 is involved
      if (localhostRe.matcher(remoteHost).find()) {
        remoteHost = LOCALHOST;
      }
    } catch (NoSuchFieldException
        | SecurityException
        | IllegalArgumentException
        | IllegalAccessException e) {
      e.printStackTrace();
      return null;
    }
    return remoteHost;
  }
  private void extracted(Class<T> clazz, List<String> columns) {
    for (String column : columns) {
      try {
        try {
          Field declaredField = this.clazz.getDeclaredField(column);
          if (declaredField != null) {
            Class<?> type = declaredField.getType();
            tableColumns.add(generateTableColumns(type, column));
          }
        } catch (NoSuchFieldException e) {
          if (AbstractDVO.class.isAssignableFrom(clazz)) {
            Field superClassField = AbstractDVO.class.getDeclaredField(column);
            if (superClassField != null) {
              Class<?> type = superClassField.getType();
              tableColumns.add(generateTableColumns(type, column));
            }
          }
        }

      } catch (NoSuchFieldException | SecurityException e) {
        e.printStackTrace();
      }
    }
  }
Beispiel #10
0
  /**
   * WASD Control.
   *
   * @param sideMot
   * @param forMot
   */
  @Override
  public void g(float sideMot, float forMot) {
    if (!CustomEntities.customEntities.contains(this)) {
      super.g(sideMot, forMot);
      return;
    }
    if (getSize() != 3) setSize(3);
    if (this.passenger != null
        && this.passenger instanceof EntityHuman
        && CustomEntities.customEntities.contains(this)) {
      this.lastYaw = this.yaw = this.passenger.yaw;
      this.pitch = this.passenger.pitch * 0.5F;
      this.setYawPitch(this.yaw, this.pitch); // Update the pitch and yaw
      this.aI = this.aG = this.yaw;
      sideMot = ((EntityLiving) this.passenger).aZ * 0.5F;
      forMot = ((EntityLiving) this.passenger).ba;

      Field jump = null; // Jumping
      try {
        jump = EntityLiving.class.getDeclaredField("aY");
      } catch (NoSuchFieldException | SecurityException e1) {
        e1.printStackTrace();
      }
      jump.setAccessible(true);

      if (jump != null && BlockUtils.isOnGround(this.getBukkitEntity())) {
        try {
          if (jump.getBoolean(this.passenger)) {
            double jumpHeight = 0.3D;
            this.motY = jumpHeight;
          }
        } catch (IllegalAccessException e) {
          e.printStackTrace();
        }
      }

      this.S = 1.0F;
      this.aK = this.yaw;
      if (!this.world.isClientSide) {
        this.k(0.2f);

        if (bM()) {
          if (V()) {
            double d0 = locY;
            float f3 = 0.8F;
            float f4 = 0.02F;
            float f2 = EnchantmentManager.b(this);
            if (f2 > 3.0F) {
              f2 = 3.0F;
            }

            if (f2 > 0.0F) {
              f3 += (0.5460001F - f3) * f2 / 3.0F;
              f4 += (bI() * 1.0F - f4) * f2 / 3.0F;
            }

            a(sideMot, forMot, f4);
            move(motX, motY, motZ);
            motX *= f3;
            motY *= 0.800000011920929D;
            motZ *= f3;
            motY -= 0.02D;
            if ((positionChanged) && (c(motX, motY + 0.6000000238418579D - locY + d0, motZ)))
              motY = 0.300000011920929D;
          } else if (ab()) {
            double d0 = locY;
            a(sideMot, forMot, 0.02F);
            move(motX, motY, motZ);
            motX *= 0.5D;
            motY *= 0.5D;
            motZ *= 0.5D;
            motY -= 0.02D;
            if ((positionChanged) && (c(motX, motY + 0.6000000238418579D - locY + d0, motZ)))
              motY = 0.300000011920929D;
          } else {
            float f5 =
                world
                        .getType(
                            new BlockPosition(
                                MathHelper.floor(locX),
                                MathHelper.floor(getBoundingBox().b) - 1,
                                MathHelper.floor(locZ)))
                        .getBlock()
                        .frictionFactor
                    * 0.91F;

            float f6 = 0.1627714F / (f5 * f5 * f5);
            float f3 = bI() * f6;

            a(sideMot, forMot, f3);
            f5 =
                world
                        .getType(
                            new BlockPosition(
                                MathHelper.floor(locX),
                                MathHelper.floor(getBoundingBox().b) - 1,
                                MathHelper.floor(locZ)))
                        .getBlock()
                        .frictionFactor
                    * 0.91F;

            if (k_()) {
              float f4 = 0.15F;
              motX = MathHelper.a(motX, -f4, f4);
              motZ = MathHelper.a(motZ, -f4, f4);
              fallDistance = 0.0F;
              if (motY < -0.15D) {
                motY = -0.15D;
              }

              if (motY < 0.0D) {
                motY = 0.0D;
              }
            }

            move(motX, motY, motZ);
            if ((positionChanged) && (k_())) {
              motY = 0.2D;
            }

            if ((world.isClientSide)
                && ((!world.isLoaded(new BlockPosition((int) locX, 0, (int) locZ)))
                    || (!world
                        .getChunkAtWorldCoords(new BlockPosition((int) locX, 0, (int) locZ))
                        .o()))) {
              if (locY > 0.0D) motY = -0.1D;
              else motY = 0.0D;
            } else {
              motY += 0D;
            }

            motY *= 0.9800000190734863D;
            motX *= f5;
            motZ *= f5;
          }
        }

        ay = az;
        double d0 = locX - lastX;
        double d1 = locZ - lastZ;

        float f2 = MathHelper.sqrt(d0 * d0 + d1 * d1) * 4.0F;
        if (f2 > 1.0F) {
          f2 = 1.0F;
        }

        az += (f2 - az) * 0.4F;
        aA += az;

        super.g(sideMot, forMot);
      }

      this.ay = this.az;
      double d0 = this.locX - this.lastX;
      double d1 = this.locZ - this.lastZ;
      float f4 = MathHelper.sqrt(d0 * d0 + d1 * d1) * 4.0F;
      if (f4 > 1.0F) {
        f4 = 1.0F;
      }

      this.az += (f4 - this.az) * 0.4F;
      this.aA += this.az;
    } else {
      this.S = 0.5F;
      this.aK = 0.02F;
      super.g(sideMot, forMot);
    }
  }
Beispiel #11
0
  /**
   * Load native libraries required by LWJGL based on platform the application is running on.
   *
   * @param platform the platform the application is running on.
   */
  protected void loadNatives(SupportedPlatform platform) {
    if (null == platform) {
      throw new IllegalArgumentException("Platform can not be null");
    }

    // Application running path
    String path = getCodeSourcePathString();

    // Copy required libraries based on platform
    switch (platform) {
      case LINUX:
        copyFileFromJar("/native/linux/libjinput-linux.so", path + "/native/libjinput-linux.so");
        copyFileFromJar("/native/linux/liblwjgl.so", path + "/native/liblwjgl.so");
        copyFileFromJar("/native/linux/libopenal.so", path + "/native/libopenal.so");
        break;
      case LINUX_64:
        copyFileFromJar(
            "/native/linux/libjinput-linux64.so", path + "/native/libjinput-linux64.so");
        copyFileFromJar("/native/linux/liblwjgl64.so", path + "/native/liblwjgl64.so");
        copyFileFromJar("/native/linux/libopenal64.so", path + "/native/libopenal64.so");
        break;
      case MAC:
        copyFileFromJar(
            "/native/macosx/libjinput-osx.jnilib", path + "/native/libjinput-osx.jnilib");
        copyFileFromJar("/native/macosx/liblwjgl.lnilib", path + "/native/liblwjgl.lnilib");
        copyFileFromJar("/native/macosx/openal.dylib", path + "/native/openal.dylib");
        break;
      case MAC_64:
        copyFileFromJar(
            "/native/macosx/libjinput-osx.jnilib", path + "/native/libjinput-osx.jnilib");
        copyFileFromJar("/native/macosx/liblwjgl.lnilib", path + "/native/liblwjgl.lnilib");
        copyFileFromJar("/native/macosx/openal.dylib", path + "/native/openal.dylib");
        break;
      case WINDOWS:
        copyFileFromJar("/native/windows/jinput-raw.dll", path + "/native/jinput-raw.dll");
        copyFileFromJar("/native/windows/jinput-dx8.dll", path + "/native/jinput-dx8.dll");
        copyFileFromJar("/native/windows/lwjgl.dll", path + "/native/lwjgl.dll");
        copyFileFromJar("/native/windows/OpenAL32.dll", path + "/native/OpenAL32.dll");
        break;
      case WINDOWS_64:
        copyFileFromJar("/native/windows/jinput-raw_64.dll", path + "/native/jinput-raw_64.dll");
        copyFileFromJar("/native/windows/jinput-dx8_64.dll", path + "/native/jinput-dx8_64.dll");
        copyFileFromJar("/native/windows/lwjgl64.dll", path + "/native/lwjgl64.dll");
        copyFileFromJar("/native/windows/OpenAL64.dll", path + "/native/OpenAL64.dll");
        break;
      default:
        throw new IllegalStateException("Error when opening native library");
    }

    // Set library path to the VM
    System.setProperty("java.library.path", path + "native/");
    try {
      Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths");
      fieldSysPath.setAccessible(true);
      fieldSysPath.set(null, null);
    } catch (NoSuchFieldException
        | SecurityException
        | IllegalArgumentException
        | IllegalAccessException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Beispiel #12
0
    /** Map function for non-indexed blocks */
    public void map(
        final Prism cellMbr,
        final Writable value,
        final OutputCollector<Writable, NullWritable> output,
        Reporter reporter)
        throws IOException {
      if (value instanceof Shape) {
        Shape shape = (Shape) value;

        try {
          Class<?> c = shape.getClass();
          Field f;
          f = c.getDeclaredField(queryField);
          f.setAccessible(true);
          if (shape.isIntersected(queryShape)) {
            boolean report_result = false;
            if (cellMbr.isValid()) {
              // Check for duplicate avoidance using reference
              // point
              // technique
              double reference_t = Math.max(queryMbr.t1, shape.getMBR().t1);
              double reference_x = Math.max(queryMbr.x1, shape.getMBR().x1);
              double reference_y = Math.max(queryMbr.y1, shape.getMBR().y1);
              report_result = cellMbr.contains(reference_t, reference_x, reference_y);
            } else {
              // A heap block, report right away
              report_result = true;
            }

            if (report_result) {
              Writable result = null;
              if (f.getType().equals(Integer.TYPE)) {
                result = new IntWritable((int) f.get(shape));
              } else if (f.getType().equals(Double.TYPE)) {
                result = new DoubleWritable((int) f.get(shape));
              } else if (f.getType().equals(Long.TYPE)) {
                result = new LongWritable((int) f.get(shape));
              }
              output.collect(result, dummy);
            }
          }
        } catch (NoSuchFieldException
            | SecurityException
            | IllegalArgumentException
            | IllegalAccessException e1) {
          // TODO Auto-generated catch block
          e1.printStackTrace();
        }
      } else if (value instanceof RTree) {
        RTree<Shape> shapes = (RTree<Shape>) value;
        if (shapes.columnar) {
          shapes.searchColumnar(
              queryMbr,
              new ResultCollector<Writable>() {
                @Override
                public void collect(Writable shape) {
                  try {

                    output.collect(shape, dummy);

                  } catch (IOException e) {
                    e.printStackTrace();
                  } catch (SecurityException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                  } catch (IllegalArgumentException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                  }
                }
              },
              queryField);
        } else {
          shapes.search(
              queryMbr,
              new ResultCollector<Shape>() {
                @Override
                public void collect(Shape shape) {
                  try {
                    Class<?> c = shape.getClass();
                    Field f;
                    f = c.getDeclaredField(queryField);
                    f.setAccessible(true);
                    Writable result = null;
                    if (f.getType().equals(Integer.TYPE)) {
                      result = new IntWritable((int) f.get(shape));
                    } else if (f.getType().equals(Double.TYPE)) {
                      result = new DoubleWritable((int) f.get(shape));
                    } else if (f.getType().equals(Long.TYPE)) {
                      result = new LongWritable((int) f.get(shape));
                    }
                    output.collect(result, dummy);

                  } catch (IOException e) {
                    e.printStackTrace();
                  } catch (SecurityException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                  } catch (IllegalArgumentException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                  } catch (NoSuchFieldException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                  } catch (IllegalAccessException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                  }
                }
              },
              queryField);
        }
      }
    }