Search in sources :

Example 1 with ShootingItemData

use of com.skelril.skree.service.internal.projectilewatcher.shooter.ShootingItemData in project Skree by Skelril.

the class ProjectileWatcherServiceImpl method onProjectileLaunch.

@Listener
public void onProjectileLaunch(SpawnEntityEvent event) {
    for (Entity entity : event.getEntities()) {
        if (!(entity instanceof Projectile)) {
            continue;
        }
        ProjectileSource shooter = ((Projectile) entity).getShooter();
        if (shooter instanceof ArmorEquipable) {
            entity.offer(new ShootingItemData((((ArmorEquipable) shooter).getItemInHand(HandTypes.MAIN_HAND).map(ItemStack::createSnapshot).orElse(null))));
        }
        track((Projectile) entity, event.getCause());
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) ArmorEquipable(org.spongepowered.api.entity.ArmorEquipable) ProjectileSource(org.spongepowered.api.entity.projectile.source.ProjectileSource) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ShootingItemData(com.skelril.skree.service.internal.projectilewatcher.shooter.ShootingItemData) Projectile(org.spongepowered.api.entity.projectile.Projectile) Listener(org.spongepowered.api.event.Listener)

Aggregations

ShootingItemData (com.skelril.skree.service.internal.projectilewatcher.shooter.ShootingItemData)1 ArmorEquipable (org.spongepowered.api.entity.ArmorEquipable)1 Entity (org.spongepowered.api.entity.Entity)1 Projectile (org.spongepowered.api.entity.projectile.Projectile)1 ProjectileSource (org.spongepowered.api.entity.projectile.source.ProjectileSource)1 Listener (org.spongepowered.api.event.Listener)1 ItemStack (org.spongepowered.api.item.inventory.ItemStack)1