Get Fishing Hook location?

Discussion in 'Plugin Development' started by Connor2weirdness, Feb 20, 2014.

Thread Status:
Not open for further replies.
  1. Hello everyone! I am trying to create a nun chucks sort of plugin where you can throw a fishing rod and create an explosion in that location. However, the code that I found buried among other threads does unfortunately not work. Thank you.

    Code:
    package exgrapple.Connor2weirdness;
     
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerFishEvent;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class exgrapplemain extends JavaPlugin implements Listener {
     
        @EventHandler(priority = EventPriority.HIGH)
        public void onPlayerFishingEvent(PlayerFishEvent event) {
            Player p = event.getPlayer();
            Material item = p.getItemInHand().getType();
            if (item == Material.FISHING_ROD) {
     
                java.util.List<Entity> nearby = p.getNearbyEntities(50, 50, 50);
                Entity hook = null;
                for (Entity e : nearby) {
     
                    if (e.getType() == EntityType.FISHING_HOOK) {
                        hook = e;
                        event.getPlayer().teleport(hook.getLocation());
                    }
                }
            }
        }
    }
     
  2. Offline

    Shayana

    Did you register the event ? I don't see an onEnable on your class...
     
  3. Just added that (I forgot to put it in :p) and it still doesn't work. Thanks.

    EDIT: Works now after correcting minor mistake :)
     
Thread Status:
Not open for further replies.

Share This Page