Spawn bots at location feature

This commit is contained in:
ThisTestUser
2022-11-23 17:49:44 -05:00
parent a829cdf701
commit 0e4a5e171f
3 changed files with 62 additions and 3 deletions

View File

@@ -10,6 +10,10 @@ import java.util.Set;
import java.util.UUID;
public interface BotManager {
Location getSpawnLoc();
void setSpawnLoc(Location loc);
Set<Terminator> fetch();
Agent getAgent();

View File

@@ -36,12 +36,23 @@ public class BotManagerImpl implements BotManager, Listener {
public boolean joinMessages = false;
private boolean mobTarget = false;
private boolean addPlayerList = false;
private Location spawnLoc;
public BotManagerImpl() {
this.agent = new LegacyAgent(this, TerminatorPlus.getInstance());
this.bots = ConcurrentHashMap.newKeySet(); //should fix concurrentmodificationexception
this.numberFormat = NumberFormat.getInstance(Locale.US);
}
@Override
public Location getSpawnLoc() {
return spawnLoc;
}
@Override
public void setSpawnLoc(Location loc) {
spawnLoc = loc;
}
@Override
public Set<Terminator> fetch() {
@@ -110,7 +121,18 @@ public class BotManagerImpl implements BotManager, Listener {
skinName = skinName == null ? name : skinName;
createBots(sender.getLocation(), name, MojangAPI.getSkin(skinName), n, network);
if (spawnLoc != null) {
sender.sendMessage("The spawn location is "
+ ChatColor.BLUE + String.format("(%s, %s, %s)", spawnLoc.getX(), spawnLoc.getY(), spawnLoc.getZ()) + ChatColor.RESET
+ ". This will be reset to the player location next time.");
Location loc = sender.getLocation().clone();
loc.setX(spawnLoc.getX());
loc.setY(spawnLoc.getY());
loc.setZ(spawnLoc.getZ());
createBots(loc, name, MojangAPI.getSkin(skinName), n, network);
spawnLoc = null;
} else
createBots(sender.getLocation(), name, MojangAPI.getSkin(skinName), n, network);
sender.sendMessage("Process completed (" + ChatColor.RED + ((System.currentTimeMillis() - timestamp) / 1000D) + "s" + ChatColor.RESET + ").");
}

View File

@@ -286,10 +286,11 @@ public class BotCommand extends CommandInstance {
String extra = ChatColor.GRAY + " [" + ChatColor.YELLOW + "/bot settings" + ChatColor.GRAY + "]";
if (arg1 == null || ((!arg1.equalsIgnoreCase("setgoal")) && !arg1.equalsIgnoreCase("mobtarget") && !arg1.equalsIgnoreCase("playertarget")
if (arg1 == null || (!arg1.equalsIgnoreCase("spawnloc") && !arg1.equalsIgnoreCase("setgoal") && !arg1.equalsIgnoreCase("mobtarget") && !arg1.equalsIgnoreCase("playertarget")
&& !arg1.equalsIgnoreCase("addplayerlist") && !arg1.equalsIgnoreCase("region"))) {
sender.sendMessage(ChatUtils.LINE);
sender.sendMessage(ChatColor.GOLD + "Bot Settings" + extra);
sender.sendMessage(ChatUtils.BULLET_FORMATTED + ChatColor.YELLOW + "spawnloc" + ChatUtils.BULLET_FORMATTED + "Set the location where the bots should spawn. This will be reset after a spawn command is executed.");
sender.sendMessage(ChatUtils.BULLET_FORMATTED + ChatColor.YELLOW + "setgoal" + ChatUtils.BULLET_FORMATTED + "Set the global bot target selection method.");
sender.sendMessage(ChatUtils.BULLET_FORMATTED + ChatColor.YELLOW + "mobtarget" + ChatUtils.BULLET_FORMATTED + "Allow all bots to be targeted by hostile mobs.");
sender.sendMessage(ChatUtils.BULLET_FORMATTED + ChatColor.YELLOW + "playertarget" + ChatUtils.BULLET_FORMATTED + "Sets a player name for spawned bots to focus on if the goal is PLAYER.");
@@ -299,7 +300,38 @@ public class BotCommand extends CommandInstance {
return;
}
if (arg1.equalsIgnoreCase("setgoal")) {
if (arg1.equalsIgnoreCase("spawnloc")) {
if (arg2 == null) {
if (manager.getSpawnLoc() == null)
sender.sendMessage("No custom spawn location has been set. The bots will spawn at the player location.");
else {
Location loc = manager.getSpawnLoc();
sender.sendMessage("The next spawn location will be at " + ChatColor.BLUE + String.format("(%s, %s, %s)", loc.getX(), loc.getY(), loc.getZ()) + ChatColor.RESET + ".");
}
return;
}
if (arg2.equalsIgnoreCase("clear")) {
manager.setSpawnLoc(null);
sender.sendMessage("The spawn location has been reset to the player location.");
return;
}
if (args.size() != 4) {
sender.sendMessage("Incorrect argument size. Correct syntax: " + ChatColor.YELLOW + "/bot settings spawnloc <x> <y> <z>" + ChatColor.RESET);
return;
}
double x, y, z;
try {
x = Double.parseDouble(args.get(1));
y = Double.parseDouble(args.get(2));
z = Double.parseDouble(args.get(3));
} catch (NumberFormatException e) {
sender.sendMessage("The block coordinates must be doubles!");
sender.sendMessage("Correct syntax: " + ChatColor.YELLOW + "/bot settings spawnloc <x> <y> <z>" + ChatColor.RESET);
return;
}
manager.setSpawnLoc(new Location(null, x, y, z));
sender.sendMessage("The next spawn location has been set to " + ChatColor.BLUE + String.format("(%s, %s, %s)", x, y, z) + ChatColor.RESET + ".");
} else if (arg1.equalsIgnoreCase("setgoal")) {
if (arg2 == null) {
sender.sendMessage("The global bot goal is currently " + ChatColor.BLUE + agent.getTargetType() + ChatColor.RESET + ".");
return;
@@ -439,6 +471,7 @@ public class BotCommand extends CommandInstance {
// lookall
if (args.length == 2) {
output.add("spawnloc");
output.add("setgoal");
output.add("mobtarget");
output.add("playertarget");