/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:
@@ -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 + "!");
|
||||
@@ -231,6 +233,23 @@ public class BotCommand extends CommandInstance {
|
||||
public List<String> infoAutofill(CommandSender sender, String[] args) {
|
||||
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",
|
||||
|
||||
Reference in New Issue
Block a user