コード例 #1
0
  public static PacketPlayOutEntityDestroy getDestroyEntityPacket() {
    PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy();

    Field a = ReflectionUtil.getDeclaredField(packet.getClass(), "a");
    a.setAccessible(true);
    try {
      a.set(packet, new int[] {ENTITY_ID});
    } catch (IllegalArgumentException e) {
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      e.printStackTrace();
    }

    return packet;
  }
コード例 #2
0
  public static PacketPlayInClientCommand getRespawnPacket() {
    PacketPlayInClientCommand packet = new PacketPlayInClientCommand();

    Field a = ReflectionUtil.getDeclaredField(packet.getClass(), "a");
    a.setAccessible(true);
    try {
      a.set(packet, (int) 1);
    } catch (IllegalArgumentException e) {
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      e.printStackTrace();
    }

    return packet;
  }
コード例 #3
0
ファイル: EndermanNPC.java プロジェクト: Robotia/BetterShops
  public static Object getPrivateField(
      String fieldName, Class<PathfinderGoalSelector> clazz, Object object) {

    Field field;
    Object o = null;

    try {
      field = clazz.getDeclaredField(fieldName);
      field.setAccessible(true);
      o = field.get(object);

    } catch (NoSuchFieldException e) {

      e.printStackTrace();

    } catch (IllegalAccessException e) {
      e.printStackTrace();
    }
    return o;
  }
コード例 #4
0
  public static PacketPlayOutEntityMetadata getMetadataPacket(DataWatcher watcher) {
    PacketPlayOutEntityMetadata metaPacket = new PacketPlayOutEntityMetadata();

    Field a = ReflectionUtil.getDeclaredField(metaPacket.getClass(), "a");
    a.setAccessible(true);
    try {
      a.set(metaPacket, (int) ENTITY_ID);
    } catch (IllegalArgumentException e1) {
      e1.printStackTrace();
    } catch (IllegalAccessException e1) {
      e1.printStackTrace();
    }

    try {
      Field b = PacketPlayOutEntityMetadata.class.getDeclaredField("b");
      b.setAccessible(true);
      b.set(metaPacket, watcher.c());
    } catch (Exception e) {
      e.printStackTrace();
    }

    return metaPacket;
  }
コード例 #5
0
  // Accessing packets
  @SuppressWarnings("deprecation")
  public static PacketPlayOutSpawnEntityLiving getMobPacket(String text, Location loc) {
    PacketPlayOutSpawnEntityLiving mobPacket = new PacketPlayOutSpawnEntityLiving();

    try {
      Field a = ReflectionUtil.getDeclaredField(mobPacket.getClass(), "a");
      a.setAccessible(true);
      a.set(mobPacket, (int) ENTITY_ID);

      Field b = ReflectionUtil.getDeclaredField(mobPacket.getClass(), "b");
      b.setAccessible(true);
      b.set(mobPacket, (byte) EntityType.WITHER.getTypeId());

      Field c = ReflectionUtil.getDeclaredField(mobPacket.getClass(), "c");
      c.setAccessible(true);
      c.set(mobPacket, (int) Math.floor(loc.getBlockX() * 32.0D));

      Field d = ReflectionUtil.getDeclaredField(mobPacket.getClass(), "d");
      d.setAccessible(true);
      d.set(mobPacket, (int) Math.floor(loc.getBlockY() * 32.0D));

      Field e = ReflectionUtil.getDeclaredField(mobPacket.getClass(), "e");
      e.setAccessible(true);
      e.set(mobPacket, (int) Math.floor(loc.getBlockZ() * 32.0D));

      Field f = ReflectionUtil.getDeclaredField(mobPacket.getClass(), "f");
      f.setAccessible(true);
      f.set(mobPacket, (byte) 0);

      Field g = ReflectionUtil.getDeclaredField(mobPacket.getClass(), "g");
      g.setAccessible(true);
      g.set(mobPacket, (byte) 0);

      Field h = ReflectionUtil.getDeclaredField(mobPacket.getClass(), "h");
      h.setAccessible(true);
      h.set(mobPacket, (byte) 0);

      Field i = ReflectionUtil.getDeclaredField(mobPacket.getClass(), "i");
      i.setAccessible(true);
      i.set(mobPacket, (byte) 0);

      Field j = ReflectionUtil.getDeclaredField(mobPacket.getClass(), "j");
      j.setAccessible(true);
      j.set(mobPacket, (byte) 0);

      Field k = ReflectionUtil.getDeclaredField(mobPacket.getClass(), "k");
      k.setAccessible(true);
      k.set(mobPacket, (byte) 0);

    } catch (IllegalArgumentException e1) {
      e1.printStackTrace();
    } catch (IllegalAccessException e1) {
      e1.printStackTrace();
    }

    DataWatcher watcher = getWatcher(text, 300);

    try {
      Field t = PacketPlayOutSpawnEntityLiving.class.getDeclaredField("l");
      t.setAccessible(true);
      t.set(mobPacket, watcher);
    } catch (Exception ex) {
      ex.printStackTrace();
    }

    return mobPacket;
  }