Search in sources :

Example 1 with Explosion

use of me.deecaad.weaponmechanics.weapon.explode.Explosion in project MechanicsMain by WeaponMechanics.

the class Projectile method shoot.

/**
 * Shoots created projectile object
 *
 * @param projectile the created projectile object
 * @param location the location containing pitch and yaw
 */
public WeaponProjectile shoot(WeaponProjectile projectile, Location location) {
    WeaponMechanics.getProjectilesRunnable().addProjectile(projectile);
    if (mechanics != null)
        mechanics.use(new CastData(projectile));
    EntityType type = projectileSettings.getProjectileDisguise();
    if (type != null) {
        FakeEntity fakeEntity;
        Object data = projectileSettings.getDisguiseData();
        if (type == EntityType.ARMOR_STAND && data != null) {
            // Armor stand height * eye height multiplier
            // 1.975 * 0.85 = 1.67875
            Location offset = new Location(location.getWorld(), 0, -1.67875, 0);
            // Add the first offset before actually spawning
            location.add(offset);
            fakeEntity = CompatibilityAPI.getEntityCompatibility().generateFakeEntity(location, type, data);
            fakeEntity.setEquipment(EquipmentSlot.HEAD, (ItemStack) data);
            fakeEntity.setInvisible(true);
            // Set the offset for new packets
            fakeEntity.setOffset(offset);
        } else {
            fakeEntity = CompatibilityAPI.getEntityCompatibility().generateFakeEntity(location, type, data);
        }
        projectile.spawnDisguise(fakeEntity);
    }
    // Handle explosions
    Explosion explosion = getConfigurations().getObject(projectile.getWeaponTitle() + ".Explosion", Explosion.class);
    if (explosion != null)
        explosion.handleExplosion(projectile.getShooter(), projectile, ExplosionTrigger.SPAWN);
    return projectile;
}
Also used : EntityType(org.bukkit.entity.EntityType) FakeEntity(me.deecaad.core.compatibility.entity.FakeEntity) CastData(me.deecaad.weaponmechanics.mechanics.CastData) Explosion(me.deecaad.weaponmechanics.weapon.explode.Explosion) Location(org.bukkit.Location)

Example 2 with Explosion

use of me.deecaad.weaponmechanics.weapon.explode.Explosion in project MechanicsMain by WeaponMechanics.

the class RayTraceResult method handleEntityHit.

private boolean handleEntityHit(WeaponProjectile projectile) {
    // Handle worldguard flags
    WorldGuardCompatibility worldGuard = CompatibilityAPI.getWorldGuardCompatibility();
    Location loc = hitLocation.clone().toLocation(projectile.getWorld());
    LivingEntity shooter = projectile.getShooter();
    if (!worldGuard.testFlag(loc, shooter instanceof Player ? (Player) shooter : null, "weapon-damage")) {
        // is cancelled check
        Object obj = worldGuard.getValue(loc, "weapon-damage-message");
        if (obj != null && !obj.toString().isEmpty() && shooter != null) {
            shooter.sendMessage(StringUtil.color(obj.toString()));
        }
        return true;
    }
    boolean backstab = livingEntity.getLocation().getDirection().dot(projectile.getMotion()) > 0.0;
    ProjectileHitEntityEvent hitEntityEvent = new ProjectileHitEntityEvent(projectile, livingEntity, hitLocation.clone(), hitPoint, backstab);
    Bukkit.getPluginManager().callEvent(hitEntityEvent);
    if (hitEntityEvent.isCancelled())
        return true;
    hitPoint = hitEntityEvent.getPoint();
    backstab = hitEntityEvent.isBackStab();
    if (!damageHandler.tryUse(livingEntity, projectile, getConfigurations().getDouble(projectile.getWeaponTitle() + ".Damage.Base_Damage"), hitPoint, backstab)) {
        // Damage was cancelled
        return true;
    }
    Explosion explosion = getConfigurations().getObject(projectile.getWeaponTitle() + ".Explosion", Explosion.class);
    if (explosion != null)
        explosion.handleExplosion(projectile.getShooter(), hitLocation.clone().toLocation(projectile.getWorld()), projectile, ExplosionTrigger.ENTITY);
    return false;
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) Explosion(me.deecaad.weaponmechanics.weapon.explode.Explosion) WorldGuardCompatibility(me.deecaad.core.compatibility.worldguard.WorldGuardCompatibility) ProjectileHitEntityEvent(me.deecaad.weaponmechanics.weapon.weaponevents.ProjectileHitEntityEvent) Location(org.bukkit.Location)

Example 3 with Explosion

use of me.deecaad.weaponmechanics.weapon.explode.Explosion in project MechanicsMain by WeaponMechanics.

the class RayTraceResult method handleBlockHit.

private boolean handleBlockHit(WeaponProjectile projectile) {
    ProjectileHitBlockEvent hitBlockEvent = new ProjectileHitBlockEvent(projectile, block, hitFace, hitLocation.clone());
    Bukkit.getPluginManager().callEvent(hitBlockEvent);
    if (hitBlockEvent.isCancelled())
        return true;
    Explosion explosion = getConfigurations().getObject(projectile.getWeaponTitle() + ".Explosion", Explosion.class);
    if (explosion != null)
        explosion.handleExplosion(projectile.getShooter(), hitLocation.clone().toLocation(projectile.getWorld()), projectile, ExplosionTrigger.BLOCK);
    return false;
}
Also used : Explosion(me.deecaad.weaponmechanics.weapon.explode.Explosion) ProjectileHitBlockEvent(me.deecaad.weaponmechanics.weapon.weaponevents.ProjectileHitBlockEvent)

Aggregations

Explosion (me.deecaad.weaponmechanics.weapon.explode.Explosion)3 Location (org.bukkit.Location)2 FakeEntity (me.deecaad.core.compatibility.entity.FakeEntity)1 WorldGuardCompatibility (me.deecaad.core.compatibility.worldguard.WorldGuardCompatibility)1 CastData (me.deecaad.weaponmechanics.mechanics.CastData)1 ProjectileHitBlockEvent (me.deecaad.weaponmechanics.weapon.weaponevents.ProjectileHitBlockEvent)1 ProjectileHitEntityEvent (me.deecaad.weaponmechanics.weapon.weaponevents.ProjectileHitEntityEvent)1 EntityType (org.bukkit.entity.EntityType)1 LivingEntity (org.bukkit.entity.LivingEntity)1 Player (org.bukkit.entity.Player)1