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