2021-06-30 02:18:31 -05:00
|
|
|
package net.nuggetmc.ai.utils;
|
|
|
|
|
|
2021-07-21 13:52:21 -05:00
|
|
|
import net.nuggetmc.ai.TerminatorPlus;
|
2021-07-09 15:49:10 -05:00
|
|
|
import net.nuggetmc.ai.bot.Bot;
|
2021-07-12 18:20:17 -05:00
|
|
|
import net.nuggetmc.ai.bot.agent.Agent;
|
2021-07-19 17:35:28 -05:00
|
|
|
import net.nuggetmc.ai.bot.agent.legacyagent.EnumTargetGoal;
|
|
|
|
|
import net.nuggetmc.ai.bot.agent.legacyagent.LegacyAgent;
|
2021-07-21 13:52:21 -05:00
|
|
|
import org.bukkit.*;
|
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-07-21 13:52:21 -05:00
|
|
|
import org.bukkit.util.Vector;
|
2021-06-30 02:18:31 -05:00
|
|
|
|
|
|
|
|
import java.beans.Statement;
|
2021-07-23 17:25:10 -05:00
|
|
|
import java.util.*;
|
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-07-16 03:41:21 -05:00
|
|
|
private final CommandSender sender;
|
2021-06-30 02:18:31 -05:00
|
|
|
|
|
|
|
|
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) {
|
2021-07-16 03:41:21 -05:00
|
|
|
return Arrays.stream(objects).map(String::valueOf).toArray(String[]::new);
|
2021-07-10 23:51:14 -05:00
|
|
|
}
|
|
|
|
|
|
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-19 17:35:28 -05:00
|
|
|
Object[] args = content.isEmpty() ? null : buildObjects(content);
|
|
|
|
|
|
|
|
|
|
Statement statement = new Statement(this, name, args);
|
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) {
|
2021-07-19 17:35:28 -05:00
|
|
|
String value = str.startsWith(" ") ? str.substring(1) : str;
|
|
|
|
|
Object obj = value;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
obj = Double.parseDouble(value);
|
|
|
|
|
} catch (NumberFormatException ignored) { }
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
obj = Integer.parseInt(value);
|
|
|
|
|
} catch (NumberFormatException ignored) { }
|
|
|
|
|
|
|
|
|
|
if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("false")) {
|
|
|
|
|
obj = Boolean.parseBoolean(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
list.add(obj);
|
2021-07-01 01:12:18 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return list.toArray();
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-19 17:35:28 -05:00
|
|
|
/*
|
|
|
|
|
* DEBUGGER METHODS
|
|
|
|
|
*/
|
|
|
|
|
|
2021-07-23 17:25:10 -05:00
|
|
|
public void block() {
|
|
|
|
|
TerminatorPlus.getInstance().getManager().fetch().forEach(bot -> bot.block(10, 10));
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-23 03:47:11 -05:00
|
|
|
public void offsets(boolean b) {
|
|
|
|
|
Agent agent = TerminatorPlus.getInstance().getManager().getAgent();
|
|
|
|
|
if (!(agent instanceof LegacyAgent)) {
|
|
|
|
|
print("This method currently only supports " + ChatColor.AQUA + "LegacyAgent" + ChatColor.RESET + ".");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LegacyAgent legacyAgent = (LegacyAgent) agent;
|
|
|
|
|
legacyAgent.offsets = b;
|
|
|
|
|
|
|
|
|
|
print("Bot target offsets are now "
|
|
|
|
|
+ (legacyAgent.offsets ? ChatColor.GREEN + "ENABLED" : ChatColor.RED + "DISABLED")
|
|
|
|
|
+ ChatColor.RESET + ".");
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-21 13:52:21 -05:00
|
|
|
public void confuse(int n) {
|
|
|
|
|
if (!(sender instanceof Player)) return;
|
|
|
|
|
|
|
|
|
|
Player player = (Player) sender;
|
|
|
|
|
Location loc = player.getLocation();
|
|
|
|
|
|
|
|
|
|
double f = n < 100 ? .004 * n : .4;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
|
Player target = Bukkit.getOnlinePlayers().stream().skip((int) (Bukkit.getOnlinePlayers().size() * Math.random())).findFirst().orElse(null);
|
|
|
|
|
String name = target == null ? "Steve" : target.getName();
|
|
|
|
|
Bot bot = Bot.createBot(loc, name);
|
|
|
|
|
bot.setVelocity(new Vector(Math.random() - 0.5, 0.5, Math.random() - 0.5).normalize().multiply(f));
|
|
|
|
|
bot.faceLocation(bot.getLocation().add(Math.random() - 0.5, Math.random() - 0.5, Math.random() - 0.5));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
player.getWorld().spawnParticle(Particle.CLOUD, loc, 100, 1, 1, 1, 0.5);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void dreamsmp() {
|
2021-07-23 17:25:10 -05:00
|
|
|
spawnBots(Arrays.asList(
|
2021-07-21 13:52:21 -05:00
|
|
|
"Dream", "GeorgeNotFound", "Callahan", "Sapnap", "awesamdude", "Ponk", "BadBoyHalo", "TommyInnit", "Tubbo_", "ItsFundy", "Punz",
|
|
|
|
|
"Purpled", "WilburSoot", "Jschlatt", "Skeppy", "The_Eret", "JackManifoldTV", "Nihachu", "Quackity", "KarlJacobs", "HBomb94",
|
|
|
|
|
"Technoblade", "Antfrost", "Ph1LzA", "ConnorEatsPants", "CaptainPuffy", "Vikkstar123", "LazarCodeLazar", "Ranboo", "FoolishG",
|
|
|
|
|
"hannahxxrose", "Slimecicle", "Michaelmcchill"
|
2021-07-23 17:25:10 -05:00
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void spawnBots(List<String> players) {
|
|
|
|
|
if (!(sender instanceof Player)) return;
|
2021-07-21 13:52:21 -05:00
|
|
|
|
2021-07-23 17:25:10 -05:00
|
|
|
print("Processing request asynchronously...");
|
2021-07-21 13:52:21 -05:00
|
|
|
|
2021-07-23 17:25:10 -05:00
|
|
|
Bukkit.getScheduler().runTaskAsynchronously(TerminatorPlus.getInstance(), () -> {
|
|
|
|
|
try {
|
|
|
|
|
print("Fetching skin data from the Mojang API for:");
|
2021-07-21 13:52:21 -05:00
|
|
|
|
2021-07-23 17:25:10 -05:00
|
|
|
Player player = (Player) sender;
|
|
|
|
|
Location loc = player.getLocation();
|
|
|
|
|
|
|
|
|
|
Collections.shuffle(players);
|
|
|
|
|
|
|
|
|
|
Map<String, String[]> skinCache = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
int size = players.size();
|
|
|
|
|
int i = 1;
|
|
|
|
|
|
|
|
|
|
for (String name : players) {
|
|
|
|
|
print(name, ChatColor.GRAY + "(" + ChatColor.GREEN + i + ChatColor.GRAY + "/" + size + ")");
|
|
|
|
|
String[] skin = MojangAPI.getSkin(name);
|
|
|
|
|
skinCache.put(name, skin);
|
|
|
|
|
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
print("Creating bots...");
|
|
|
|
|
|
|
|
|
|
double f = .004 * players.size();
|
|
|
|
|
|
|
|
|
|
Bukkit.getScheduler().runTask(TerminatorPlus.getInstance(), () -> {
|
|
|
|
|
skinCache.forEach((name, skin) -> {
|
|
|
|
|
Bot bot = Bot.createBot(loc, name, skin);
|
|
|
|
|
bot.setVelocity(new Vector(Math.random() - 0.5, 0.5, Math.random() - 0.5).normalize().multiply(f));
|
|
|
|
|
bot.faceLocation(bot.getLocation().add(Math.random() - 0.5, Math.random() - 0.5, Math.random() - 0.5));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
player.getWorld().spawnParticle(Particle.CLOUD, loc, 100, 1, 1, 1, 0.5);
|
|
|
|
|
|
|
|
|
|
print("Done.");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (Exception e) {
|
|
|
|
|
print(e);
|
|
|
|
|
}
|
|
|
|
|
});
|
2021-07-21 13:52:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void item() {
|
|
|
|
|
TerminatorPlus.getInstance().getManager().fetch().forEach(b -> b.item = true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void j(boolean b) {
|
|
|
|
|
TerminatorPlus.getInstance().getManager().joinMessages = b;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void epic(int n) {
|
|
|
|
|
if (!(sender instanceof Player)) return;
|
|
|
|
|
|
2021-07-23 17:25:10 -05:00
|
|
|
print("Fetching names asynchronously...");
|
2021-07-21 13:52:21 -05:00
|
|
|
|
2021-07-23 17:25:10 -05:00
|
|
|
List<String> players = new ArrayList<>();
|
2021-07-21 13:52:21 -05:00
|
|
|
|
|
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
|
String name = PlayerUtils.randomName();
|
2021-07-23 17:25:10 -05:00
|
|
|
players.add(name);
|
|
|
|
|
print(name);
|
2021-07-21 13:52:21 -05:00
|
|
|
}
|
|
|
|
|
|
2021-07-23 17:25:10 -05:00
|
|
|
spawnBots(players);
|
2021-07-21 13:52:21 -05:00
|
|
|
}
|
|
|
|
|
|
2021-07-19 17:35:28 -05:00
|
|
|
public void tp() {
|
2021-07-21 13:52:21 -05:00
|
|
|
Bot bot = MathUtils.getRandomSetElement(TerminatorPlus.getInstance().getManager().fetch());
|
2021-07-16 03:41:21 -05:00
|
|
|
|
2021-07-19 17:35:28 -05:00
|
|
|
if (bot == null) {
|
|
|
|
|
print("Failed to locate a bot.");
|
2021-07-16 03:41:21 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-19 17:35:28 -05:00
|
|
|
print("Located bot", ChatColor.GREEN + bot.getName() + ChatColor.RESET + ".");
|
2021-07-16 03:41:21 -05:00
|
|
|
|
2021-07-19 17:35:28 -05:00
|
|
|
if (sender instanceof Player) {
|
|
|
|
|
print("Teleporting...");
|
|
|
|
|
((Player) sender).teleport(bot.getLocation());
|
|
|
|
|
}
|
2021-07-16 03:41:21 -05:00
|
|
|
}
|
|
|
|
|
|
2021-07-19 17:35:28 -05:00
|
|
|
public void setTarget(int n) {
|
2021-07-21 13:52:21 -05:00
|
|
|
Agent agent = TerminatorPlus.getInstance().getManager().getAgent();
|
2021-07-19 17:35:28 -05:00
|
|
|
if (!(agent instanceof LegacyAgent)) {
|
|
|
|
|
print("This method currently only supports " + ChatColor.AQUA + "LegacyAgent" + ChatColor.RESET + ".");
|
2021-07-16 03:41:21 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-19 17:35:28 -05:00
|
|
|
LegacyAgent legacyAgent = (LegacyAgent) agent;
|
|
|
|
|
EnumTargetGoal goal = EnumTargetGoal.of(n);
|
2021-07-16 03:41:21 -05:00
|
|
|
|
2021-07-19 17:35:28 -05:00
|
|
|
legacyAgent.setTargetType(goal);
|
2021-07-16 03:41:21 -05:00
|
|
|
|
2021-07-19 17:35:28 -05:00
|
|
|
print("The goal has been set to " + ChatColor.BLUE + goal.name() + ChatColor.RESET + ".");
|
|
|
|
|
}
|
2021-07-16 03:41:21 -05:00
|
|
|
|
2021-07-19 17:35:28 -05:00
|
|
|
public void fire(boolean b) {
|
2021-07-21 13:52:21 -05:00
|
|
|
TerminatorPlus.getInstance().getManager().fetch().forEach(bot -> bot.setOnFirePackets(b));
|
2021-07-16 03:41:21 -05:00
|
|
|
}
|
|
|
|
|
|
2021-07-10 23:51:14 -05:00
|
|
|
public void trackYVel() {
|
|
|
|
|
if (!(sender instanceof Player)) return;
|
|
|
|
|
|
|
|
|
|
Player player = (Player) sender;
|
|
|
|
|
|
2021-07-21 13:52:21 -05:00
|
|
|
Bukkit.getScheduler().scheduleSyncRepeatingTask(TerminatorPlus.getInstance(), () -> {
|
2021-07-10 23:51:14 -05:00
|
|
|
print(player.getVelocity().getY());
|
|
|
|
|
}, 0, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void hideNametags() { // this works for some reason
|
2021-07-21 13:52:21 -05:00
|
|
|
Set<Bot> bots = TerminatorPlus.getInstance().getManager().fetch();
|
2021-07-09 15:49:10 -05:00
|
|
|
|
|
|
|
|
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-21 13:52:21 -05:00
|
|
|
Set<Bot> bots = TerminatorPlus.getInstance().getManager().fetch();
|
2021-07-09 15:49:10 -05:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
2021-07-21 13:52:21 -05:00
|
|
|
for (Bot bot : TerminatorPlus.getInstance().getManager().fetch()) {
|
2021-07-09 15:49:10 -05:00
|
|
|
bot.faceLocation(player.getEyeLocation());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-10 23:51:14 -05:00
|
|
|
public void toggleAgent() {
|
2021-07-21 13:52:21 -05:00
|
|
|
Agent agent = TerminatorPlus.getInstance().getManager().getAgent();
|
2021-06-30 02:18:31 -05:00
|
|
|
|
|
|
|
|
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 + ".");
|
|
|
|
|
}
|
|
|
|
|
}
|