Getting a dropped item.

Discussion in 'Plugin Development' started by Cyber_Pigeon, Apr 4, 2014.

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

    Cyber_Pigeon

    Hello, today I was wondering if you could help me figure this out. I am creating a grenades class for my plugin, and I want to know how to make my ghast tear go completely straight (Because it goes diagonal right now) and get the ghast tear (Because mine is not working) on a projectile hit event.
    Thanks! Here is the code:
    Code:
    package Listeners;
     
    import java.util.List;
     
    import org.bukkit.Effect;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.Sound;
    import org.bukkit.entity.Arrow;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.Item;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.entity.ProjectileHitEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
     
    public class Grenades implements Listener {
       
       
        @EventHandler
        public void flash(PlayerInteractEvent e){
            Player p = e.getPlayer();
            if(e.getAction().equals(Action.RIGHT_CLICK_AIR) && p.getItemInHand().getType() == Material.GHAST_TEAR){
                Item item =  p.getWorld().dropItem(p.getLocation(),new ItemStack(Material.GHAST_TEAR));
                item.setVelocity(p.getLocation().getDirection().multiply(1.75D));
            }
        }
        @EventHandler
        public void onProHit(ProjectileHitEvent e){
            Entity entity = e.getEntity();
            if (entity instanceof Item)
            {
                try
                {
                        Location loc = entity.getLocation();
                       
                        entity.getWorld().createExplosion(loc.getX(), loc.getY(), loc.getZ(), 0);
                        entity.getWorld().playSound(entity.getLocation(), Sound.FIREWORK_LARGE_BLAST2, 1.0F, 1.0F);
                        entity.getWorld().playEffect(entity.getLocation(), Effect.SMOKE, 50);
                        entity.getWorld().playEffect(entity.getLocation(), Effect.SMOKE, 50);
                        entity.getWorld().playEffect(entity.getLocation(), Effect.SMOKE, 50);
                        entity.getWorld().playEffect(entity.getLocation(), Effect.SMOKE, 50);
                        entity.getWorld().playEffect(entity.getLocation(), Effect.SMOKE, 50);
                        List<Entity> nearby = entity.getNearbyEntities(5.0, 5.0, 5.0);
                        if(nearby instanceof Player){
                            ((Player) nearby).addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 100, 1));
                        }
                       
                    }
                catch (Exception e1) {}
                }
        }
        }
    I need help getting the ghast tear in the pro hit event, because "Item" is not working.
    I also need help making the ghast tear go straight, instead of diagonal. Thanks :)

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

    Maurdekye

    Cyber_Pigeon Oh gods, that repetition is killing me. Please add a for loop or something.

    Also, I'm not sure what you expect to catch with a ProjectileHitEvent; a ghast fireball? An arrow? This event is only called when an entity that has code specifically written to activate when they hit a surface/entity. A flying dropped item won't call that. Unless you meant ghast fireball, not ghast tear.
     
  3. Offline

    Cyber_Pigeon

    Thats not what I am asking. I want to know how I can get the dropped ghast tear in a pro hit event to make an explosion.
     
  4. Offline

    Maurdekye

    Cyber_Pigeon The ghast tear won't trigger a ProjectileHitEvent, because it's just an Item. I don't quite understand what you mean.
     
  5. Offline

    Cyber_Pigeon

    Maurdekye Oh, Ok. I just want to know how to get the ghast tear in that event so when the item is dropped it it run those events. :)
     
  6. Offline

    McPhillygin

    Cyber_Pigeon , Maybe you can make from a ghast tear an IDE with Proximity detector (Detects Players.)

    and for the ghast_Tear that goes diagonal,

    Code:java
    1.  
    2.  
    3. @EventHandler
    4. public void flash(PlayerInteractEvent e){
    5. Player p = e.getPlayer();
    6. if(e.getAction().equals(Action.RIGHT_CLICK_AIR) && p.getItemInHand().getType() == Material.GHAST_TEAR){
    7. //Instead of p.getLocation() to launch the Item, use p.getEyeLocation()
    8. Item item = p.getWorld().dropItem(p.getLocation(),new ItemStack(Material.GHAST_TEAR));
    9.  
    10. item.setVelocity(p.getLocation().getDirection().multiply(1.75D));
    11. }
    12.  
    13.  
    14. So then it should look like
    15. Item item = p.getWorld().dropItem(p.getEyeLocation(),new ItemStack(Material.GHAST_TEAR));
    16. }
    17.  
    18.  


    For proximity detectors, just use a radius and a player to terminate ;)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
Thread Status:
Not open for further replies.

Share This Page