Throwing an enderpearl

Discussion in 'Plugin Development' started by ThatGuyWhoDied13, Nov 11, 2013.

Thread Status:
Not open for further replies.
  1. Hey Guys, I was wondering how to throw an enderpearl when I right click on a diamond it shoots an enderpearl, but I can't figure out how to.
    any help??
     
  2. Offline

    NinjaWAffles

    Listen for an onPlayerInteract event. Check if he right clicked, then if he's holding a diamond, then use the 'LivingEntity.launchProjectile' to launch an enderpearl.

    Something like this should do:
    Code:Java
    1. @EventHandler
    2. public void onPlayerInteract(PlayerInteractEvent e)
    3. {
    4. Player player = e.getPlayer();
    5.  
    6. if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK)
    7. {
    8. if(player.getItemInHand().getType().equals(Material.DIAMOND))
    9. {
    10. player.launchProjectile(EnderPearl.class);
    11. }
    12. }
    13. }
     
    GrandmaJam likes this.
  3. NinjaWAffles Thanks. also how would I make it so when the enderpearl hits the ground it teleports the player to a certain location
     
  4. Offline

    NinjaWAffles

    Whenever the enderpearl hits the ground, it'll teleport the player automatically. No need for extra code.
     
  5. sorry Ii messed up my words. how would I make it so when the player's enderpearl hits something it doesnt tp them and if it hits another player it tps them back to a location

    I'm working on a minigame
     
  6. Offline

    Nibbur

    probably with Eventhandler when a enderpearl hits the ground: event.setCancelled(true);
     
  7. Nibbur thanks that works. now teleporting the other player back to the spawnpoint
     
  8. Offline

    Nibbur

    so you mean when the pearl hits a player, it should teleport the hit player to the spawnpoint?
     
  9. Nibbur I'm making a paintball type plugin and I want it so when a player is hit by an enderpearl(paintball) they will get teleported back to that teams spawn point and the other team will gain a point
     
  10. Offline

    NinjaWAffles

    To stop players being teleported by ender pearls, listen in on the PlayerTeleportEvent.
    Code:Java
    1. public void onPlayerTeleport(PlayerTeleportEvent e)
    2. {
    3. if(e.getCause().equals(TeleportCause.ENDER_PEARL))
    4. {
    5. e.setCancelled(true);
    6. }
    7. }


    In order to see if a player got hit by an enderpearl, you'll listen in on EntityDamageByEntityEvent, and make sure the entity is a player and the damager is an enderpearl.
    Code:Java
    1. public void onEntityDamageByEntity(EntityDamageByEntityEvent e)
    2. {
    3. if(e.getEntity() instanceof Player && e.getDamager() instanceof EnderPearl)
    4. {
    5. //Do WHATEVER
    6. }
    7. }
     
  11. NinjaWAffles thanks, this works. Would the snowball be
    Code:java
    1. if(e.getEntity() instanceof Player && e.getDamager() instanceof SnowBall)
     
  12. Offline

    NinjaWAffles

    Indeed, it would.
     
  13. Offline

    xTrollxDudex

    KevyPorter
    Isn't the B in SnowBall supposed to be lowercase tho?
     
  14. Offline

    bars96

    How to make mob throw enderpearl to player? I create explode when enderpearl hit ground but how to make mob explode player by enderpearl? Thx.
     
Thread Status:
Not open for further replies.

Share This Page