Add CustomListMode enum
This commit is contained in:
@@ -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("|"));
|
||||
}
|
||||
}
|
||||
@@ -58,7 +58,7 @@ public class LegacyAgent extends Agent {
|
||||
private double regionWeightZ;
|
||||
|
||||
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) {
|
||||
super(manager, plugin);
|
||||
@@ -1462,7 +1462,7 @@ public class LegacyAgent extends Agent {
|
||||
|
||||
case NEAREST_HOSTILE: {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1473,7 +1473,7 @@ public class LegacyAgent extends Agent {
|
||||
case NEAREST_RAIDER: {
|
||||
for (LivingEntity entity : bot.getBukkitEntity().getWorld().getLivingEntities()) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1483,7 +1483,7 @@ public class LegacyAgent extends Agent {
|
||||
|
||||
case NEAREST_MOB: {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1539,7 +1539,7 @@ public class LegacyAgent extends Agent {
|
||||
|
||||
case CUSTOM_LIST: {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.EntityType;
|
||||
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.LegacyMats;
|
||||
import net.nuggetmc.tplus.api.utils.ChatUtils;
|
||||
@@ -265,13 +266,12 @@ public class BotEnvironmentCommand extends CommandInstance {
|
||||
public void mobListType(CommandSender sender, List<String> args) {
|
||||
if (args.isEmpty()) {
|
||||
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")
|
||||
|| args.get(0).equals("mob") || args.get(0).equals("custom"))) {
|
||||
LegacyAgent.customListMode = args.get(0);
|
||||
} else if (args.size() > 0 && CustomListMode.isValid(args.get(0))) {
|
||||
LegacyAgent.customListMode = CustomListMode.from(args.get(0));
|
||||
sender.sendMessage(
|
||||
"Successfully set the custom mob list type to " + ChatColor.BLUE + args.get(0) + ChatColor.RESET + ".");
|
||||
} 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
|
||||
@@ -290,10 +290,8 @@ public class BotEnvironmentCommand extends CommandInstance {
|
||||
if (type != EntityType.UNKNOWN)
|
||||
output.add(type.name());
|
||||
} else if (matches(args[0], "mobListType")) {
|
||||
output.add("hostile");
|
||||
output.add("raider");
|
||||
output.add("mob");
|
||||
output.add("custom");
|
||||
for (CustomListMode mode : CustomListMode.values())
|
||||
output.add(mode.name().toLowerCase(Locale.ENGLISH));
|
||||
}
|
||||
}
|
||||
return output;
|
||||
|
||||
Reference in New Issue
Block a user