Search in sources :

Example 1 with WrappedBlockData

use of com.comphenix.protocol.wrappers.WrappedBlockData 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)

Example 2 with WrappedBlockData

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

the class ParamInfoParticle method toString.

@Override
public String toString(Object object) {
    WrappedParticle particle = (WrappedParticle) object;
    Object data = particle.getData();
    String returns = particle.getParticle().name();
    if (data != null) {
        if (data instanceof ItemStack) {
            returns += "," + ((ItemStack) data).getType().name();
        } else if (data instanceof WrappedBlockData) {
            returns += "," + ((WrappedBlockData) data).getType().name();
        } else if (data instanceof Particle.DustOptions) {
            returns += "," + ParamInfoManager.getParamInfo(Color.class).toString(((Particle.DustOptions) data).getColor());
            if (((Particle.DustOptions) data).getSize() != 1f) {
                returns += "," + ((Particle.DustOptions) data).getSize();
            }
        }
    }
    return returns;
}
Also used : WrappedBlockData(com.comphenix.protocol.wrappers.WrappedBlockData) Particle(org.bukkit.Particle) WrappedParticle(com.comphenix.protocol.wrappers.WrappedParticle) WrappedParticle(com.comphenix.protocol.wrappers.WrappedParticle) Color(org.bukkit.Color) ItemStack(org.bukkit.inventory.ItemStack)

Example 3 with WrappedBlockData

use of com.comphenix.protocol.wrappers.WrappedBlockData in project CombatLogX by SirBlobman.

the class ForceFieldAdapter method onPacketSending.

@Override
public void onPacketSending(PacketEvent e) {
    if (e.isCancelled()) {
        return;
    }
    Player player = e.getPlayer();
    ICombatManager combatManager = this.plugin.getCombatManager();
    if (!combatManager.isInCombat(player)) {
        return;
    }
    World world = player.getWorld();
    PacketContainer packetContainer = e.getPacket();
    Location location = getLocation0(world, packetContainer);
    if (isForceFieldBlock(player, location)) {
        WrappedBlockData wrappedBlockData = getWrappedBlockData();
        if (wrappedBlockData != null) {
            packetContainer.getBlockData().writeSafely(0, wrappedBlockData);
        }
    }
}
Also used : WrappedBlockData(com.comphenix.protocol.wrappers.WrappedBlockData) Player(org.bukkit.entity.Player) PacketContainer(com.comphenix.protocol.events.PacketContainer) ICombatManager(com.github.sirblobman.combatlogx.api.manager.ICombatManager) World(org.bukkit.World) Location(org.bukkit.Location)

Aggregations

WrappedBlockData (com.comphenix.protocol.wrappers.WrappedBlockData)3 WrappedParticle (com.comphenix.protocol.wrappers.WrappedParticle)2 ItemStack (org.bukkit.inventory.ItemStack)2 PacketContainer (com.comphenix.protocol.events.PacketContainer)1 FieldAccessException (com.comphenix.protocol.reflect.FieldAccessException)1 BlockPosition (com.comphenix.protocol.wrappers.BlockPosition)1 Direction (com.comphenix.protocol.wrappers.EnumWrappers.Direction)1 Vector3F (com.comphenix.protocol.wrappers.Vector3F)1 WrappedChatComponent (com.comphenix.protocol.wrappers.WrappedChatComponent)1 WrappedDataWatcherObject (com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject)1 WrappedWatchableObject (com.comphenix.protocol.wrappers.WrappedWatchableObject)1 NbtWrapper (com.comphenix.protocol.wrappers.nbt.NbtWrapper)1 ICombatManager (com.github.sirblobman.combatlogx.api.manager.ICombatManager)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 Color (org.bukkit.Color)1