Search in sources :

Example 1 with Vector3F

use of com.comphenix.protocol.wrappers.Vector3F in project InteractionVisualizer by LOOHP.

the class WatchableCollection method getWatchableCollection.

public static WrappedDataWatcher getWatchableCollection(ArmorStand stand, WrappedDataWatcher watcher) {
    if (watcher == null) {
        watcher = new WrappedDataWatcher();
    }
    byte bitmask = (byte) 0;
    bitmask = !stand.isVisible() ? (byte) (bitmask | 0x20) : bitmask;
    watcher.setObject(new WrappedDataWatcherObject(0, byteSerializer), bitmask);
    switch(metaversion) {
        case 0:
            if (stand.getCustomName() != null && !PlainTextComponentSerializer.plainText().serialize(stand.getCustomName()).equals("")) {
                watcher.setObject(new WrappedDataWatcherObject(2, stringSerializer), LegacyComponentSerializer.legacySection().serialize(LanguageUtils.convert(stand.getCustomName(), InteractionVisualizer.language)));
            } else {
                watcher.setObject(new WrappedDataWatcherObject(2, stringSerializer), "");
            }
            break;
        case 1:
        case 2:
        case 3:
        case 4:
            watcher.setObject(new WrappedDataWatcherObject(2, optChatSerializer), Optional.of(WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(stand.getCustomName())).getHandle()));
            break;
    }
    watcher.setObject(new WrappedDataWatcherObject(3, booleanSerializer), stand.isCustomNameVisible());
    watcher.setObject(new WrappedDataWatcherObject(4, booleanSerializer), stand.isSilent());
    watcher.setObject(new WrappedDataWatcherObject(5, booleanSerializer), !stand.hasGravity());
    byte standbitmask = (byte) 0;
    standbitmask = stand.isSmall() ? (byte) (standbitmask | 0x01) : standbitmask;
    standbitmask = stand.hasArms() ? (byte) (standbitmask | 0x04) : standbitmask;
    standbitmask = !stand.hasBasePlate() ? (byte) (standbitmask | 0x08) : standbitmask;
    standbitmask = stand.isMarker() ? (byte) (standbitmask | 0x10) : standbitmask;
    switch(metaversion) {
        case 0:
        case 1:
            watcher.setObject(new WrappedDataWatcherObject(11, byteSerializer), standbitmask);
            break;
        case 2:
            watcher.setObject(new WrappedDataWatcherObject(13, byteSerializer), standbitmask);
            break;
        case 3:
            watcher.setObject(new WrappedDataWatcherObject(14, byteSerializer), standbitmask);
            break;
        case 4:
            watcher.setObject(new WrappedDataWatcherObject(15, byteSerializer), standbitmask);
            break;
    }
    Vector3F headrotation = new Vector3F();
    headrotation.setX((float) Math.toDegrees(stand.getHeadPose().getX()));
    headrotation.setY((float) Math.toDegrees(stand.getHeadPose().getY()));
    headrotation.setZ((float) Math.toDegrees(stand.getHeadPose().getZ()));
    switch(metaversion) {
        case 0:
        case 1:
            watcher.setObject(new WrappedDataWatcherObject(12, vectorSerializer), headrotation);
            break;
        case 2:
            watcher.setObject(new WrappedDataWatcherObject(14, vectorSerializer), headrotation);
            break;
        case 3:
            watcher.setObject(new WrappedDataWatcherObject(15, vectorSerializer), headrotation);
            break;
        case 4:
            watcher.setObject(new WrappedDataWatcherObject(16, vectorSerializer), headrotation);
            break;
    }
    Vector3F rightarmrotation = new Vector3F();
    rightarmrotation.setX((float) Math.toDegrees(stand.getRightArmPose().getX()));
    rightarmrotation.setY((float) Math.toDegrees(stand.getRightArmPose().getY()));
    rightarmrotation.setZ((float) Math.toDegrees(stand.getRightArmPose().getZ()));
    switch(metaversion) {
        case 0:
        case 1:
            watcher.setObject(new WrappedDataWatcherObject(15, vectorSerializer), rightarmrotation);
            break;
        case 2:
            watcher.setObject(new WrappedDataWatcherObject(17, vectorSerializer), rightarmrotation);
            break;
        case 3:
            watcher.setObject(new WrappedDataWatcherObject(18, vectorSerializer), rightarmrotation);
            break;
        case 4:
            watcher.setObject(new WrappedDataWatcherObject(19, vectorSerializer), rightarmrotation);
            break;
    }
    return watcher;
}
Also used : WrappedDataWatcherObject(com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject) Vector3F(com.comphenix.protocol.wrappers.Vector3F) WrappedDataWatcher(com.comphenix.protocol.wrappers.WrappedDataWatcher)

Example 2 with Vector3F

use of com.comphenix.protocol.wrappers.Vector3F in project LibsDisguises by libraryaddict.

the class ArmorStandWatcher method setPose.

private void setPose(MetaIndex<Vector3F> type, EulerAngle vector) {
    setData(type, new Vector3F((float) vector.getX(), (float) vector.getY(), (float) vector.getZ()));
    sendData(type);
}
Also used : Vector3F(com.comphenix.protocol.wrappers.Vector3F)

Example 3 with Vector3F

use of com.comphenix.protocol.wrappers.Vector3F in project LibsDisguises by libraryaddict.

the class ReflectionManager method convertInvalidMeta.

