2017-03-24 01:10:10 +01:00
|
|
|
package com.zeshanaslam.actionhealth;
|
|
|
|
|
2019-08-04 06:38:21 +02:00
|
|
|
import com.zeshanaslam.actionhealth.utils.TargetHelper;
|
2017-03-24 01:10:10 +01:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.entity.LivingEntity;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.scheduler.BukkitRunnable;
|
|
|
|
|
|
|
|
import java.util.List;
|
2017-03-26 20:11:30 +02:00
|
|
|
import java.util.Set;
|
|
|
|
import java.util.TreeSet;
|
2017-03-24 01:10:10 +01:00
|
|
|
|
|
|
|
public class LookThread extends BukkitRunnable {
|
|
|
|
|
|
|
|
private Main plugin;
|
2017-03-26 20:11:30 +02:00
|
|
|
private Set<Byte> transparentTypeIds;
|
2017-03-24 01:10:10 +01:00
|
|
|
|
|
|
|
public LookThread(Main plugin) {
|
|
|
|
this.plugin = plugin;
|
2017-03-26 20:11:30 +02:00
|
|
|
this.transparentTypeIds = new TreeSet<>();
|
|
|
|
|
|
|
|
transparentTypeIds.add((byte) 0);
|
|
|
|
transparentTypeIds.add((byte) 20);
|
|
|
|
transparentTypeIds.add((byte) 95);
|
|
|
|
transparentTypeIds.add((byte) 102);
|
|
|
|
transparentTypeIds.add((byte) 160);
|
|
|
|
transparentTypeIds.add((byte) 8);
|
|
|
|
transparentTypeIds.add((byte) 9);
|
2017-03-24 01:10:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
|
|
|
if (plugin.toggle.contains(player.getUniqueId())) {
|
2019-08-04 06:38:21 +02:00
|
|
|
if (plugin.configStore.toggleMessage != null && !plugin.configStore.toggleMessage.equals("")) {
|
|
|
|
plugin.healthUtil.sendActionBar(player, plugin.configStore.toggleMessage.replace("{name}", player.getName()));
|
2017-03-24 01:10:10 +01:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-08-04 06:38:21 +02:00
|
|
|
List<LivingEntity> entities = TargetHelper.getLivingTargets(player, plugin.configStore.lookDistance);
|
2017-03-24 01:10:10 +01:00
|
|
|
if (!entities.isEmpty()) {
|
2017-05-10 00:01:42 +02:00
|
|
|
for (LivingEntity livingEntity : entities) {
|
2017-03-26 20:11:30 +02:00
|
|
|
if (livingEntity.getType().name().equals("ARMOR_STAND")) continue;
|
2018-08-03 04:19:13 +02:00
|
|
|
if (player.getWorld() != livingEntity.getWorld()) continue;
|
2017-03-24 01:10:10 +01:00
|
|
|
|
2017-03-26 20:11:30 +02:00
|
|
|
String name;
|
|
|
|
if (livingEntity.getCustomName() == null) {
|
|
|
|
name = livingEntity.getName();
|
|
|
|
} else {
|
|
|
|
name = livingEntity.getCustomName();
|
|
|
|
}
|
2017-03-24 01:10:10 +01:00
|
|
|
|
2019-08-04 06:38:21 +02:00
|
|
|
if (TargetHelper.canSee(player, livingEntity.getLocation(), transparentTypeIds) && !plugin.configStore.blacklist.contains(name) && !livingEntity.hasMetadata("NPC")) {
|
2017-03-26 20:11:30 +02:00
|
|
|
plugin.healthUtil.sendHealth(player, livingEntity, livingEntity.getHealth());
|
|
|
|
break;
|
|
|
|
}
|
2017-03-24 01:10:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|