Improvements and bug fixes

- Improved look detection for the look option.
- Fixed showing decimals again (sorry about that).
- Don't show health for armor stands.
This commit is contained in:
Zeshan Aslam 2017-03-26 14:11:30 -04:00
parent ec257f3b41
commit 56e25c4bf4
9 changed files with 75 additions and 12 deletions

View File

@ -1,6 +1,6 @@
name: ActionHealth
main: com.zeshanaslam.actionhealth.Main
version: 3.1.5
version: 3.1.6
commands:
Actionhealth:
description: Actionhealth main command.

View File

@ -39,6 +39,8 @@ public class HealthListeners implements Listener {
Entity damaged = event.getEntity();
if (damaged.getType().name().equals("ARMOR_STAND")) return;
if (event.getDamager() instanceof Projectile) {
Projectile projectile = (Projectile) event.getDamager();

View File

@ -58,8 +58,8 @@ public class HealthUtil {
String output = plugin.settingsManager.healthMessage;
output = output.replace("{name}", name);
output = output.replace("{health}", String.valueOf(health));
output = output.replace("{maxhealth}", String.valueOf(maxHealth));
output = output.replace("{health}", String.valueOf((int) health));
output = output.replace("{maxhealth}", String.valueOf((int) maxHealth));
if (output.contains("{usestyle}")) {
String style = "";

View File

@ -6,13 +6,25 @@ import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
public class LookThread extends BukkitRunnable {
private Main plugin;
private Set<Byte> transparentTypeIds;
public LookThread(Main plugin) {
this.plugin = plugin;
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);
}
@Override
@ -28,17 +40,21 @@ public class LookThread extends BukkitRunnable {
List<LivingEntity> entities = TargetHelper.getLivingTargets(player, plugin.settingsManager.lookDistance);
if (!entities.isEmpty()) {
LivingEntity livingEntity = entities.get(0);
String name;
for (LivingEntity livingEntity: entities) {
if (livingEntity.getType().name().equals("ARMOR_STAND")) continue;
if (livingEntity.getCustomName() == null) {
name = livingEntity.getName();
} else {
name = livingEntity.getCustomName();
}
String name;
if (!plugin.settingsManager.blacklist.contains(name) && !livingEntity.hasMetadata("NPC")) {
plugin.healthUtil.sendHealth(player, livingEntity, livingEntity.getHealth());
if (livingEntity.getCustomName() == null) {
name = livingEntity.getName();
} else {
name = livingEntity.getCustomName();
}
if (TargetHelper.canSee(player, livingEntity.getLocation(), transparentTypeIds) && !plugin.settingsManager.blacklist.contains(name) && !livingEntity.hasMetadata("NPC")) {
plugin.healthUtil.sendHealth(player, livingEntity, livingEntity.getHealth());
break;
}
}
}
}

View File

@ -2,12 +2,16 @@ package com.zeshanaslam.actionhealth;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.util.BlockIterator;
import org.bukkit.util.Vector;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* <p>Helper class for getting targets using various methods</p>
@ -285,4 +289,45 @@ public class TargetHelper {
return temp;
}
}
public static Block getTarget(Location from, int distance, byte... transparentTypeIds) {
if (transparentTypeIds.length == 0) {
return getTarget(from, distance, (Set<Byte>) null);
} else {
Set<Byte> types = new HashSet<>(transparentTypeIds.length);
for (byte b : transparentTypeIds) types.add(b);
return getTarget(from, distance, types);
}
}
public static Block getTarget(Location from, int distance, Set<Byte> transparentTypeIds) {
BlockIterator itr = new BlockIterator(from, 0, distance);
while (itr.hasNext()) {
Block block = itr.next();
int id = block.getTypeId();
if (transparentTypeIds == null) {
if (id == 0) continue;
} else if (transparentTypeIds.contains((byte) id)) {
continue;
}
return block;
}
return null;
}
public static Block getTarget(LivingEntity from, int distance, Set<Byte> transparentTypeIds) {
return getTarget(from.getEyeLocation(), distance, transparentTypeIds);
}
public static Block getTarget(LivingEntity from, int distance, byte... transparentTypeIds) {
return getTarget(from.getEyeLocation(), distance, transparentTypeIds);
}
public static boolean canSee(LivingEntity from, Location to, Set<Byte> transparentTypeIds) {
return getTarget(from, (int) Math.ceil(from.getLocation().distance(to)), transparentTypeIds) == null;
}
public static boolean canSee(LivingEntity from, Location to, byte... transparentTypeIds) {
return getTarget(from, (int) Math.ceil(from.getLocation().distance(to)), transparentTypeIds) == null;
}
}