Add CustomListMode enum

This commit is contained in:
ThisTestUser
2024-09-25 18:07:27 -04:00
parent 77b9915b39
commit dbfdef89ac
3 changed files with 39 additions and 13 deletions

View File

@@ -0,0 +1,28 @@
package net.nuggetmc.tplus.api.agent.legacyagent;
import java.util.Arrays;
import java.util.stream.Collectors;
public enum CustomListMode {
HOSTILE,
RAIDER,
MOB,
CUSTOM;
public static boolean isValid(String name) {
return from(name) != null;
}
public static CustomListMode from(String name) {
for (CustomListMode mode : values()) {
if (mode.name().equalsIgnoreCase(name)) {
return mode;
}
}
return null;
}
public static String listModes() {
return Arrays.stream(values()).map(e -> e.name().toLowerCase()).collect(Collectors.joining("|"));
}
}

View File

@@ -58,7 +58,7 @@ public class LegacyAgent extends Agent {
private double regionWeightZ; private double regionWeightZ;
public static final Set<EntityType> CUSTOM_MOB_LIST = new HashSet<>(); public static final Set<EntityType> CUSTOM_MOB_LIST = new HashSet<>();
public static String customListMode = "custom"; public static CustomListMode customListMode = CustomListMode.CUSTOM;
public LegacyAgent(BotManager manager, Plugin plugin) { public LegacyAgent(BotManager manager, Plugin plugin) {
super(manager, plugin); super(manager, plugin);
@@ -1462,7 +1462,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 || (customListMode.equals("hostile") && CUSTOM_MOB_LIST.contains(entity.getType()))) && validateCloserEntity(entity, loc, result)) { if ((entity instanceof Monster || (customListMode == CustomListMode.HOSTILE && CUSTOM_MOB_LIST.contains(entity.getType()))) && validateCloserEntity(entity, loc, result)) {
result = entity; result = entity;
} }
} }
@@ -1473,7 +1473,7 @@ 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()) {
boolean raider = entity instanceof Raider || (entity instanceof Vex vex && vex.getSummoner() instanceof Raider); 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)) { if ((raider || (customListMode == CustomListMode.RAIDER && CUSTOM_MOB_LIST.contains(entity.getType()))) && validateCloserEntity(entity, loc, result)) {
result = entity; result = entity;
} }
} }
@@ -1483,7 +1483,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 || (customListMode.equals("mob") && CUSTOM_MOB_LIST.contains(entity.getType()))) && validateCloserEntity(entity, loc, result)) { if ((entity instanceof Mob || (customListMode == CustomListMode.MOB && CUSTOM_MOB_LIST.contains(entity.getType()))) && validateCloserEntity(entity, loc, result)) {
result = entity; result = entity;
} }
} }
@@ -1539,7 +1539,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 (customListMode.equals("custom") && CUSTOM_MOB_LIST.contains(entity.getType()) && validateCloserEntity(entity, loc, result)) { if (customListMode == CustomListMode.CUSTOM && CUSTOM_MOB_LIST.contains(entity.getType()) && validateCloserEntity(entity, loc, result)) {
result = entity; result = entity;
} }
} }

View File

@@ -10,6 +10,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import net.nuggetmc.tplus.api.agent.legacyagent.CustomListMode;
import net.nuggetmc.tplus.api.agent.legacyagent.LegacyAgent; import net.nuggetmc.tplus.api.agent.legacyagent.LegacyAgent;
import net.nuggetmc.tplus.api.agent.legacyagent.LegacyMats; import net.nuggetmc.tplus.api.agent.legacyagent.LegacyMats;
import net.nuggetmc.tplus.api.utils.ChatUtils; import net.nuggetmc.tplus.api.utils.ChatUtils;
@@ -265,13 +266,12 @@ public class BotEnvironmentCommand extends CommandInstance {
public void mobListType(CommandSender sender, List<String> args) { public void mobListType(CommandSender sender, List<String> args) {
if (args.isEmpty()) { if (args.isEmpty()) {
sender.sendMessage("The custom mob list type is " + ChatColor.BLUE + LegacyAgent.customListMode + ChatColor.RESET + "."); sender.sendMessage("The custom mob list type is " + ChatColor.BLUE + LegacyAgent.customListMode + ChatColor.RESET + ".");
} else if (args.size() > 0 && (args.get(0).equals("hostile") || args.get(0).equals("raider") } else if (args.size() > 0 && CustomListMode.isValid(args.get(0))) {
|| args.get(0).equals("mob") || args.get(0).equals("custom"))) { LegacyAgent.customListMode = CustomListMode.from(args.get(0));
LegacyAgent.customListMode = args.get(0);
sender.sendMessage( sender.sendMessage(
"Successfully set the custom mob list type to " + ChatColor.BLUE + args.get(0) + ChatColor.RESET + "."); "Successfully set the custom mob list type to " + ChatColor.BLUE + args.get(0) + ChatColor.RESET + ".");
} else } else
sender.sendMessage("Usage: " + ChatColor.YELLOW + "/botenvironment mobListType (hostile|raider|mob|custom)" + ChatColor.RESET); sender.sendMessage("Usage: " + ChatColor.YELLOW + "/botenvironment mobListType (" + CustomListMode.listModes() + ")" + ChatColor.RESET);
} }
@Autofill @Autofill
@@ -290,10 +290,8 @@ public class BotEnvironmentCommand extends CommandInstance {
if (type != EntityType.UNKNOWN) if (type != EntityType.UNKNOWN)
output.add(type.name()); output.add(type.name());
} else if (matches(args[0], "mobListType")) { } else if (matches(args[0], "mobListType")) {
output.add("hostile"); for (CustomListMode mode : CustomListMode.values())
output.add("raider"); output.add(mode.name().toLowerCase(Locale.ENGLISH));
output.add("mob");
output.add("custom");
} }
} }
return output; return output;