Change CUSTOM_MOB_LIST

This commit is contained in:
ThisTestUser
2024-09-19 12:24:51 -04:00
parent 1ce2c0bad1
commit 545a3f64c7
2 changed files with 35 additions and 34 deletions

View File

@@ -57,8 +57,8 @@ public class LegacyAgent extends Agent {
private double regionWeightY; private double regionWeightY;
private double regionWeightZ; private double regionWeightZ;
public static final Set<EntityType> CUSTOM_TYPES_LIST = new HashSet<>(); public static final Set<EntityType> CUSTOM_MOB_LIST = new HashSet<>();
public static boolean areCustomTypesHostile = false; public static String customListMode = "custom";
public LegacyAgent(BotManager manager, Plugin plugin) { public LegacyAgent(BotManager manager, Plugin plugin) {
super(manager, plugin); super(manager, plugin);
@@ -1459,7 +1459,7 @@ public class LegacyAgent extends Agent {
case NEAREST_HOSTILE: { case NEAREST_HOSTILE: {
for (LivingEntity entity : bot.getBukkitEntity().getWorld().getLivingEntities()) { for (LivingEntity entity : bot.getBukkitEntity().getWorld().getLivingEntities()) {
if ((entity instanceof Monster || (areCustomTypesHostile && CUSTOM_TYPES_LIST.contains(entity.getType()))) && validateCloserEntity(entity, loc, result)) { if ((entity instanceof Monster || (customListMode.equals("hostile") && CUSTOM_MOB_LIST.contains(entity.getType()))) && validateCloserEntity(entity, loc, result)) {
result = entity; result = entity;
} }
} }
@@ -1469,7 +1469,8 @@ public class LegacyAgent extends Agent {
case NEAREST_RAIDER: { case NEAREST_RAIDER: {
for (LivingEntity entity : bot.getBukkitEntity().getWorld().getLivingEntities()) { for (LivingEntity entity : bot.getBukkitEntity().getWorld().getLivingEntities()) {
if ((entity instanceof Raider || (entity instanceof Vex vex && vex.getSummoner() instanceof Raider)) && validateCloserEntity(entity, loc, result)) { boolean raider = entity instanceof Raider || (entity instanceof Vex vex && vex.getSummoner() instanceof Raider);
if (raider || (customListMode.equals("raider") && CUSTOM_MOB_LIST.contains(entity.getType())) && validateCloserEntity(entity, loc, result)) {
result = entity; result = entity;
} }
} }
@@ -1479,7 +1480,7 @@ public class LegacyAgent extends Agent {
case NEAREST_MOB: { case NEAREST_MOB: {
for (LivingEntity entity : bot.getBukkitEntity().getWorld().getLivingEntities()) { for (LivingEntity entity : bot.getBukkitEntity().getWorld().getLivingEntities()) {
if ((entity instanceof Mob || CUSTOM_TYPES_LIST.contains(entity.getType())) && validateCloserEntity(entity, loc, result)) { if ((entity instanceof Mob || (customListMode.equals("mob") && CUSTOM_MOB_LIST.contains(entity.getType()))) && validateCloserEntity(entity, loc, result)) {
result = entity; result = entity;
} }
} }
@@ -1535,7 +1536,7 @@ public class LegacyAgent extends Agent {
case CUSTOM_LIST: { case CUSTOM_LIST: {
for (LivingEntity entity : bot.getBukkitEntity().getWorld().getLivingEntities()) { for (LivingEntity entity : bot.getBukkitEntity().getWorld().getLivingEntities()) {
if (CUSTOM_TYPES_LIST.contains(entity.getType()) && validateCloserEntity(entity, loc, result)) { if (customListMode.equals("custom") && CUSTOM_MOB_LIST.contains(entity.getType()) && validateCloserEntity(entity, loc, result)) {
result = entity; result = entity;
} }
} }
@@ -1559,7 +1560,7 @@ public class LegacyAgent extends Agent {
if (event.isCancelled()) return null; if (event.isCancelled()) return null;
return event.getTarget(); return event.getTarget();
} }
private boolean validateCloserEntity(LivingEntity entity, Location loc, LivingEntity result) { private boolean validateCloserEntity(LivingEntity entity, Location loc, LivingEntity result) {
double regionDistEntity = getWeightedRegionDist(entity.getLocation()); double regionDistEntity = getWeightedRegionDist(entity.getLocation());
if (regionDistEntity == Double.MAX_VALUE) if (regionDistEntity == Double.MAX_VALUE)

View File

@@ -62,15 +62,15 @@ public class BotEnvironmentCommand extends CommandInstance {
sender.sendMessage(ChatUtils.LINE); sender.sendMessage(ChatUtils.LINE);
} else if (args.size() > 0 && args.get(0).equals("mobs")) { } else if (args.size() > 0 && args.get(0).equals("mobs")) {
sender.sendMessage(ChatUtils.LINE); sender.sendMessage(ChatUtils.LINE);
sender.sendMessage("Sometimes, you may want to have a pre-set list of mob types that the bot will target."); sender.sendMessage("The custom mob list is a user-defined list of mobs.");
sender.sendMessage("Additionally, some mobs (especially bosses) may not be considered as hostile."); sender.sendMessage("Use " + ChatColor.YELLOW + "/botenvironment addCustomMob <name>" + ChatColor.RESET + " to add mob types to the list.");
sender.sendMessage("To resolve this, use " + ChatColor.YELLOW + "/botenvironment addCustomMob <name>" + ChatColor.RESET + " to add mob types to a list."); sender.sendMessage("The list can be used in the CUSTOM_LIST targeting option, and can also be appended to the hostile, raider, or mob targeting options.");
sender.sendMessage(ChatColor.YELLOW + "/botenvironment mobListType" + ChatColor.RESET + " changes if the nearest hostile targeting option should consider this list."); sender.sendMessage("When appending, the mobs predefined as well as the mobs in the custom list will be considered.");
sender.sendMessage("The nearest mob and custom list targeting options will always include mobs in this list."); sender.sendMessage("Use " + ChatColor.YELLOW + "/botenvironment mobListType" + ChatColor.RESET + " to change the behavior of the custom mob list.");
sender.sendMessage(ChatUtils.LINE); sender.sendMessage(ChatUtils.LINE);
} else { } else {
sender.sendMessage("Do " + ChatColor.YELLOW + "/botenvironment help blocks " + ChatColor.RESET + "for more information on adding solid blocks."); sender.sendMessage("Do " + ChatColor.YELLOW + "/botenvironment help blocks " + ChatColor.RESET + "for more information on adding solid blocks.");
sender.sendMessage("Do " + ChatColor.YELLOW + "/botenvironment help mobs " + ChatColor.RESET + "for more information on adding custom mobs."); sender.sendMessage("Do " + ChatColor.YELLOW + "/botenvironment help mobs " + ChatColor.RESET + "for more information on creating a custom mob list.");
} }
} }
@@ -277,7 +277,7 @@ public class BotEnvironmentCommand extends CommandInstance {
@Command( @Command(
name = "addCustomMob", name = "addCustomMob",
desc = "Adds a mob type to the list of custom mobs.", desc = "Adds a mob to the custom list.",
aliases = {"addcustommob"}, aliases = {"addcustommob"},
autofill = "autofill" autofill = "autofill"
) )
@@ -287,7 +287,7 @@ public class BotEnvironmentCommand extends CommandInstance {
sender.sendMessage("The entity type you specified does not exist!"); sender.sendMessage("The entity type you specified does not exist!");
return; return;
} }
if (LegacyAgent.CUSTOM_TYPES_LIST.add(type)) if (LegacyAgent.CUSTOM_MOB_LIST.add(type))
sender.sendMessage("Successfully added " + ChatColor.BLUE + type.name() + ChatColor.RESET + " to the list."); sender.sendMessage("Successfully added " + ChatColor.BLUE + type.name() + ChatColor.RESET + " to the list.");
else else
sender.sendMessage(ChatColor.BLUE + type.name() + ChatColor.RESET + " already exists in the list!"); sender.sendMessage(ChatColor.BLUE + type.name() + ChatColor.RESET + " already exists in the list!");
@@ -295,7 +295,7 @@ public class BotEnvironmentCommand extends CommandInstance {
@Command( @Command(
name = "removeCustomMob", name = "removeCustomMob",
desc = "Removes a mob type to the list of custom mobs.", desc = "Removes a mob from the custom list.",
aliases = {"removecustommob"}, aliases = {"removecustommob"},
autofill = "autofill" autofill = "autofill"
) )
@@ -305,7 +305,7 @@ public class BotEnvironmentCommand extends CommandInstance {
sender.sendMessage("The entity type you specified does not exist!"); sender.sendMessage("The entity type you specified does not exist!");
return; return;
} }
if (LegacyAgent.CUSTOM_TYPES_LIST.remove(type)) if (LegacyAgent.CUSTOM_MOB_LIST.remove(type))
sender.sendMessage("Successfully removed " + ChatColor.BLUE + type.name() + ChatColor.RESET + " from the list."); sender.sendMessage("Successfully removed " + ChatColor.BLUE + type.name() + ChatColor.RESET + " from the list.");
else else
sender.sendMessage(ChatColor.BLUE + type.name() + ChatColor.RESET + " does not exist in the list!"); sender.sendMessage(ChatColor.BLUE + type.name() + ChatColor.RESET + " does not exist in the list!");
@@ -313,46 +313,44 @@ public class BotEnvironmentCommand extends CommandInstance {
@Command( @Command(
name = "listCustomMobs", name = "listCustomMobs",
desc = "Displays the list of custom mobs manually added.", desc = "Displays the custom list of mobs.",
aliases = {"listcustommobs"} aliases = {"listcustommobs"}
) )
public void listCustomMobs(CommandSender sender) { public void listCustomMobs(CommandSender sender) {
sender.sendMessage(ChatUtils.LINE); sender.sendMessage(ChatUtils.LINE);
for (EntityType type : LegacyAgent.CUSTOM_TYPES_LIST) for (EntityType type : LegacyAgent.CUSTOM_MOB_LIST)
sender.sendMessage(ChatColor.GREEN + type.name() + ChatColor.RESET); sender.sendMessage(ChatColor.GREEN + type.name() + ChatColor.RESET);
sender.sendMessage("Total items: " + ChatColor.BLUE + LegacyAgent.CUSTOM_TYPES_LIST.size() + ChatColor.RESET); sender.sendMessage("Total items: " + ChatColor.BLUE + LegacyAgent.CUSTOM_MOB_LIST.size() + ChatColor.RESET);
sender.sendMessage(ChatUtils.LINE); sender.sendMessage(ChatUtils.LINE);
} }
@Command( @Command(
name = "clearCustomMobs", name = "clearCustomMobs",
desc = "Clears the list of custom mobs manually added.", desc = "Clears the custom list of mobs.",
aliases = {"clearcustommobs"} aliases = {"clearcustommobs"}
) )
public void clearCustomMobs(CommandSender sender) { public void clearCustomMobs(CommandSender sender) {
int size = LegacyAgent.CUSTOM_TYPES_LIST.size(); int size = LegacyAgent.CUSTOM_MOB_LIST.size();
LegacyAgent.CUSTOM_TYPES_LIST.clear(); LegacyAgent.CUSTOM_MOB_LIST.clear();
sender.sendMessage("Removed all " + ChatColor.BLUE + size + ChatColor.RESET + " item(s) from the list."); sender.sendMessage("Removed all " + ChatColor.BLUE + size + ChatColor.RESET + " item(s) from the list.");
} }
@Command( @Command(
name = "mobListType", name = "mobListType",
desc = "Changes the custom mob list type to hostile or passive.", desc = "Changes the behavior of the custom mob list.",
aliases = {"moblisttype"}, aliases = {"moblisttype"},
autofill = "autofill" autofill = "autofill"
) )
public void mobListType(CommandSender sender, List<String> args) { public void mobListType(CommandSender sender, List<String> args) {
if (args.isEmpty()) { if (args.isEmpty()) {
String type = LegacyAgent.areCustomTypesHostile ? "hostile" : "passive"; sender.sendMessage("The custom mob list type is " + ChatColor.BLUE + LegacyAgent.customListMode + ChatColor.RESET + ".");
sender.sendMessage("The custom mob list type is " + ChatColor.BLUE + type + ChatColor.RESET + "."); } else if (args.size() > 0 && (args.get(0).equals("hostile") || args.get(0).equals("raider")
} else if (args.size() > 0 && args.get(0).equals("hostile")) { || args.get(0).equals("mob") || args.get(0).equals("custom"))) {
LegacyAgent.areCustomTypesHostile = true; LegacyAgent.customListMode = args.get(0);
sender.sendMessage("The custom mob list type has been set to " + ChatColor.BLUE + "hostile" + ChatColor.RESET + "."); sender.sendMessage(
} else if (args.size() > 0 && args.get(0).equals("passive")) { "Successfully set the custom mob list type to " + ChatColor.BLUE + args.get(0) + ChatColor.RESET + ".");
LegacyAgent.areCustomTypesHostile = false;
sender.sendMessage("The custom mob list type has been set to " + ChatColor.BLUE + "passive" + ChatColor.RESET + ".");
} else } else
sender.sendMessage("Usage: " + ChatColor.YELLOW + "/botenvironment mobListType (hostile|passive)" + ChatColor.RESET); sender.sendMessage("Usage: " + ChatColor.YELLOW + "/botenvironment mobListType (hostile|raider|mob|custom)" + ChatColor.RESET);
} }
@Autofill @Autofill
@@ -374,7 +372,9 @@ public class BotEnvironmentCommand extends CommandInstance {
output.add(type.name()); output.add(type.name());
} else if (matches(args[0], "mobListType")) { } else if (matches(args[0], "mobListType")) {
output.add("hostile"); output.add("hostile");
output.add("passive"); output.add("raider");
output.add("mob");
output.add("custom");
} }
} }
return output; return output;