Search in sources :

Example 6 with EntityWrapper

use of me.deecaad.weaponmechanics.wrappers.EntityWrapper in project MechanicsMain by WeaponMechanics.

the class OutRemoveEntityEffectListener method onPacket.

@Override
public void onPacket(Packet packet) {
    // If packet entity id is not player's id
    if ((int) packet.getFieldValue(idField) != packet.getPlayer().getEntityId()) {
        return;
    }
    EntityWrapper entityWrapper = WeaponMechanics.getEntityWrapper(packet.getPlayer());
    if (!entityWrapper.getMainHandData().getZoomData().hasZoomNightVision() && !entityWrapper.getOffHandData().getZoomData().hasZoomNightVision())
        return;
    if (!WeaponCompatibilityAPI.getScopeCompatibility().isRemoveNightVisionPacket(packet))
        return;
    packet.setCancelled(true);
}
Also used : EntityWrapper(me.deecaad.weaponmechanics.wrappers.EntityWrapper)

Example 7 with EntityWrapper

use of me.deecaad.weaponmechanics.wrappers.EntityWrapper in project MechanicsMain by WeaponMechanics.

the class WeaponHandler method useTrigger.

/**
 * Checks main and off hand items if they're weapons and uses them based on trigger.
 * This is used with the exceptions off
 * {@link TriggerPlayerListeners#dropItem(PlayerDropItemEvent)},
 * {@link TriggerPlayerListeners#interact(PlayerInteractEvent)}
 * and {@link TriggerPlayerListeners#swapHandItems(PlayerSwapHandItemsEvent)}.
 *
 * @param livingEntity the living entity which caused trigger
 * @param triggerType the trigger type
 * @param autoConvert whether or not the weapon items should be converted
 */
public void useTrigger(LivingEntity livingEntity, TriggerType triggerType, boolean autoConvert) {
    // This because for all players this should be always nonnull
    // -> No auto add true to deny entity wrappers being added for unnecessary entities (they can also trigger certain
    EntityWrapper entityWrapper = getEntityWrapper(livingEntity, true);
    if (entityWrapper == null)
        return;
    if (livingEntity.getType() == EntityType.PLAYER && ((Player) livingEntity).getGameMode() == GameMode.SPECTATOR)
        return;
    EntityEquipment entityEquipment = livingEntity.getEquipment();
    if (entityEquipment == null)
        return;
    ItemStack mainStack = entityEquipment.getItemInMainHand();
    String mainWeapon = infoHandler.getWeaponTitle(mainStack, autoConvert);
    ItemStack offStack = entityEquipment.getItemInOffHand();
    String offWeapon = infoHandler.getWeaponTitle(offStack, autoConvert);
    if (mainWeapon == null && offWeapon == null)
        return;
    if (infoHandler.denyDualWielding(triggerType, livingEntity.getType() == EntityType.PLAYER ? (Player) livingEntity : null, mainWeapon, offWeapon))
        return;
    boolean dualWield = mainWeapon != null && offWeapon != null;
    if (mainWeapon != null)
        tryUses(entityWrapper, mainWeapon, mainStack, EquipmentSlot.HAND, triggerType, dualWield, null);
    if (offWeapon != null)
        tryUses(entityWrapper, offWeapon, offStack, EquipmentSlot.OFF_HAND, triggerType, dualWield, null);
}
Also used : Player(org.bukkit.entity.Player) EntityEquipment(org.bukkit.inventory.EntityEquipment) WeaponMechanics.getEntityWrapper(me.deecaad.weaponmechanics.WeaponMechanics.getEntityWrapper) EntityWrapper(me.deecaad.weaponmechanics.wrappers.EntityWrapper) ItemStack(org.bukkit.inventory.ItemStack)

Example 8 with EntityWrapper

use of me.deecaad.weaponmechanics.wrappers.EntityWrapper in project MechanicsMain by WeaponMechanics.

the class DamageUtil method calculateFinalDamage.

