1.16.1 How to make a egg that hits a player kill them!

Discussion in 'Spigot Plugin Development' started by MystikDraggon, Aug 2, 2020 at 6:58 PM.

  1. I would like to detect if a egg hits a player it kills them right now this is my code:
    Bukkit.getScheduler().scheduleAsyncRepeatingTask(this, new Runnable() {
    Player player = (I dont know how to get the player)
    public void run() {
    if(isHit.contain("hit")) {
    if(!thrower.coontains(player)) {
    }, 5L, 200);
    when the Projectile hit event happens it makes a a new string!
  2. joehot200


    For the player, projectile.getShooter() should suffice. Then, check if the shooter is a player, if it is, cast to a player.
    Code (Text):
    Player p = (Player) projectile.getShooter();

    For tasks, you should be using
    Code (Text):
    You accidentally used scheduleAsyncRepeatingTask, you should be using scheduleSyncRepeatingTask.

    Is a repeating task necessary for your purpose? It makes more sense in my opinion to simply listen for the ProjectileHitEvent and then apply the damage upon projectile impact. What made you choose a repeating task, as opposed to a delayed task?
  3. You should use an event listener for this. So you detect when the egg hits the payer to kill him.

    Code (Text):
        public void onEntityDamageByEntity ( EntityDamageByEntityEvent event )
            Entity damagedEntity = event.getEntity();
            Entity damagerEntity = event.getDamager();

            if( damagerEntity instanceof Egg && damagedEntity instanceof Player)
                Player player = (Player) damagedEntity;

  4. you dont know how happy i am thank you soo much!!