added mob target command

This commit is contained in:
Badbird-5907
2022-08-11 19:42:14 -04:00
parent 24f9790f52
commit 534258dd0a
3 changed files with 32 additions and 14 deletions

View File

@@ -46,5 +46,8 @@ public interface BotManager {
Terminator getBot(int entityId); Terminator getBot(int entityId);
boolean isMobTarget();
void setMobTarget(boolean mobTarget);
} }

View File

@@ -34,7 +34,7 @@ public class BotManagerImpl implements BotManager, Listener {
private final NumberFormat numberFormat; private final NumberFormat numberFormat;
public boolean joinMessages = false; public boolean joinMessages = false;
private boolean mobTarget = false;
public BotManagerImpl() { public BotManagerImpl() {
this.agent = new LegacyAgent(this, TerminatorPlus.getInstance()); this.agent = new LegacyAgent(this, TerminatorPlus.getInstance());
this.bots = ConcurrentHashMap.newKeySet(); //should fix concurrentmodificationexception this.bots = ConcurrentHashMap.newKeySet(); //should fix concurrentmodificationexception
@@ -139,6 +139,7 @@ public class BotManagerImpl implements BotManager, Listener {
} else if (i > 1) { } else if (i > 1) {
bot.setVelocity(randomVelocity().multiply(f)); bot.setVelocity(randomVelocity().multiply(f));
} }
bot.setIgnoredByMobs(!mobTarget);
bots.add(bot); bots.add(bot);
i++; i++;
@@ -194,6 +195,16 @@ public class BotManagerImpl implements BotManager, Listener {
return null; return null;
} }
@Override
public boolean isMobTarget() {
return mobTarget;
}
@Override
public void setMobTarget(boolean mobTarget) {
this.mobTarget = mobTarget;
}
@EventHandler @EventHandler
public void onJoin(PlayerJoinEvent event) { public void onJoin(PlayerJoinEvent event) {
ServerGamePacketListenerImpl connection = ((CraftPlayer) event.getPlayer()).getHandle().connection; ServerGamePacketListenerImpl connection = ((CraftPlayer) event.getPlayer()).getHandle().connection;

View File

@@ -267,29 +267,33 @@ public class BotCommand extends CommandInstance {
String extra = ChatColor.GRAY + " [" + ChatColor.YELLOW + "/bot settings" + ChatColor.GRAY + "]"; String extra = ChatColor.GRAY + " [" + ChatColor.YELLOW + "/bot settings" + ChatColor.GRAY + "]";
if (arg1 == null || (!arg1.equals("setgoal"))) { if (arg1 == null || ((!arg1.equals("setgoal")) && !arg1.equals("mobtarget"))) {
sender.sendMessage(ChatUtils.LINE); sender.sendMessage(ChatUtils.LINE);
sender.sendMessage(ChatColor.GOLD + "Bot Settings" + extra); sender.sendMessage(ChatColor.GOLD + "Bot Settings" + extra);
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 + "setgoal" + ChatUtils.BULLET_FORMATTED + "Set the global bot target selection method.");
sender.sendMessage(ChatUtils.BULLET_FORMATTED + ChatColor.YELLOW + "mobtarget" + ChatUtils.BULLET_FORMATTED + "Allow all future bots spawned to be targetted by hostile mobs."); sender.sendMessage(ChatUtils.BULLET_FORMATTED + ChatColor.YELLOW + "mobtarget" + ChatUtils.BULLET_FORMATTED + "Allow all future bots spawned to be targeted by hostile mobs.");
sender.sendMessage(ChatUtils.LINE); sender.sendMessage(ChatUtils.LINE);
return; return;
} }
EnumTargetGoal goal = EnumTargetGoal.from(arg2 == null ? "" : arg2); if (arg1.equalsIgnoreCase("setgoal")) {
EnumTargetGoal goal = EnumTargetGoal.from(arg2 == null ? "" : arg2);
if (goal == null) { if (goal == null) {
sender.sendMessage(ChatUtils.LINE); sender.sendMessage(ChatUtils.LINE);
sender.sendMessage(ChatColor.GOLD + "Goal Selection Types" + extra); sender.sendMessage(ChatColor.GOLD + "Goal Selection Types" + extra);
Arrays.stream(EnumTargetGoal.values()).forEach(g -> sender.sendMessage(ChatUtils.BULLET_FORMATTED + ChatColor.YELLOW + g.name().replace("_", "").toLowerCase() Arrays.stream(EnumTargetGoal.values()).forEach(g -> sender.sendMessage(ChatUtils.BULLET_FORMATTED + ChatColor.YELLOW + g.name().replace("_", "").toLowerCase()
+ ChatUtils.BULLET_FORMATTED + g.description())); + ChatUtils.BULLET_FORMATTED + g.description()));
sender.sendMessage(ChatUtils.LINE); sender.sendMessage(ChatUtils.LINE);
return; return;
}
agent.setTargetType(goal);
sender.sendMessage("The global bot goal has been set to " + ChatColor.BLUE + goal.name() + ChatColor.RESET + ".");
} else if (arg1.equalsIgnoreCase("mobtarget")) {
manager.setMobTarget(!manager.isMobTarget());
sender.sendMessage("Mob targeting is now " + (manager.isMobTarget() ? ChatColor.GREEN + "enabled" : ChatColor.RED + "disabled") + ChatColor.RESET + ". (for all future bots)");
} }
agent.setTargetType(goal);
sender.sendMessage("The global bot goal has been set to " + ChatColor.BLUE + goal.name() + ChatColor.RESET + ".");
} }
@Autofill @Autofill