Search in sources :

Example 16 with EntityWrapper

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

the class TriggerEntityListeners method damage.

@EventHandler
public void damage(EntityDamageByEntityEvent e) {
    EntityDamageEvent.DamageCause cause = e.getCause();
    if (cause != EntityDamageEvent.DamageCause.ENTITY_ATTACK && cause != EntityDamageEvent.DamageCause.ENTITY_SWEEP_ATTACK)
        return;
    if (getBasicConfigurations().getBool("Disabled_Trigger_Checks.Right_And_Left_Click"))
        return;
    Entity damager = e.getDamager();
    Entity victim = e.getEntity();
    if (!damager.getType().isAlive() || !victim.getType().isAlive())
        return;
    EntityWrapper entityWrapper = getEntityWrapper((LivingEntity) damager, true);
    if (entityWrapper == null)
        return;
    LivingEntity livingEntity = entityWrapper.getEntity();
    EntityEquipment entityEquipment = livingEntity.getEquipment();
    if (entityEquipment == null)
        return;
    ItemStack mainStack = entityEquipment.getItemInMainHand();
    String mainWeapon = weaponHandler.getInfoHandler().getWeaponTitle(mainStack, false);
    ItemStack offStack = entityEquipment.getItemInOffHand();
    String offWeapon = weaponHandler.getInfoHandler().getWeaponTitle(offStack, false);
    if (mainWeapon == null && offWeapon == null)
        return;
    if (mainWeapon != null) {
        // Cancel melee with weapons by default
        e.setCancelled(true);
    }
    // When sweep hit we don't want to do actual melee casts
    if (cause == EntityDamageEvent.DamageCause.ENTITY_SWEEP_ATTACK)
        return;
    if (weaponHandler.getInfoHandler().denyDualWielding(TriggerType.MELEE, livingEntity.getType() == EntityType.PLAYER ? (Player) livingEntity : null, mainWeapon, offWeapon))
        return;
    if (mainStack.getAmount() != 0) {
        weaponHandler.tryUses(entityWrapper, mainWeapon, mainStack, EquipmentSlot.HAND, TriggerType.MELEE, mainWeapon != null && offWeapon != null, (LivingEntity) victim);
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) EntityEquipment(org.bukkit.inventory.EntityEquipment) EntityWrapper(me.deecaad.weaponmechanics.wrappers.EntityWrapper) WeaponMechanics.getEntityWrapper(me.deecaad.weaponmechanics.WeaponMechanics.getEntityWrapper) ItemStack(org.bukkit.inventory.ItemStack) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent) EventHandler(org.bukkit.event.EventHandler)

Example 17 with EntityWrapper

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

the class WeaponMechanicsAPI method isReloading.

/**
 * Returns <code>true</code> if the given <code>entity</code> is reloading
 * their weapon.
 *
 * @param entity The non-null living entity to check the reload state of.
 * @return <code>true</code> if the entity is reloading.
 */
public static boolean isReloading(@Nonnull LivingEntity entity) {
    checkState();
    notNull(entity);
    EntityWrapper wrapper = WeaponMechanics.getEntityWrapper(entity, true);
    if (wrapper == null)
        return false;
    return wrapper.getMainHandData().isReloading() || wrapper.getOffHandData().isReloading();
}
Also used : 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