Arrows in the body (after death)

Discussion in 'Plugin Development' started by re4ly, Jul 31, 2013.

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

    re4ly

    [​IMG]

    How can i remove these arrows (body & area)?

    thanks, re4ly
     
  2. Offline

    foodyling

    This *might* help, haven't tested, you need to import craftbukkit though.

    Code:
    ((CraftPlayer) event.getEntity()).getHandle().getDataWatcher().watch(9, (byte)0);
     
  3. Offline

    EcMiner

    what you could do is with the event, EntityDamageByEntityEvent, you could check if the damager is a projectile, then check if the projectile is an arrow, and then do projectile.remove()
     
  4. Offline

    xxMOxMOxx

    In order to remove them after death you would need to log the arrows upon impact and then remove them all after a PlayerDeathEvent
     
  5. Offline

    EcMiner

  6. Offline

    re4ly

    xxMOxMOxx it is not possible to remove all projectile from a body without logging?
     
  7. Offline

    xxMOxMOxx

    I don't know, I was just saying if you want to do EcMiner's idea you need to log them, not remove the immediately.
     
  8. Offline

    foodyling

    Confirmed to work for me, it removes the arrows on respawn (if you use a death event it removes the arrows as you die, which is probably not wanted). It uses Reflection so you don't have to import CraftBukkit.
    Code:
    public class ArrowRemover implements Listener {
        private static final String MC_VERSION = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
        private static final Class<?> craftPlayer = forClassName("org.bukkit.craftbukkit.%MC_VERSION%.entity.CraftPlayer"),
                                      packet = forClassName("net.minecraft.server.%MC_VERSION%.Packet205ClientCommand");
       
        @EventHandler
        public void onPlayerRespawn(PlayerRespawnEvent event) {
            try {
                Object handle = craftPlayer.getMethod("getHandle").invoke(craftPlayer.cast(event.getPlayer())),
                  dataWatcher = handle.getClass().getMethod("getDataWatcher").invoke(handle);
                dataWatcher.getClass().getMethod("watch", int.class, Object.class).invoke(dataWatcher, 9, (byte) 0);
            } catch (Throwable error) {
                error.printStackTrace();
            }
        }
       
        public static Class<?> forClassName(String name) {
            try {
                return Class.forName(name.replace("%MC_VERSION%", MC_VERSION));
            } catch (Throwable error) {
                return null;
            }
        }
    }
     
    xTrollxDudex likes this.
Thread Status:
Not open for further replies.

Share This Page