How to make dropped items hurt players on contact?

Discussion in 'Plugin Development' started by redside100, May 17, 2014.

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

    redside100

    Hello there, I am currently making a brick throwing plugin. I have the "throwing" part operational, but I can't seem to find a way for the thrown item to hurt a player on contact. Is there anyway?

    Here is my code:
    Code:
        @EventHandler
        public void onPlayerBlock(PlayerInteractEvent event)
        {
            Player p = event.getPlayer();
            if (p.getItemInHand().getTypeId() == 336)
            {
                if (event.getAction() == Action.RIGHT_CLICK_AIR)
                {
                    ItemStack brick = new ItemStack(Material.CLAY_BRICK, 1, (short) 0);
                    p.getInventory().removeItem(brick);
                    Vector direction = p.getEyeLocation().getDirection();
                    p.getWorld().dropItemNaturally(event.getPlayer().getLocation(), brick).setVelocity(direction);
                   
                }
                if (event.getAction() == Action.RIGHT_CLICK_BLOCK)
                {
                    ItemStack brick = new ItemStack(Material.CLAY_BRICK, 1, (short) 0);
                    p.getInventory().removeItem(brick);
                    Vector direction = p.getEyeLocation().getDirection();
                    p.getWorld().dropItemNaturally(event.getPlayer().getLocation(), brick).setVelocity(direction);
                }
            }
     
  2. Offline

    mickedplay

    redside100 Try to use PlayerPickupItemEvent

    redside100 Ouh, and use ((e.getAction() == Action.RIGHT_CLICK_AIR) || (e.getAction() == Action.RIGHT_CLICK_BLOCK)) instead of two if-statements

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  3. Offline

    redside100

    The thing about Player PickupEvent is that the item has to land near them. I want it so it can go at full speed, but when it touches the player the player gets hurt.
     
  4. Offline

    Code0

    you can setup a loop or something (or a timer) and test for nearby entities
     
Thread Status:
Not open for further replies.

Share This Page