2021-07-01 01:12:18 -05:00
|
|
|
package net.nuggetmc.ai.command.commands;
|
2021-06-26 19:08:15 -07:00
|
|
|
|
2021-07-16 03:41:21 -05:00
|
|
|
import com.jonahseguin.drink.annotation.Command;
|
|
|
|
|
import com.jonahseguin.drink.annotation.OptArg;
|
|
|
|
|
import com.jonahseguin.drink.annotation.Sender;
|
|
|
|
|
import com.jonahseguin.drink.annotation.Text;
|
2021-07-01 01:12:18 -05:00
|
|
|
import com.jonahseguin.drink.utils.ChatUtils;
|
2021-06-26 19:08:15 -07:00
|
|
|
import net.nuggetmc.ai.PlayerAI;
|
2021-07-19 17:35:28 -05:00
|
|
|
import net.nuggetmc.ai.bot.Bot;
|
2021-06-27 00:26:45 -05:00
|
|
|
import net.nuggetmc.ai.bot.BotManager;
|
2021-07-01 01:12:18 -05:00
|
|
|
import net.nuggetmc.ai.command.CommandHandler;
|
|
|
|
|
import net.nuggetmc.ai.command.CommandInstance;
|
2021-06-30 02:18:31 -05:00
|
|
|
import net.nuggetmc.ai.utils.Debugger;
|
2021-07-19 17:35:28 -05:00
|
|
|
import org.bukkit.Bukkit;
|
2021-06-26 19:08:15 -07:00
|
|
|
import org.bukkit.ChatColor;
|
2021-07-19 17:35:28 -05:00
|
|
|
import org.bukkit.Location;
|
2021-06-28 13:18:49 -05:00
|
|
|
import org.bukkit.command.CommandSender;
|
2021-07-19 17:35:28 -05:00
|
|
|
import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer;
|
2021-06-26 19:08:15 -07:00
|
|
|
import org.bukkit.entity.Player;
|
2021-07-19 17:35:28 -05:00
|
|
|
import org.bukkit.scheduler.BukkitScheduler;
|
|
|
|
|
import org.bukkit.util.Vector;
|
2021-06-26 19:08:15 -07:00
|
|
|
|
2021-07-19 17:35:28 -05:00
|
|
|
import java.text.DecimalFormat;
|
2021-06-26 19:08:15 -07:00
|
|
|
import java.text.NumberFormat;
|
|
|
|
|
import java.util.Locale;
|
|
|
|
|
|
2021-07-10 23:51:14 -05:00
|
|
|
public class MainCommand extends CommandInstance {
|
2021-06-26 19:08:15 -07:00
|
|
|
|
2021-07-19 17:35:28 -05:00
|
|
|
private final PlayerAI plugin;
|
2021-07-16 03:41:21 -05:00
|
|
|
private final BotManager manager;
|
2021-07-19 17:35:28 -05:00
|
|
|
private final BukkitScheduler scheduler;
|
|
|
|
|
private final DecimalFormat formatter;
|
2021-06-28 13:18:49 -05:00
|
|
|
|
2021-07-10 23:51:14 -05:00
|
|
|
public MainCommand(CommandHandler commandHandler) {
|
2021-06-26 19:08:15 -07:00
|
|
|
super(commandHandler);
|
2021-06-28 13:18:49 -05:00
|
|
|
|
2021-07-19 17:35:28 -05:00
|
|
|
this.plugin = PlayerAI.getInstance();
|
|
|
|
|
this.manager = plugin.getManager();
|
|
|
|
|
this.scheduler = Bukkit.getScheduler();
|
|
|
|
|
this.formatter = new DecimalFormat("0.##");
|
2021-06-26 19:08:15 -07:00
|
|
|
}
|
|
|
|
|
|
2021-07-04 03:15:30 -05:00
|
|
|
@Command(
|
|
|
|
|
desc = "The PlayerAI main command."
|
|
|
|
|
)
|
|
|
|
|
public void root(@Sender Player sender) {
|
2021-06-26 19:08:15 -07:00
|
|
|
sender.sendMessage(ChatUtils.LINE);
|
2021-07-16 03:41:21 -05:00
|
|
|
sender.sendMessage(ChatColor.GOLD + "PlayerAI" + ChatColor.GRAY + " [" + ChatColor.RED + "v" + PlayerAI.getVersion() + ChatColor.GRAY + "]");
|
2021-07-01 01:12:18 -05:00
|
|
|
commandHandler.getHelp(getClass()).forEach(sender::sendMessage);
|
2021-06-26 19:08:15 -07:00
|
|
|
sender.sendMessage(ChatUtils.LINE);
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-04 03:15:30 -05:00
|
|
|
@Command(
|
|
|
|
|
name = "create",
|
|
|
|
|
desc = "Create bots.",
|
|
|
|
|
usage = "<name> [skin]"
|
|
|
|
|
)
|
|
|
|
|
public void create(@Sender Player sender, String name, @OptArg String skin) {
|
2021-06-28 13:18:49 -05:00
|
|
|
manager.createBots(sender, name, skin, 1);
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-04 03:15:30 -05:00
|
|
|
@Command(
|
|
|
|
|
name = "multi",
|
|
|
|
|
desc = "Create multiple bots at once.",
|
|
|
|
|
usage = "<amount> <name> [skin]"
|
|
|
|
|
)
|
|
|
|
|
public void multi(@Sender Player sender, int n, String name, @OptArg String skin) {
|
2021-06-28 13:18:49 -05:00
|
|
|
manager.createBots(sender, name, skin, n);
|
2021-06-26 19:08:15 -07:00
|
|
|
}
|
|
|
|
|
|
2021-07-04 03:15:30 -05:00
|
|
|
@Command(
|
|
|
|
|
name = "debug",
|
|
|
|
|
desc = "Debug plugin code.",
|
|
|
|
|
usage = "<expression>"
|
|
|
|
|
)
|
|
|
|
|
public void debug(@Sender CommandSender sender, @Text String cmd) {
|
2021-07-01 01:12:18 -05:00
|
|
|
new Debugger(sender).execute(cmd);
|
2021-06-26 19:08:15 -07:00
|
|
|
}
|
|
|
|
|
|
2021-07-04 03:15:30 -05:00
|
|
|
@Command(
|
|
|
|
|
name = "info",
|
2021-07-19 17:35:28 -05:00
|
|
|
desc = "Information about loaded bots.",
|
|
|
|
|
usage = "[name]"
|
2021-07-04 03:15:30 -05:00
|
|
|
)
|
2021-07-19 17:35:28 -05:00
|
|
|
public void info(@Sender CommandSender sender, @OptArg String name) {
|
|
|
|
|
if (name == null) {
|
|
|
|
|
sender.sendMessage(ChatColor.YELLOW + "Bot GUI coming soon!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sender.sendMessage("Processing request...");
|
|
|
|
|
|
|
|
|
|
scheduler.runTaskAsynchronously(plugin, () -> {
|
|
|
|
|
try {
|
|
|
|
|
Bot bot = manager.getFirst(name);
|
|
|
|
|
|
|
|
|
|
if (bot == null) {
|
|
|
|
|
sender.sendMessage("Could not find bot " + ChatColor.GREEN + name + ChatColor.RESET + "!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* health
|
|
|
|
|
* inventory
|
|
|
|
|
* current target
|
|
|
|
|
* current kills
|
|
|
|
|
* skin
|
|
|
|
|
* neural network values
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
sender.sendMessage(ChatUtils.LINE);
|
|
|
|
|
String botName = bot.getName();
|
|
|
|
|
sender.sendMessage(ChatColor.GREEN + botName);
|
|
|
|
|
//String created = ChatColor.YELLOW + "";
|
|
|
|
|
//sender.sendMessage(ChatUtils.BULLET_FORMATTED + "Created: " + created);
|
|
|
|
|
String world = ChatColor.YELLOW + bot.getBukkitEntity().getWorld().getName();
|
|
|
|
|
sender.sendMessage(ChatUtils.BULLET_FORMATTED + "World: " + world);
|
|
|
|
|
Location loc = bot.getLocation();
|
|
|
|
|
String strLoc = ChatColor.YELLOW + formatter.format(loc.getBlockX()) + ", " + formatter.format(loc.getBlockY()) + ", " + formatter.format(loc.getBlockZ());
|
|
|
|
|
sender.sendMessage(ChatUtils.BULLET_FORMATTED + "Position: " + strLoc);
|
|
|
|
|
Vector vel = bot.getVelocity();
|
|
|
|
|
sender.sendMessage(ChatUtils.BULLET_FORMATTED + "Velocity: " + vel);
|
|
|
|
|
String strVel = ChatColor.AQUA + formatter.format(vel.getX()) + ", " + formatter.format(vel.getY()) + ", " + formatter.format(vel.getZ());
|
|
|
|
|
sender.sendMessage(ChatUtils.BULLET_FORMATTED + "Velocity: " + strVel);
|
|
|
|
|
|
|
|
|
|
sender.sendMessage(ChatUtils.LINE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (Exception e) {
|
|
|
|
|
sender.sendMessage(ChatColor.RED + "An exception has occured. Please try again.");
|
|
|
|
|
}
|
|
|
|
|
});
|
2021-06-26 19:08:15 -07:00
|
|
|
}
|
|
|
|
|
|
2021-07-04 03:15:30 -05:00
|
|
|
@Command(
|
|
|
|
|
name = "reset",
|
|
|
|
|
desc = "Remove all loaded bots."
|
|
|
|
|
)
|
|
|
|
|
public void reset(@Sender CommandSender sender) {
|
2021-06-26 19:08:15 -07:00
|
|
|
sender.sendMessage("Removing every bot...");
|
2021-06-26 23:58:51 -05:00
|
|
|
|
2021-06-26 19:08:15 -07:00
|
|
|
int size = manager.fetch().size();
|
|
|
|
|
manager.reset();
|
2021-06-26 23:58:51 -05:00
|
|
|
|
2021-06-26 19:08:15 -07:00
|
|
|
String formatted = NumberFormat.getNumberInstance(Locale.US).format(size);
|
|
|
|
|
sender.sendMessage("Removed " + ChatColor.RED + formatted + ChatColor.RESET + " entit" + (size == 1 ? "y" : "ies") + ".");
|
|
|
|
|
}
|
|
|
|
|
}
|