public static Object convertInvalidMeta(Object value) {
    if (value instanceof Optional) {
        Optional opt = (Optional) value;
        if (!opt.isPresent()) {
            return NmsVersion.v1_13.isSupported() ? value : com.google.common.base.Optional.absent();
        }
        if (nmsReflection != null) {
            return nmsReflection.convertOptional(opt.get());
        }
        Object val = opt.get();
        if (val instanceof BlockPosition) {
            BlockPosition pos = (BlockPosition) val;
            try {
                Object obj = blockPositionConstructor.newInstance(pos.getX(), pos.getY(), pos.getZ());
                return NmsVersion.v1_13.isSupported() ? Optional.of(obj) : com.google.common.base.Optional.of(obj);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        } else if (val instanceof WrappedBlockData) {
            try {
                Object obj = ((WrappedBlockData) val).getHandle();
                return NmsVersion.v1_13.isSupported() ? Optional.of(obj) : com.google.common.base.Optional.of(obj);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        } else if (val instanceof ItemStack) {
            val = getNmsItem((ItemStack) val);
            if (val == null) {
                return NmsVersion.v1_13.isSupported() ? Optional.empty() : com.google.common.base.Optional.absent();
            } else {
                return Optional.of(val);
            }
        } else if (val instanceof WrappedChatComponent) {
            Object obj = ((WrappedChatComponent) val).getHandle();
            return NmsVersion.v1_13.isSupported() ? Optional.of(obj) : com.google.common.base.Optional.of(obj);
        } else if (!NmsVersion.v1_13.isSupported()) {
            return com.google.common.base.Optional.of(val);
        } else {
            return Optional.of(val);
        }
    } else if (value instanceof Vector3F) {
        Vector3F angle = (Vector3F) value;
        if (nmsReflection != null) {
            return nmsReflection.convertVec3(angle);
        }
        try {
            return vector3FConstructor.newInstance(angle.getX(), angle.getY(), angle.getZ());
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    } else if (value instanceof EulerAngle) {
        EulerAngle angle = (EulerAngle) value;
        if (nmsReflection != null) {
            return nmsReflection.convertVec3(angle);
        }
        try {
            return vector3FConstructor.newInstance((float) angle.getX(), (float) angle.getY(), (float) angle.getZ());
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    } else if (value instanceof Direction) {
        if (nmsReflection != null) {
            return nmsReflection.convertDirection((Direction) value);
        }
        try {
            return enumDirectionFrom.invoke(null, ((Direction) value).ordinal());
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    } else if (value instanceof BlockPosition) {
        BlockPosition pos = (BlockPosition) value;
        if (nmsReflection != null) {
            return nmsReflection.getBlockPosition(pos.getX(), pos.getY(), pos.getZ());
        }
        try {
            return blockPositionConstructor.newInstance(pos.getX(), pos.getY(), pos.getZ());
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    } else if (value instanceof ItemStack) {
        return getNmsItem((ItemStack) value);
    } else if (value instanceof Double) {
        return ((Double) value).floatValue();
    } else if (value instanceof NbtWrapper) {
        return ((NbtWrapper) value).getHandle();
    } else if (value instanceof WrappedParticle) {
        return ((WrappedParticle) value).getHandle();
    } else if (value instanceof EntityPose) {
        return getNmsEntityPose((EntityPose) value);
    } else if (value instanceof VillagerData) {
        return getNmsVillagerData((VillagerData) value);
    } else if (value instanceof WrappedChatComponent) {
        return ((WrappedChatComponent) value).getHandle();
    }
    return value;
}
Also used : WrappedBlockData(com.comphenix.protocol.wrappers.WrappedBlockData) WrappedChatComponent(com.comphenix.protocol.wrappers.WrappedChatComponent) Optional(java.util.Optional) BlockPosition(com.comphenix.protocol.wrappers.BlockPosition) WrappedParticle(com.comphenix.protocol.wrappers.WrappedParticle) Direction(com.comphenix.protocol.wrappers.EnumWrappers.Direction) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) FieldAccessException(com.comphenix.protocol.reflect.FieldAccessException) Vector3F(com.comphenix.protocol.wrappers.Vector3F) VillagerData(me.libraryaddict.disguise.disguisetypes.VillagerData) WrappedDataWatcherObject(com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject) AccessibleObject(java.lang.reflect.AccessibleObject) WrappedWatchableObject(com.comphenix.protocol.wrappers.WrappedWatchableObject) ItemStack(org.bukkit.inventory.ItemStack) EulerAngle(org.bukkit.util.EulerAngle) NbtWrapper(com.comphenix.protocol.wrappers.nbt.NbtWrapper) EntityPose(me.libraryaddict.disguise.disguisetypes.EntityPose)

Aggregations

Vector3F (com.comphenix.protocol.wrappers.Vector3F)3 WrappedDataWatcherObject (com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject)2 FieldAccessException (com.comphenix.protocol.reflect.FieldAccessException)1 BlockPosition (com.comphenix.protocol.wrappers.BlockPosition)1 Direction (com.comphenix.protocol.wrappers.EnumWrappers.Direction)1 WrappedBlockData (com.comphenix.protocol.wrappers.WrappedBlockData)1 WrappedChatComponent (com.comphenix.protocol.wrappers.WrappedChatComponent)1 WrappedDataWatcher (com.comphenix.protocol.wrappers.WrappedDataWatcher)1 WrappedParticle (com.comphenix.protocol.wrappers.WrappedParticle)1 WrappedWatchableObject (com.comphenix.protocol.wrappers.WrappedWatchableObject)1 NbtWrapper (com.comphenix.protocol.wrappers.nbt.NbtWrapper)1 IOException (java.io.IOException)1 AccessibleObject (java.lang.reflect.AccessibleObject)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Optional (java.util.Optional)1 EntityPose (me.libraryaddict.disguise.disguisetypes.EntityPose)1 VillagerData (me.libraryaddict.disguise.disguisetypes.VillagerData)1 ItemStack (org.bukkit.inventory.ItemStack)1 EulerAngle (org.bukkit.util.EulerAngle)1