我使用自定义拼写插件运行服务器。下面的功能是单个咒语。它应该做的是对被击中的任何物体造成2点红心,并为施法者治疗2点(每击中一个目标)。但是,它总是将脚轮设置为十个心!

public void onPlayerInteractBlockLifeSteal(final Player player) {
    if (worldChecker(player)){
            if (player.getFoodLevel() > 12){
                List<Block> targets = player.getLineOfSight((Set)null, 20);
                float pathway = 0;
                for (final Block target : targets){
                    Bukkit.getScheduler().runTaskLater(MagictgCraft.that, new Runnable(){
                        @Override
                        public void run(){
                            int count = 0;
                            if (target.getType() != Material.AIR){
                                player.getWorld().playSound(target.getLocation(), Sound.SUCCESSFUL_HIT, 10, 1);
                            }
                            while (count < 5){
                                player.getWorld().playEffect(target.getLocation().clone().add(0.5,0.5,0.5), Effect.WITCH_MAGIC, 10);
                                player.getWorld().playEffect(target.getLocation().clone().add(0.5,0.5,0.5), Effect.SMOKE, 10);
                                count = count + 1;
                            }
                            List<Entity> victims = (List<Entity>) target.getWorld().getNearbyEntities(target.getLocation(),1,1,1);
                            for (Entity victim2 : victims){
                                if (victim2 instanceof LivingEntity){
                                    LivingEntity victim = (LivingEntity) victim2;
                                    if (victim != player){
                                        victim.damage(4,player);
                                        double health = player.getHealth();
                                        health = health + 4;
                                        if (health > 20){
                                            health = 20;
                                        }
                                            player.setHealth(health);
                                    }
                                }
                            }
                        }
                    },(long) pathway);
                    pathway = (float) (pathway + 0.5);
                }
                int manaused = player.getFoodLevel();
                manaused = manaused - 12;
                player.setFoodLevel(manaused);
        }
    }
}


谁能看到任何问题吗?

最佳答案

List<Block> targets = player.getLineOfSight((Set)null, 20);

for (final Block target : targets)


在这里,此循环调用可运行对象的次数与可见的块数量相同。因此,由于您设置了如此宽广的视线,因此每次施法时,它们都会被多次治愈,并自然达到十颗心的上限。

07-28 00:04