ProjectileHitEvent doesn't work for fish.

Discussion in 'Plugin Development' started by evanejk, May 9, 2012.

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

    evanejk

    I tested it and it works for snowballs, arrows, ender perls, etc; but it seems to not work for the fishing rod. This is a disappointing because I wanted to make a grappling hook out of it :D

    This is my test code. When I cast a line or catch a fish nothing happens.
    Code:
    @EventHandler(priority=EventPriority.NORMAL)
    public void onProjectileHit(ProjectileHitEvent e){
        System.out.println("Projectile hit.");
    }
     
  2. Offline

    TnT

    Moved to plugin development.

    If you mean to submit a bug, ensure this is an issue by having someone look over your code. If it can be confirmed, submit a ticket to leaky.bukkit.org.
     
    evanejk likes this.
  3. Offline

    Father Of Time

    Have you tried the fishing event?

    http://jd.bukkit.org/doxygen/d2/d98...ent_1_1player_1_1PlayerFishEvent-members.html

    It doesn't contain a "getBobber" variable, but during the events trigger you can do a "getneabyentities" from the player object and look for a bobber within X distance of you.

    Needless to say this isn't ideal as you may find neaby bobbers that you didn't cast yourself, but it's a starting point.

    Hope this helps!
     
    evanejk likes this.
  4. Offline

    evanejk

    Perfect! Thanks so much I'll just make it so if the bobber is in water it is ignored, and I'll delete the bobber right after it adds the vector to the player. Somebody casting their line closer to you during the 2ish second pause to wait for the bobber to land is fairly unlikely. They would just then be sent to your line instead.
     
  5. Offline

    Father Of Time

    Bingo, you got it! I'm sure it will take a little playing around with, but you'll get it. :D

    Oh, p.s., you can use the getState() function within the fishing event to determine whether or not the line was cast on land:

    This should make figuring out whether they cast on land or not a heck of a lot easier.

    Hope this helps, good luck with the project!
     
  6. Offline

    evanejk

    Code:
    e.getPlayer().getNearbyEntities(40, 40, 40).IndexOf("CraftFish");
    and
    Code:
    e.getPlayer().getNearbyEntities(40, 40, 40).IndexOf("Fish");
    Both are returning -1 every time even when I see this

    Code:
    [INFO] [CraftSkeleton, CraftPig, CraftPig, CraftPig, CraftPig, CraftChicken, CraftSkeleton, CraftZombie, CraftChicken, CraftCreeper, CraftPig, CraftPig, CraftPig, CraftPig, CraftPig, CraftZombie, CraftZombie, CraftSkeleton, CraftSpider, CraftPig, CraftSkeleton, CraftItem, CraftItem, CraftItem, CraftItem,
    CraftFish,
    CraftPig, CraftPig, CraftPig, CraftPig, CraftPig, CraftPig, CraftSpider, CraftCreeper]
    from

    Code:
    System.out.println(e.getPlayer().getNearbyEntities(40, 40, 40));
    Edit: The getNearbyEntities(x,y,z); function's return needs to be converted into an array and then checked in a for loop for "CraftFish"
     
  7. Offline

    KaiBB

    If you somehow get this to work, of course, the grappling hook will have gravity to it. But if you don't mind ridding your grappling hook of any sort of physics, you can get the block the player is looking at onPlayerInteract, if he is holding a fishing rod, and tp said player to that block.
     
  8. Offline

    evanejk

    The game engine takes care of the gravity for me. I used vectors.

    I ended up converting the <List>Entity into an array and then I used a for loop to find the right element.

    This is my final code if anybody is interested.
    Code:
    @EventHandler(priority=EventPriority.NORMAL)
    public void onPlayerFish(PlayerFishEvent e){
    //System.out.println("Hook works.");
    //System.out.println(e.getPlayer().getNearbyEntities(40, 40, 40));
    List<Entity> slotsOriginal = e.getPlayer().getNearbyEntities(40, 40, 40); //definatly save this to make it faster
    //System.out.println("Making it array.");
    Object[] slotsArray = slotsOriginal.toArray();
    //The death if stays -1
    int slot=-1;
    //System.out.println("Starting for loop.");
    for(int i=slotsArray.length-1;i>=0;i--){
    //System.out.println("On slot: "+i+" Data: "+slotsArray[i].toString());
    if(slotsArray[i].toString().equals("CraftFish")){
    slot=i;
    }
    }
    if(slot==-1){
    return;
    }
    boolean opversion = false;//levelvar OP power
    if(opversion){
    Location bobberLoc = slotsOriginal.get(slot).getLocation();
    Location playerLoc = e.getPlayer().getLocation();
    e.getPlayer().setVelocity(new Vector(bobberLoc.getX()-playerLoc.getX(),bobberLoc.getY()-playerLoc.getY()-1/* I think it needs -1 because the rod is where your dick is instead of your eyes like it shows you.  Fucking notch.*/,bobberLoc.getZ()-playerLoc.getZ()));
    return;
    }else if(  (slotsOriginal.get(slot).getLocation().getBlock().getTypeId()==0
    && (slotsOriginal.get(slot).getLocation().getBlock().getRelative(0, -1, 0).getTypeId()==0)
    && (slotsOriginal.get(slot).getLocation().getBlock().getRelative(-1, 0, 0).getTypeId()==0)
    && (slotsOriginal.get(slot).getLocation().getBlock().getRelative(1, 0, 0).getTypeId()==0)
    && (slotsOriginal.get(slot).getLocation().getBlock().getRelative(0, 0, -1).getTypeId()==0)
    && (slotsOriginal.get(slot).getLocation().getBlock().getRelative(0, 0, 1)).getTypeId()==0)
    ){
    //System.out.println("Using slot: "+slot);
    //System.out.println("Starting player movement.");
    Location bobberLoc = slotsOriginal.get(slot).getLocation();
    Location playerLoc = e.getPlayer().getLocation();
    e.getPlayer().setVelocity(new Vector(bobberLoc.getX()-playerLoc.getX(),bobberLoc.getY()-playerLoc.getY()-1/* I think it needs -1 because the rod is where your dick is instead of your eyes like it shows you.  Fucking notch.*/,bobberLoc.getZ()-playerLoc.getZ()));
    }
    }
    
    The OPVersion is where you don't need it to be touching a block. You can use it to sore through the air and landing in water is your only hope if you have fall damage.

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

Share This Page