Making an enderpearl not work

Discussion in 'Plugin Development' started by Divinity Realms, Feb 4, 2015.

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

    Divinity Realms

    Im having trouble finding the event like PlayerEggThrowEvent except with an enderpearl. I don't want players to be able to throw it because it activates/deactivates players. So does anyone know how I could prevent that?
    Thanks

    ~Extended
     
  2. Offline

    adam753

    I think PlayerInteractEvent would do the trick. Remember to check for both RIGHT_CLICK_AIR and RIGHT_CLICK_BLOCK.
     
  3. Offline

    Konato_K

    @Divinity Realms I'm not sure what you mean with activate/deactivate players, but you can listen to PlayerTeleportEvent and cancel it if the reason it's an Ender Pearl
     
  4. Offline

    _Cookie_

    Just use
    Code:
    @EventHandler
    public void usePearl(PlayerInteractEvent event){
        Player p = (Player) event.getPlayer();
        if(p.getItemInHand().getType() == Material.ENDER_PEARL){
              if(event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_AIR){
                event.setCancelled(true);
              }
          }
    }
    Something like that shall do the trick :)
     
  5. Offline

    Konato_K

    @_Cookie_ As far I know, getItemInHand can return null

    Anyway, it would be better to use PlayerInteractEvent#getMaterial
     
  6. Offline

    Divinity Realms

    @_Cookie_ Nope you can still see it fly and it still teleports you :/
     
  7. Offline

    Konato_K

  8. Offline

    ChipDev

    Remove all ender pearls owned by the thrower nearby.
     
  9. Offline

    Konato_K

  10. Offline

    Divinity Realms

    Thanks but how can i check what type of entity it is?
     
  11. Offline

    Konato_K

  12. Offline

    Divinity Realms

    I know that i can do that but how can i see if it equals a certain entity
     
  13. Offline

    Konato_K

    @Divinity Realms Object#equals?

    I'm not sure what you're asking, if you want to check if it's an enderpearl just use getType or instanceof, if you're trying to use it with a custom enderpearl then the best would be to attach metadata to the entity.
     
  14. Offline

    Divinity Realms

    No just a normal entity im doing
    event.getEntityType();

    if(EntityType.ENDER_PEARL != null) Please help
    @Konato_K
     
    Last edited: Feb 4, 2015
  15. Offline

    teej107

    Are you even registering your events?
    EntityType is an enum so of coarse if will never be null when you reference it! That if statement will always be true
     
    GrandmaJam likes this.
  16. Offline

    GrandmaJam

    Hope this helps!
    Code:
    @EventHandler
        public void onPlayerTeleport(PlayerTeleportEvent e) {
            if(e.getCause().equals(TeleportCause.ENDER_PEARL)) {
                e.setCancelled(true);
            }
        }
     
  17. Offline

    Divinity Realms

    @GrandmaJam Works like a charm. Yet it still leaves your inevntory and you can still see it fly out.. Please help!

    @teej107 I know that, that was wrong Im just showing you kind of an example xD I really put it there for no reason i guess. And yes.. Im registering my events lol
     
    Last edited by a moderator: Feb 4, 2015
  18. Offline

    sirrus86

    To stop it from leaving the inventory you'll want to listen for the PlayerInteractEvent, if the item was an ender pearl and they right-clicked, give them an ender pearl (don't think cancelling will prevent the item from being lost).

    To remove the thrown pearl, listen to the ProjectileLaunchEvent, see if it's an ender pearl and remove it.
     
    Divinity Realms likes this.
  19. Offline

    Divinity Realms

Thread Status:
Not open for further replies.

Share This Page