public static double calculateFinalDamage(LivingEntity cause, LivingEntity victim, double damage, DamagePoint point, boolean isBackStab) {
    Configuration config = WeaponMechanics.getBasicConfigurations();
    AtomicDouble rate = new AtomicDouble(1.0);
    EntityWrapper wrapper = WeaponMechanics.getEntityWrapper(victim);
    // Apply backstab damage
    if (isBackStab)
        rate.addAndGet(config.getDouble("Damage.Back"));
    // Apply damage per potion effect
    for (PotionEffect potion : victim.getActivePotionEffects()) {
        rate.addAndGet(config.getDouble("Damage.Potions." + potion.getType().getName()));
    }
    // Apply damage per armor and attachment
    for (ItemStack armorSlot : victim.getEquipment().getArmorContents()) {
        if (armorSlot == null)
            continue;
        // We parse Material and EquipmentSlot from the given item. Note
        // that all armor names are formatted like: DIAMOND_CHESTPLATE,
        // IRON_BOOTS, LEATHER_HELMET, hence Material_Equipment slot.
        // Normally we would split at the '_', but using String#split is
        // ~50x slower than String#subString.
        String name = armorSlot.getType().name();
        int splitIndex = name.indexOf('_');
        if (splitIndex == -1)
            continue;
        // This method of parsing material and slot has issues with
        // materials like ACACIA_BOAT. In this case, it will fail silently
        // by adding 0.0 to the rate.
        String material = name.substring(0, splitIndex);
        String slot = name.substring(splitIndex + 1);
        rate.addAndGet(config.getDouble("Damage.Armor." + slot + "." + material, 0.0));
        armorSlot.getEnchantments().forEach((enchant, level) -> rate.addAndGet(level * config.getDouble("Damage.Armor.Enchantments." + enchant.getKey().getKey())));
    }
    // Apply damage based on victim movement
    if (wrapper.isInMidair())
        rate.addAndGet(config.getDouble("Damage.Movement.In_Midair"));
    if (wrapper.isWalking())
        rate.addAndGet(config.getDouble("Damage.Movement.Walking"));
    if (wrapper.isSwimming())
        rate.addAndGet(config.getDouble("Damage.Movement.Swimming"));
    if (wrapper.isSprinting())
        rate.addAndGet(config.getDouble("Damage.Movement.Sprinting"));
    if (wrapper.isSneaking())
        rate.addAndGet(config.getDouble("Damage.Movement.Sneaking"));
    // Apply damage based on the point that hit the victim
    if (point != null) {
        rate.addAndGet(config.getDouble("Damage.Critical_Points." + point.name()));
    }
    // Make sure damage is within ranges
    rate.set(Math.min(rate.get(), config.getDouble("Damage.Maximum_Rate")));
    rate.set(Math.max(rate.get(), config.getDouble("Damage.Minimum_Rate")));
    // Apply damage to victim
    return damage * rate.get();
}
Also used : Configuration(me.deecaad.core.file.Configuration) AtomicDouble(com.google.common.util.concurrent.AtomicDouble) PotionEffect(org.bukkit.potion.PotionEffect) EntityWrapper(me.deecaad.weaponmechanics.wrappers.EntityWrapper) ItemStack(org.bukkit.inventory.ItemStack)

Example 9 with EntityWrapper

use of me.deecaad.weaponmechanics.wrappers.EntityWrapper in project MechanicsMain by WeaponMechanics.

the class Explosion method explode.

