2021-06-30 02:18:31 -05:00
|
|
|
package net.nuggetmc.ai.utils;
|
|
|
|
|
|
|
|
|
|
import net.nuggetmc.ai.PlayerAI;
|
2021-07-09 15:49:10 -05:00
|
|
|
import net.nuggetmc.ai.bot.Bot;
|
2021-06-30 02:18:31 -05:00
|
|
|
import net.nuggetmc.ai.bot.agent.BotAgent;
|
2021-07-10 23:51:14 -05:00
|
|
|
import org.bukkit.Bukkit;
|
2021-06-30 02:18:31 -05:00
|
|
|
import org.bukkit.ChatColor;
|
2021-07-09 15:49:10 -05:00
|
|
|
import org.bukkit.Location;
|
|
|
|
|
import org.bukkit.World;
|
2021-06-30 02:18:31 -05:00
|
|
|
import org.bukkit.command.CommandSender;
|
2021-07-09 15:49:10 -05:00
|
|
|
import org.bukkit.entity.ArmorStand;
|
|
|
|
|
import org.bukkit.entity.EntityType;
|
|
|
|
|
import org.bukkit.entity.Player;
|
2021-07-10 23:51:14 -05:00
|
|
|
import org.bukkit.permissions.ServerOperator;
|
2021-06-30 02:18:31 -05:00
|
|
|
|
|
|
|
|
import java.beans.Statement;
|
2021-07-01 01:12:18 -05:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.List;
|
2021-07-09 15:49:10 -05:00
|
|
|
import java.util.Set;
|
2021-06-30 02:18:31 -05:00
|
|
|
|
|
|
|
|
public class Debugger {
|
|
|
|
|
|
2021-07-01 01:12:18 -05:00
|
|
|
private static final String PREFIX = ChatColor.YELLOW + "[DEBUG] " + ChatColor.RESET;
|
|
|
|
|
|
2021-06-30 02:18:31 -05:00
|
|
|
private CommandSender sender;
|
|
|
|
|
|
|
|
|
|
public Debugger(CommandSender sender) {
|
|
|
|
|
this.sender = sender;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-10 23:51:14 -05:00
|
|
|
public static void log(Object... objects) {
|
|
|
|
|
String[] values = formStringArray(objects);
|
|
|
|
|
Bukkit.getOnlinePlayers().stream().filter(ServerOperator::isOp).forEach(p -> p.sendMessage(PREFIX + String.join(" ", values)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static String[] formStringArray(Object[] objects) {
|
|
|
|
|
return Arrays.stream(objects).map(Object::toString).toArray(String[]::new);
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-01 01:12:18 -05:00
|
|
|
private void print(Object... objects) {
|
2021-07-10 23:51:14 -05:00
|
|
|
sender.sendMessage(PREFIX + String.join(" ", formStringArray(objects)));
|
2021-06-30 02:18:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void execute(String cmd) {
|
|
|
|
|
try {
|
2021-07-01 01:12:18 -05:00
|
|
|
int[] pts = {cmd.indexOf('('), cmd.indexOf(')')};
|
|
|
|
|
if (pts[0] == -1 || pts[1] == -1) throw new IllegalArgumentException();
|
|
|
|
|
|
|
|
|
|
String name = cmd.substring(0, pts[0]);
|
|
|
|
|
String content = cmd.substring(pts[0] + 1, pts[1]);
|
|
|
|
|
|
2021-07-10 23:51:14 -05:00
|
|
|
Statement statement = new Statement(this, name, content.isEmpty() ? null : new Object[]{content});
|
2021-07-01 01:12:18 -05:00
|
|
|
print("Running the expression \"" + ChatColor.AQUA + cmd + ChatColor.RESET + "\"...");
|
2021-06-30 02:18:31 -05:00
|
|
|
statement.execute();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (Exception e) {
|
2021-07-01 01:12:18 -05:00
|
|
|
print("Error: the expression \"" + ChatColor.AQUA + cmd + ChatColor.RESET + "\" failed to execute.");
|
|
|
|
|
print(e.toString());
|
2021-06-30 02:18:31 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-01 01:12:18 -05:00
|
|
|
public Object[] buildObjects(String content) {
|
|
|
|
|
List<Object> list = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
if (!content.isEmpty()) {
|
|
|
|
|
String[] values = content.split(",");
|
|
|
|
|
|
|
|
|
|
for (String str : values) {
|
|
|
|
|
list.add(str.startsWith(" ") ? str.substring(1) : str);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return list.toArray();
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-10 23:51:14 -05:00
|
|
|
public void trackYVel() {
|
|
|
|
|
if (!(sender instanceof Player)) return;
|
|
|
|
|
|
|
|
|
|
Player player = (Player) sender;
|
|
|
|
|
|
|
|
|
|
Bukkit.getScheduler().scheduleSyncRepeatingTask(PlayerAI.getInstance(), () -> {
|
|
|
|
|
print(player.getVelocity().getY());
|
|
|
|
|
}, 0, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void t() {
|
|
|
|
|
Bukkit.dispatchCommand(sender, "bot debug t(" + !PlayerUtils.getAllTargetable() + ")");
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-09 15:49:10 -05:00
|
|
|
public void t(String content) {
|
|
|
|
|
Object[] obj = buildObjects(content);
|
|
|
|
|
|
|
|
|
|
if (obj.length != 1 || obj[0] instanceof Boolean) {
|
|
|
|
|
print("Invalid arguments!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PlayerUtils.setAllTargetable(Boolean.parseBoolean((String) obj[0]));
|
|
|
|
|
String var = "PlayerUtils.allTargetable";
|
|
|
|
|
|
|
|
|
|
if (PlayerUtils.getAllTargetable()) {
|
|
|
|
|
print(var + " is now " + ChatColor.GREEN + "TRUE" + ChatColor.RESET + ".");
|
|
|
|
|
} else {
|
|
|
|
|
print(var + " is now " + ChatColor.RED + "FALSE" + ChatColor.RESET + ".");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-10 23:51:14 -05:00
|
|
|
public void hideNametags() { // this works for some reason
|
2021-07-09 15:49:10 -05:00
|
|
|
Set<Bot> bots = PlayerAI.getInstance().getManager().fetch();
|
|
|
|
|
|
|
|
|
|
for (Bot bot : bots) {
|
|
|
|
|
Location loc = bot.getLocation();
|
|
|
|
|
World world = loc.getWorld();
|
|
|
|
|
|
|
|
|
|
if (world == null) continue;
|
|
|
|
|
|
|
|
|
|
loc.setX(loc.getBlockX());
|
|
|
|
|
loc.setY(loc.getBlockY());
|
|
|
|
|
loc.setZ(loc.getBlockZ());
|
|
|
|
|
|
|
|
|
|
loc.add(0.5, 0.5, 0.5);
|
|
|
|
|
|
|
|
|
|
ArmorStand seat = (ArmorStand) world.spawnEntity(loc, EntityType.ARMOR_STAND);
|
|
|
|
|
seat.setVisible(false);
|
|
|
|
|
seat.setSmall(true);
|
|
|
|
|
|
|
|
|
|
bot.getBukkitEntity().setPassenger(seat);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-10 23:51:14 -05:00
|
|
|
public void sit() {
|
2021-07-09 15:49:10 -05:00
|
|
|
Set<Bot> bots = PlayerAI.getInstance().getManager().fetch();
|
|
|
|
|
|
|
|
|
|
for (Bot bot : bots) {
|
|
|
|
|
Location loc = bot.getLocation();
|
|
|
|
|
World world = loc.getWorld();
|
|
|
|
|
|
|
|
|
|
if (world == null) continue;
|
|
|
|
|
|
|
|
|
|
loc.setX(loc.getBlockX());
|
|
|
|
|
loc.setY(loc.getBlockY());
|
|
|
|
|
loc.setZ(loc.getBlockZ());
|
|
|
|
|
|
|
|
|
|
loc.add(0.5, -1.5, 0.5);
|
|
|
|
|
|
|
|
|
|
ArmorStand seat = (ArmorStand) world.spawnEntity(loc, EntityType.ARMOR_STAND);
|
|
|
|
|
seat.setVisible(false);
|
|
|
|
|
seat.setGravity(false);
|
|
|
|
|
seat.setSmall(true);
|
|
|
|
|
|
|
|
|
|
seat.addPassenger(bot.getBukkitEntity());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-10 23:51:14 -05:00
|
|
|
public void look() {
|
2021-07-09 15:49:10 -05:00
|
|
|
if (!(sender instanceof Player)) {
|
|
|
|
|
print("Unspecified player.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Player player = (Player) sender;
|
|
|
|
|
|
|
|
|
|
for (Bot bot : PlayerAI.getInstance().getManager().fetch()) {
|
|
|
|
|
bot.faceLocation(player.getEyeLocation());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-01 01:12:18 -05:00
|
|
|
public void printObj(String content) {
|
|
|
|
|
if (content.isEmpty()) {
|
|
|
|
|
print("null");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Arrays.stream(buildObjects(content)).forEach(this::print);
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-10 23:51:14 -05:00
|
|
|
public void toggleAgent() {
|
2021-06-30 02:18:31 -05:00
|
|
|
BotAgent agent = PlayerAI.getInstance().getManager().getAgent();
|
|
|
|
|
|
|
|
|
|
boolean b = agent.isEnabled();
|
|
|
|
|
agent.setEnabled(!b);
|
|
|
|
|
|
2021-07-01 01:12:18 -05:00
|
|
|
print("The Bot Agent is now "
|
2021-06-30 02:18:31 -05:00
|
|
|
+ (b ? ChatColor.RED + "DISABLED" : ChatColor.GREEN + "ENABLED")
|
|
|
|
|
+ ChatColor.RESET + ".");
|
|
|
|
|
}
|
|
|
|
|
}
|