Removing Arrows From Player body

Discussion in 'Spigot Plugin Development' started by Technerder, Jun 10, 2017.

  1. how can i remove all arows out of player bodies, or prevent them from being stuck in the player in the first place?
     
  2. ScarabCoder

    ScarabCoder Retired Resource Staff
    Retired

    Almost definitely not part of the Bukkit API. You'll probably have to do it with NMS.
     
  3. any idea how? what would be the best way i could do it. so it runs 24/7 any examples (i know im supposed to use runnables, but they confuse me)
     
  4. You could possibly do a entity damage entity event and see if it's an arrow get the damage it done cancel it and set the players health to their health minus the arrow damage but I don't know if this would get rid of the arrow
     
  5. Should be something like this ( 1.9 + ) :

    Code (Text):

    ((CraftPlayer)player).getHandle().getDataWatcher().set(new DataWatcherObject<>(10, DataWatcherRegistry.b),0);
     
    For older versions use this:

    Code (Text):

    ((CraftPlayer) player).getHandle().getDataWatcher().watch(9, (byte) 0);
     
     
    • Informative Informative x 1
  6. im sorry if this is wrong im really bad with packets! would i do this?


    Code (Text):
    public void ArowRemover(PlayerMoveEvnet event) {
           
            Player player = event.getPlayer();
           
            ((CraftPlayer) player).getHandle().getDataWatcher().watch(9, (byte) 0);
           
        }
     
     
  7. Oh my gosh :D don't do that in the move event ( the event will be executed like on every single location change ( even if its the head turning around )
    I would recommend using the EntityDamageByEntityEvent as it would automatically be executed by beeing hit from an arrow ( just check at that event if the damager is an arrow )
    Also what i posted is not a packet xD
     
  8. haha, i use playermoveevent when i want something to happen repeatably. any way how would i make it work? it keeps saying "craft player can not be resolved" any help?
     
  9. have you imported the correct class?
     
  10. Code (Text):
    package technerder.kurion.kurionduels;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;

    public class Main extends JavaPlugin implements Listener {

        public boolean onCommand(CommandSender sender, Command command, String alias, String[] args) {
            Player player = (Player) sender;
            if (alias.equalsIgnoreCase("duel")) {
                if (args.length == 0) {
                    player.sendMessage(ChatColor.RED + "Usage: /duel <player>");
                } else {
                    Player target = Bukkit.getPlayerExact(args[0]);
                    if (target == null) {
                        player.sendMessage(ChatColor.RED + "Player" + args[0] + " is not online!");
                    } else {

                        Location ArenaSpawn1 = new Location(Bukkit.getWorld("Spawn"), -5, 4, -5);
                        Location ArenaSpawn2 = new Location(Bukkit.getWorld("Spawn"), 5, 4, 5);

                        // Teleportation and Messages

                        player.teleport(ArenaSpawn1);
                        player.sendMessage(ChatColor.RED + "Warning:" + ChatColor.DARK_AQUA + " Skybasing will result in a 1 week ban!");
                        player.sendMessage(ChatColor.BLUE + "Now in match against " + target.getName() + " With 1400 ELO in kit BuildUHC");

                        target.teleport(ArenaSpawn2);
                        target.sendMessage(ChatColor.RED + "Warning:" + ChatColor.DARK_AQUA + " Skybasing will result in a 1 week ban!");
                        target.sendMessage(ChatColor.BLUE + "Now in match against " + player.getName() + " With 1400 ELO in kit BuildUHC!");

                        // Giving Kit items
                       
                        player.getInventory().clear();
                        target.getInventory().clear();

                        player.getInventory().addItem(new ItemStack(Material.DIAMOND_SWORD));
                        player.getInventory().setHelmet(new ItemStack(Material.IRON_HELMET));
                        player.getInventory().setChestplate(new ItemStack(Material.IRON_CHESTPLATE));
                        player.getInventory().setLeggings(new ItemStack(Material.IRON_LEGGINGS));
                        player.getInventory().setBoots(new ItemStack(Material.IRON_BOOTS));

                        target.getInventory().addItem(new ItemStack(Material.DIAMOND_SWORD));
                        target.getInventory().setHelmet(new ItemStack(Material.IRON_HELMET));
                        target.getInventory().setChestplate(new ItemStack(Material.IRON_CHESTPLATE));
                        target.getInventory().setLeggings(new ItemStack(Material.IRON_LEGGINGS));
                        target.getInventory().setBoots(new ItemStack(Material.IRON_BOOTS));

                    }
                }
            }
            return true;
        }

        public void ArowRemover(PlayerMoveEvent event) {
           
            Player player = event.getPlayer();
           
            ((CraftPlayer) player).getHandle().getDataWatcher().watch(9, (byte) 0);
           
        }
       
    }
     
  11. import the following class:
    org.bukkit.craftbukkit.v1_8???.entity.CraftPlayer

    change "v1_8???" with your nms version

    Also note to register your event & add the @EventHandler.
     
  12. so for 1.7 it would be

    import org.bukkit.craftbukkit.1.7.entity.CraftPlayer;
     
  13. no, it would be something like v1_7_R1
     
  14. getting an error on org.bukkit.craftbukkit
     
  15. what does it say when you hover over it?
     
  16. import can not be resolved
     
  17. which server version do you use as dependency?
    ( i don't mean "1.7" or something, i mean like "v1_7_R4" )
     
  18. You need to use craftbukkit as a dependency to utilize craftbukkit code.
     
  19. already have, using 1.11 API.
     
  20. You should have an import something like this
    import org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer;

    if you use IntelliJ you can write
    import org.bukkit.craftbukkit.
    and then do CTRL + SPACE and it will suggest the right package name for your version.

    Also you need to use the same version for both Craftbukkit and bukkit can't have 1.7 bukkit, and 1.11 craftbukkit
     
    • Agree Agree x 1