Solved Getting superclass BaseBlockPosition from BlockPosition in PacketPlayInDigEvent

Discussion in 'Spigot Plugin Development' started by hydos06, Jan 16, 2020.

  1. I have being using reflection for some time and ive came across the PacketPlayInBlockDig class. when trying to grab the x y and z of the block ive being trying to get the superclass'es method to no avail. is there a better way or what am i doing wrong? here is the code
    Code (Java):
                Object blockPosition = rawPacket.getClass().getMethod("a",  new Class[]{}).invoke(rawPacket, new Object[] {}).getClass().getSuperclass();

                position = ReflectionUtils.getBlockCoordsFromBlockPosition(blockPosition);
    Code (Java):
        public static List<Field> getAllFields(Class<?> type) {
            List<Field> fields = new ArrayList<Field>();
            for (Class<?> c = type; c != null; c = c.getSuperclass()) {
            return fields;
        public static Vector getBlockCoordsFromBlockPosition(Object obj) throws IllegalArgumentException, IllegalAccessException {
            List<Field> superFields = getAllFields(obj.getClass());
            int x = -1;
            int y = -1;
            int z = -1;
            for(Field f: superFields) {
                if(f.getClass().getSimpleName().equalsIgnoreCase("BaseBlockPosition")) {
                    Bukkit.broadcastMessage("getting closer");
            return new Vector(x,y,z);
    any help is appreciated. Thanks
  2. md_5

    Administrator Developer

    Is there something wrong with the getX/Y/Z methods?
    • Like Like x 1
  3. oops... i was looking through the code just now and i think i missed it xp. Thanks for the help though