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);
}
}
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();
}
Aggregations