Remove/prevent arrows stuck in a player

Discussion in 'Plugin Development' started by St3venAU, Apr 12, 2013.

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

    St3venAU

    Does anyone know of a way to remove the arrows stuck in a player (the ones that get stuck in their body after they have been shot).

    These are the things I have tried without success:

    - Player.getNearbyEntities(3,3,3) did not return any entities when the player had arrows stuck in him

    - Tried having EntityDamageByEntityEvent check if entity instanceof Player and damager instanceof Arrow and call .remove() on the arrow did nothing (arrow still stuck in player)

    - Cancelling the EntityDamageByEntityEvent does prevent the arrow sticking in the player but it also cancels the damage and the knockback of the arrow

    Does anyone have any ideas, or know how the information about the the arrows in a player is stored and/or transmitted to the client? I thought it might be a client side thing so I tested it by having 1 player shoot a 2nd and then having a 3rd player join the server. The 3rd player could see the arrow stuck in the 2nd player, so that info must have been sent to the client by the server.

    Any thoughts would be appreciated.
     
  2. Offline

    orange451

    I would also like to know how to do this.
     
  3. Offline

    tenten8401

    I do i do.... Have it refresh the player entity... Then it will remove the arrows and your guy will be clean...
     
  4. Offline

    St3venAU

    Do you know how this can be done?
     
  5. Offline

    tenten8401

    Just like TAGApi Does it, Destroy the player entity and put it back up without killing the player,... And the best part about tagapi is that its open source and you are allowed to look how they do it...
     
  6. Offline

    St3venAU

    I've poured through the source for TAGApi and as far as I can tell the "refreshing of the player entity" just does Player.hidePlayer and then Player.showPlayer. I have tried this and the arrows come back as soon as the player comes back.

    I assume this can also be done with a destroy entity packet and a spawn named entity packet, but I'm unsure of the correct way to do so.
     
  7. Offline

    tenten8401

    Well... hold on... Why dont you get some code to killall entities named Arrow so it will remove them.
     
  8. Offline

    St3venAU

    Doing so will remove all arrows on the ground or in the air but it does not remove the arrows in players. It seems that once they are stuck in the player they are no longer entities.
     
  9. Offline

    tenten8401

    [diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond]
    Just got an idea...
    You could "hide" The arrows from a player by just cancelling the packet that the arrows are there.
    That way... they are there... but noone can see them! :)

    [diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond][diamond]
     
  10. Offline

    St3venAU

    Sounds good in theory, but I cant see in any of the packet documentation anything about arrows stuck in a player so I would have no idea which packets to cancel. Also it's unlikely that it's a single packet dedicated to arrows stuck in a player so cancelling it may have other unwanted side-effects (I would suspect something like making not just the arrows invisible but the player too).
     
  11. Offline

    Jake0oo0

    Talked to EvilSeph about this on IRC, it's not possible to remove arrows on the ground - It's something on Mojang's end.
     
  12. Offline

    Cybermaxke

    This should set the arrows in the players body. ;)
    Code:
    public int getArrowsInBody(Player player) {
        return ((CraftPlayer) player).getHandle().getDataWatcher().getByte(10);
    }
    Code:
    public void setArrowsInBody(Player player, byte amount) {
        ((CraftPlayer) player).getHandle().getDataWatcher().watch(10, new Byte(amount));
    }
     
  13. Offline

    St3venAU

    1.6 broke this. Here's the change for 1.6.x to remove all arrows from a player in case anyone needs it:

    ((CraftPlayer) player).getHandle().getDataWatcher().watch(9, (byte)0);
     
    metalhedd likes this.
  14. Offline

    metalhedd

    Out of curiosity, is there any documentation on all the possible datawatcher values? whenever there's some behaviour that I can't explain, it usually involves the DataWatcher, would be nice to read up on everything that its responsible for,
     
  15. Offline

    Codex Arcanum

    I know this is an old thread, but the easy way to do it would seem to me to be to cancel the EntityDamageByEntityEvent, and then use p.damage(evt.getDamage()).
     
  16. Offline

    St3venAU

    metalhedd: I don't know of any documentation. I use a combination of looking through the craftbukkit source code and trial and error.

    Codex Arcnum: That was a solution that I thought of and rejected because you would not get the knockback effect from the arrow and if the bow had power or punch enchants you wouldn't get the effects from them either.
     
  17. Offline

    Grave

    Hey, sorry to bother you. I get the error CraftPlayer cannot be resolved to a type. Is there a way to fix this?
     
  18. Offline

    xTrollxDudex

  19. Offline

    Grave

  20. Offline

    xTrollxDudex

  21. Offline

    zzienzz

    Sorry to dig up an old thread.
    But the import cant be resolved for:
    import org.bukkit.craftbukkit.entity.CraftPlayer;

    Thus meaning I can't use the method to remove arrows as described above.
    I'm using 1.6.4 and have bukkit, then craftbukkit in libraries.
     
  22. Offline

    St3venAU


    Assuming you are using the latest recommended build of 1.6.4 craftbukkit then it will be:
    import org.bukkit.craftbukkit.v1_6_R3.entity.CraftPlayer;
     
    zzienzz likes this.
  23. Offline

    zzienzz

Thread Status:
Not open for further replies.

Share This Page