public void explode(LivingEntity cause, Location origin, WeaponProjectile projectile) {
    // Handle worldguard flags
    WorldGuardCompatibility worldGuard = CompatibilityAPI.getWorldGuardCompatibility();
    EntityWrapper entityWrapper = WeaponMechanics.getEntityWrapper(cause);
    if (!worldGuard.testFlag(origin, entityWrapper instanceof PlayerWrapper ? ((PlayerWrapper) entityWrapper).getPlayer() : null, "weapon-explode")) {
        Object obj = worldGuard.getValue(origin, "weapon-explode-message");
        if (obj != null && !obj.toString().isEmpty()) {
            entityWrapper.getEntity().sendMessage(StringUtil.color(obj.toString()));
        }
        return;
    }
    // triggered instead of the explosion.
    if (projectile != null && airStrike != null && projectile.getIntTag("airstrike-bomb") == 0) {
        airStrike.trigger(origin, cause, projectile);
        return;
    }
    List<Block> blocks;
    BlockRegenSorter sorter;
    DoubleMap<LivingEntity> entities;
    if (projectile != null) {
        // This event is not cancellable. If developers want to cancel
        // explosions, they should use ProjectilePreExplodeEvent
        ProjectileExplodeEvent event = new ProjectileExplodeEvent(projectile, shape.getBlocks(origin), new LayerDistanceSorter(origin, this), exposure.mapExposures(origin, shape));
        Bukkit.getPluginManager().callEvent(event);
        blocks = event.getBlocks();
        sorter = event.getSorter();
        entities = event.getEntities();
    } else {
        blocks = shape.getBlocks(origin);
        sorter = new LayerDistanceSorter(origin, this);
        entities = exposure.mapExposures(origin, shape);
    }
    int initialCapacity = Math.max(blocks.size(), 10);
    List<Block> transparent = new ArrayList<>(initialCapacity);
    List<Block> solid = new ArrayList<>(initialCapacity);
    // redstone contraptions.
    for (Block block : blocks) {
        if (block.getType().isSolid()) {
            solid.add(block);
        } else if (!block.isEmpty()) {
            transparent.add(block);
        }
    }
    // regenerate in a random order.
    try {
        if (sorter == null) {
            debug.debug("Null sorter used while regenerating explosion... Was this intentional?");
        } else {
            solid.sort(sorter);
        }
    } catch (IllegalArgumentException e) {
        debug.log(LogLevel.ERROR, "A plugin modified the explosion block sorter with an illegal sorter! " + "Please report this error to the developers of that plugin. Sorter: " + sorter.getClass(), e);
    }
    // spawn falling blocks. We also don't need to worry about regeneration.
    if (blockDamage != null) {
        int timeOffset = regeneration == null ? -1 : (solid.size() * regeneration.getInterval() / regeneration.getMaxBlocksPerUpdate());
        damageBlocks(transparent, true, origin, timeOffset);
        damageBlocks(solid, false, origin, 0);
    }
    if (projectile != null && projectile.getWeaponTitle() != null) {
        WeaponMechanics.getWeaponHandler().getDamageHandler().tryUseExplosion(projectile, origin, entities);
        // higher your exposure, the greater the knockback.
        if (isKnockback) {
            Vector originVector = origin.toVector();
            for (DoubleEntry<LivingEntity> entry : entities.entrySet()) {
                LivingEntity entity = entry.getKey();
                double exposure = entry.getValue();
                // Normalized vector between the explosion and entity involved
                Vector between = VectorUtil.setLength(entity.getLocation().toVector().subtract(originVector), exposure);
                Vector motion = entity.getVelocity().add(between);
                entity.setVelocity(motion);
            }
        }
        if (cluster != null)
            cluster.trigger(projectile, cause, origin);
    } else {
        // size explosion they may want
        for (DoubleEntry<LivingEntity> entry : entities.entrySet()) {
            LivingEntity entity = entry.getKey();
            double impact = entry.getValue();
            entity.sendMessage(StringUtil.color("&cYou suffered " + impact * 100 + "% of the impact"));
        }
    }
    if (flashbang != null)
        flashbang.trigger(exposure, projectile, origin);
    if (mechanics != null)
        mechanics.use(new CastData(entityWrapper, origin, projectile == null ? null : projectile.getWeaponTitle(), projectile == null ? null : projectile.getWeaponStack()));
}
Also used : CastData(me.deecaad.weaponmechanics.mechanics.CastData) BlockRegenSorter(me.deecaad.weaponmechanics.weapon.explode.regeneration.BlockRegenSorter) LayerDistanceSorter(me.deecaad.weaponmechanics.weapon.explode.regeneration.LayerDistanceSorter) ArrayList(java.util.ArrayList) PlayerWrapper(me.deecaad.weaponmechanics.wrappers.PlayerWrapper) LivingEntity(org.bukkit.entity.LivingEntity) WorldGuardCompatibility(me.deecaad.core.compatibility.worldguard.WorldGuardCompatibility) EntityWrapper(me.deecaad.weaponmechanics.wrappers.EntityWrapper) Block(org.bukkit.block.Block) Vector(org.bukkit.util.Vector) ProjectileExplodeEvent(me.deecaad.weaponmechanics.weapon.weaponevents.ProjectileExplodeEvent)

Example 10 with EntityWrapper

use of me.deecaad.weaponmechanics.wrappers.EntityWrapper in project MechanicsMain by WeaponMechanics.

the class Flashbang method effect.

public void effect(WeaponProjectile projectile, LivingEntity entity) {
    if (mechanics != null) {
        EntityWrapper wrapper = WeaponMechanics.getEntityWrapper(entity);
        mechanics.use(new CastData(wrapper, projectile.getWeaponTitle(), projectile.getWeaponStack()));
    }
}
Also used : CastData(me.deecaad.weaponmechanics.mechanics.CastData) EntityWrapper(me.deecaad.weaponmechanics.wrappers.EntityWrapper)

Aggregations

EntityWrapper (me.deecaad.weaponmechanics.wrappers.EntityWrapper)17 CastData (me.deecaad.weaponmechanics.mechanics.CastData)4 Player (org.bukkit.entity.Player)4 EventHandler (org.bukkit.event.EventHandler)4 ItemStack (org.bukkit.inventory.ItemStack)4 PlayerWrapper (me.deecaad.weaponmechanics.wrappers.PlayerWrapper)3 LivingEntity (org.bukkit.entity.LivingEntity)3 Configuration (me.deecaad.core.file.Configuration)2 WeaponMechanics.getEntityWrapper (me.deecaad.weaponmechanics.WeaponMechanics.getEntityWrapper)2 EntityEquipment (org.bukkit.inventory.EntityEquipment)2 AtomicDouble (com.google.common.util.concurrent.AtomicDouble)1 ArrayList (java.util.ArrayList)1 Nonnegative (javax.annotation.Nonnegative)1 Nullable (javax.annotation.Nullable)1 WorldGuardCompatibility (me.deecaad.core.compatibility.worldguard.WorldGuardCompatibility)1 WeaponMechanics (me.deecaad.weaponmechanics.WeaponMechanics)1 Mechanics (me.deecaad.weaponmechanics.mechanics.Mechanics)1 BlockRegenSorter (me.deecaad.weaponmechanics.weapon.explode.regeneration.BlockRegenSorter)1 LayerDistanceSorter (me.deecaad.weaponmechanics.weapon.explode.regeneration.LayerDistanceSorter)1 WeaponInfoDisplay (me.deecaad.weaponmechanics.weapon.info.WeaponInfoDisplay)1