Java Code Examples for org.bukkit.event.entity.EntityShootBowEvent#setProjectile()

The following examples show how to use org.bukkit.event.entity.EntityShootBowEvent#setProjectile() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Projectiles.java    From CardinalPGM with MIT License 5 votes vote down vote up
@EventHandler
public void onEntityShootBowEvent(EntityShootBowEvent event) {
    if (!projectile.equals(EntityType.ARROW) || velocityMod != 1.0) {
        Vector vector = event.getProjectile().getVelocity();
        event.setProjectile(GameHandler.getGameHandler().getMatchWorld().spawnEntity(event.getProjectile().getLocation(), projectile));
        ((Projectile) event.getProjectile()).setShooter(event.getEntity());
        event.getProjectile().setVelocity(vector.multiply(velocityMod));
        event.getProjectile().setMetadata("custom", new FixedMetadataValue(GameHandler.getGameHandler().getPlugin(), true));
    }
}
 
Example 2
Source File: ModifyBowProjectileMatchModule.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void changeBowProjectile(EntityShootBowEvent event) {
  Plugin plugin = PGM.get();
  Entity newProjectile;

  if (this.cls == Arrow.class && event.getProjectile() instanceof Arrow) {
    // Don't change the projectile if it's an Arrow and the custom entity type is also Arrow
    newProjectile = event.getProjectile();
  } else {
    // Replace the projectile
    Projectile oldEntity = (Projectile) event.getProjectile();
    if (Projectile.class.isAssignableFrom(this.cls)) {
      newProjectile = event.getEntity().launchProjectile((Class<? extends Projectile>) this.cls);
    } else {
      World world = event.getEntity().getWorld();
      newProjectile = world.spawn(oldEntity.getLocation(), this.cls);
    }
    event.setProjectile(newProjectile);

    // Copy some things from the old projectile
    newProjectile.setVelocity(oldEntity.getVelocity());
    newProjectile.setFallDistance(oldEntity.getFallDistance());
    newProjectile.setFireTicks(oldEntity.getFireTicks());

    if (newProjectile instanceof Projectile) {
      ((Projectile) newProjectile).setShooter(oldEntity.getShooter());
      ((Projectile) newProjectile).setBounce(oldEntity.doesBounce());
    }

    // Save some special properties of Arrows
    if (oldEntity instanceof Arrow) {
      Arrow arrow = (Arrow) oldEntity;
      newProjectile.setMetadata("critical", new FixedMetadataValue(plugin, arrow.isCritical()));
      newProjectile.setMetadata(
          "knockback", new FixedMetadataValue(plugin, arrow.getKnockbackStrength()));
      newProjectile.setMetadata(
          "damage", new FixedMetadataValue(plugin, arrow.spigot().getDamage()));
    }
  }

  // Tag the projectile as custom
  newProjectile.setMetadata("customProjectile", new FixedMetadataValue(plugin, true));

  match.callEvent(new EntityLaunchEvent(newProjectile, event.getEntity()));
}
 
Example 3
Source File: ModifyBowProjectileMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void changeBowProjectile(EntityShootBowEvent event) {
    Plugin plugin = this.getMatch().getPlugin();
    Entity newProjectile;

    if(this.projectile == Arrow.class && event.getProjectile() instanceof Arrow) {
        // Don't change the projectile if it's an Arrow and the custom entity type is also Arrow
        newProjectile = event.getProjectile();
    } else {
        // Replace the projectile
        World world = event.getEntity().getWorld();
        Projectile oldEntity = (Projectile) event.getProjectile();

        if(Projectile.class.isAssignableFrom(projectile)) {
            // Ender Pearls need to be soawned this way, otherwise they will hit the shooter sometimes
            newProjectile = event.getEntity().launchProjectile(projectile.asSubclass(Projectile.class), oldEntity.getVelocity());
        } else {
            newProjectile = world.spawn(oldEntity.getLocation(), projectile);
            newProjectile.setVelocity(oldEntity.getVelocity());
        }

        event.setProjectile(newProjectile);

        // Copy some things from the old projectile
        newProjectile.setFallDistance(oldEntity.getFallDistance());
        newProjectile.setFireTicks(oldEntity.getFireTicks());

        if(newProjectile instanceof Projectile) {
            ((Projectile) newProjectile).setShooter(oldEntity.getShooter());
            ((Projectile) newProjectile).setBounce(oldEntity.doesBounce());
        }

        // Save some special properties of Arrows
        if(oldEntity instanceof Arrow) {
            Arrow arrow = (Arrow) oldEntity;
            newProjectile.setMetadata("critical", new FixedMetadataValue(plugin, arrow.isCritical()));
            newProjectile.setMetadata("knockback", new FixedMetadataValue(plugin, arrow.getKnockbackStrength()));
            newProjectile.setMetadata("damage", new FixedMetadataValue(plugin, arrow.getDamage()));
        }
    }

    // Tag the projectile as custom
    newProjectile.setMetadata("customProjectile", new FixedMetadataValue(plugin, true));

    getMatch().callEvent(new EntityLaunchEvent(newProjectile, event.getEntity()));
}
 
Example 4
Source File: EnderBow.java    From NBTEditor with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onShootBow(EntityShootBowEvent event, DelayedPlayerDetails details) {
	Entity perl = event.getEntity().launchProjectile(EnderPearl.class);
	perl.setVelocity(event.getProjectile().getVelocity());
	event.setProjectile(perl);
}
 
Example 5
Source File: WitherBow.java    From NBTEditor with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onShootBow(EntityShootBowEvent event, DelayedPlayerDetails details) {
	Entity skull = event.getEntity().launchProjectile(WitherSkull.class);
	skull.setVelocity(event.getProjectile().getVelocity());
	event.setProjectile(skull);
}