Throw item, stop player form picking it up, and despawn it

Discussion in 'Plugin Development' started by ohtwo, Feb 2, 2013.

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

    ohtwo

    How would I go about allowing a player to throw an item, such as an ender eye (or any item that can be thrown in a similar manner), stop players from picking up that specific item, and then despawn it after a specified amount of time?

    That was the longest question ever. I know how to use timers and such in Bukkit, so I dont really need to know how to use that portion.

    Ah I think I figured out how to despawn an item now...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  2. Offline

    chasechocolate

    For stopping pickup, I would save the item's UUID to a list and then check if the list contains the picked up item's UUID, if so, cancel the event.
     
  3. Offline

    ohtwo

    Ah. So I'll need to create a listener, PlayerPickupEvent (dunno if thats the exact event), and then create an if statement that checks if the items UDID is in the ArrayList, and event.cancel()?

    Also, how do I cancel an enderpearl's teleport? I think thats one of the other main things I need to know.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  4. Offline

    skore87

    Simplest is to check the PlayerInteractEvent and cancel the event if they are using the right mouse button and the ender pearl is selected.
     
  5. Offline

    Miner_Fil

    Code:java
    1.  
    2. @EventHandler
    3. public void onPlayerInteract(PlayerInteractEvent e){
    4. Player p = e.getPlayer();
    5. Material clickedItem = e.getMaterial();
    6. if(clickedItem == Material.ENDER_PEARL) {
    7. if(!p.hasPermission("test.test"){
    8. e.setCancelled(true);
    9. p.sendMessage(ChatColor.DARK_RED + "You do not have Permission to teleport with Ender Pearls :)");
    10. } else if(p.hasPermission("test.test"){
    11. e.setCancelled(false);
    12. }
    13. }
    14. }
    15.  


    That works for me :)

    It basically cancels the teleportation and gives the item back to you

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  6. Offline

    ohtwo

    Thanks! But I didn't actually want to fully cancel throwing the ender pearl. I just want to cancel the teleporting portion of it. I can't quite find anything that allows that...
     
  7. Offline

    Miner_Fil

    I dont really think thats Possible :p
     
  8. Offline

    ohtwo

    danggg. Is there any way I can throw an item and make it mimic the "throwing" qualities of an enderpearl?
     
  9. Offline

    macguy8

    You can listen for PlayerTeleportEvent, and check the cause, and cancel it if it's from an ender pearl
     
  10. Offline

    chasechocolate

    Yes it is :p. ProjectileHitEvent, check if the entity is an ender pearl, check if the shooter is a player, check if the player has a specific permission, if not, cancel the event. (Kind of hard to write code on an iPad...)
     
  11. Offline

    Miner_Fil

  12. Offline

    ohtwo

    Thanks so much guys, I'll try it!

    There doesn't appear to be a way to cancel the event. My parameter is (ProjectileHitEvent event), and then I type "event." (expecting to see a cancel method, but none appears). I'll take a look at the JavaDoc and see if there is anything there.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  13. Offline

    raGan.

    You can't cancel projectile hit event. Just cancel teleport event.

    if(teleport cause == TeleportCause.ENDER_PEARL)
     
    ohtwo likes this.
  14. Offline

    ohtwo

    Will try it. Thank you.
     
Thread Status:
Not open for further replies.

Share This Page