/bot count and region fixes
-Fix bugs with region setting -/bot count: Count bots by name -/bot info gets closest bot
This commit is contained in:
@@ -16,7 +16,7 @@ public interface BotManager {
|
||||
|
||||
void add(Terminator bot);
|
||||
|
||||
Terminator getFirst(String name);
|
||||
Terminator getFirst(String name, Location target);
|
||||
|
||||
List<String> fetchNames();
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ public enum EnumTargetGoal {
|
||||
this.put("nearestbot", NEAREST_BOT);
|
||||
this.put("nearestbotdiffer", NEAREST_BOT_DIFFER);
|
||||
this.put("nearestbotdifferalpha", NEAREST_BOT_DIFFER_ALPHA);
|
||||
this.put("player", PLAYER);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1496,24 +1496,19 @@ public class LegacyAgent extends Agent {
|
||||
return false;
|
||||
double regionDistResult = result == null ? 0 : getWeightedRegionDist(result.getLocation());
|
||||
return loc.getWorld() == entity.getWorld() && !entity.isDead()
|
||||
&& (result == null || (loc.distance(entity.getLocation()) + regionDistEntity) < (loc.distance(result.getLocation())) + regionDistResult);
|
||||
&& (result == null || (loc.distanceSquared(entity.getLocation()) + regionDistEntity) < (loc.distanceSquared(result.getLocation())) + regionDistResult);
|
||||
}
|
||||
|
||||
private double getWeightedRegionDist(Location loc) {
|
||||
if (region == null)
|
||||
return 0;
|
||||
double diffX = Math.min(0, Math.abs(region.getCenterX() - loc.getX()) - region.getWidthX() * 0.5);
|
||||
double diffX = Math.max(0, Math.abs(region.getCenterX() - loc.getX()) - region.getWidthX() * 0.5);
|
||||
double diffY = Math.max(0, Math.abs(region.getCenterY() - loc.getY()) - region.getHeight() * 0.5);
|
||||
double diffZ = Math.max(0, Math.abs(region.getCenterZ() - loc.getZ()) - region.getWidthZ() * 0.5);
|
||||
if (regionWeightX == 0 && regionWeightY == 0 && regionWeightZ == 0) {
|
||||
if (regionWeightX == 0 && regionWeightY == 0 && regionWeightZ == 0)
|
||||
if (diffX > 0 || diffY > 0 || diffZ > 0)
|
||||
return Double.MAX_VALUE;
|
||||
} else {
|
||||
diffX *= regionWeightX;
|
||||
diffY *= regionWeightY;
|
||||
diffZ *= regionWeightZ;
|
||||
}
|
||||
return diffX * diffX + diffY * diffY + diffZ * diffZ;
|
||||
return diffX * diffX * regionWeightX + diffY * diffY * regionWeightY + diffZ * diffZ * regionWeightZ;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -56,7 +56,17 @@ public class BotManagerImpl implements BotManager, Listener {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Terminator getFirst(String name) {
|
||||
public Terminator getFirst(String name, Location target) {
|
||||
if (target != null) {
|
||||
Terminator closest = null;
|
||||
for (Terminator bot : bots) {
|
||||
if (name.equals(bot.getBotName()) && (closest == null
|
||||
|| target.distanceSquared(bot.getLocation()) < target.distanceSquared(closest.getLocation()))) {
|
||||
closest = bot;
|
||||
}
|
||||
}
|
||||
return closest;
|
||||
}
|
||||
for (Terminator bot : bots) {
|
||||
if (name.equals(bot.getBotName())) {
|
||||
return bot;
|
||||
|
||||
@@ -121,7 +121,7 @@ public class AICommand extends CommandInstance implements AIManager {
|
||||
|
||||
scheduler.runTaskAsynchronously(plugin, () -> {
|
||||
try {
|
||||
Terminator bot = manager.getFirst(name);
|
||||
Terminator bot = manager.getFirst(name, (sender instanceof Player pl) ? pl.getLocation() : null);
|
||||
|
||||
if (bot == null) {
|
||||
sender.sendMessage("Could not find bot " + ChatColor.GREEN + name + ChatColor.RESET + "!");
|
||||
|
||||
@@ -27,6 +27,8 @@ import org.bukkit.util.Vector;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class BotCommand extends CommandInstance {
|
||||
|
||||
@@ -190,7 +192,7 @@ public class BotCommand extends CommandInstance {
|
||||
|
||||
scheduler.runTaskAsynchronously(plugin, () -> {
|
||||
try {
|
||||
Terminator bot = manager.getFirst(name);
|
||||
Terminator bot = manager.getFirst(name, (sender instanceof Player pl) ? pl.getLocation() : null);
|
||||
|
||||
if (bot == null) {
|
||||
sender.sendMessage("Could not find bot " + ChatColor.GREEN + name + ChatColor.RESET + "!");
|
||||
@@ -232,6 +234,23 @@ public class BotCommand extends CommandInstance {
|
||||
return args.length == 2 ? manager.fetchNames() : null;
|
||||
}
|
||||
|
||||
@Command(
|
||||
name = "count",
|
||||
desc = "Counts the amount of bots on screen by name."
|
||||
)
|
||||
public void count(CommandSender sender) {
|
||||
List<String> names = manager.fetchNames();
|
||||
Map<String, Integer> freqMap = names.stream().collect(Collectors.toMap(s -> s, s -> 1, Integer::sum));
|
||||
List<Entry<String, Integer>> entries = freqMap.entrySet().stream()
|
||||
.sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())).collect(Collectors.toList());
|
||||
|
||||
sender.sendMessage(ChatUtils.LINE);
|
||||
entries.forEach(en -> sender.sendMessage(ChatColor.GREEN + en.getKey()
|
||||
+ ChatColor.RESET + " - " + ChatColor.BLUE + en.getValue().toString() + ChatColor.RESET));
|
||||
sender.sendMessage("Total bots: " + ChatColor.BLUE + freqMap.values().stream().reduce(0, Integer::sum) + ChatColor.RESET);
|
||||
sender.sendMessage(ChatUtils.LINE);
|
||||
}
|
||||
|
||||
@Command(
|
||||
name = "reset",
|
||||
desc = "Remove all loaded bots."
|
||||
|
||||
Reference in New Issue
Block a user