How to shoot an egg on command

Discussion in 'Plugin Development' started by coolmonkeyguy, Mar 28, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    coolmonkeyguy

    I am trying to shoot an egg on command. I know how to shoot a snowball but i don't know how to shoot an egg. And also how would I spawn exp orbs or xp bottle at the position of the egg when it hits the ground.

    thanks!
     
  2. Offline

    MrInspector

    I believe it's something like this.
    Code:java
    1. player.throwEgg();
    (I'm not sure if it's shoot or throw egg)
     
  3. MrInspector coolmonkeyguy That or player.launchProjectile(Egg.class)

    As for the xp thing, you need to look into projectilehitevent and then spawn some xp there
     
  4. Offline

    Opacification

  5. Offline

    MrInspector

  6. Offline

    Opacification

    MrInspector, he can use it.

    Just thinking that using something that isn't deprecated would be better.

    If that's his only option, than he can go for it.
     
  7. Offline

    MrCodeMiner

    I did something similar here, hope this helps you out:

    Code:java
    1. @EventHandler
    2. public void onPlayerInteract(PlayerInteractEvent e){
    3. if (!(e.getAction() == Action.RIGHT_CLICK_BLOCK)) return;
    4. if (!(e.getItem().getType() == Material.BLAZE_ROD)) return;
    5. e.getPlayer().launchProjectile(Snowball.class);
    6. }
    7.  
    8. @EventHandler
    9. public void onProjectileHit(ProjectileHitEvent e){
    10. Projectile p = e.getEntity();
    11. if (!(p instanceof Snowball)) return;
    12. Snowball s = (Snowball) p;
    13. s.getWorld().createExplosion(s.getLocation(), 0F);
    14. for (Entity en : s.getNearbyEntities(10, 10, 10)){
    15. if (en instanceof Player){
    16. Player pl = (Player) en;
    17. if (!(pl == e.getEntity().getShooter())) pl.addPotionEffect(new PotionEffect(PotionEffectType.POISON, 100, 0));
    18. }
    19. }}
     
  8. Offline

    coolmonkeyguy

    thanks!
     
  9. Offline

    MrCodeMiner

  10. Offline

    Garris0n

    It works fine, it's just better to use the launchProjectile() method. You may as well, throwEgg() just calls it anyway.
     
    MrInspector likes this.
Thread Status:
Not open for further replies.

Share This Page