added single player target

This commit is contained in:
Badbird-5907
2022-08-11 19:25:25 -04:00
parent 2dd068186f
commit 14f245ae57
4 changed files with 32 additions and 4 deletions

View File

@@ -11,6 +11,8 @@ import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
import java.util.UUID;
public interface Terminator {
String getBotName();
@@ -110,4 +112,8 @@ public interface Terminator {
void renderBot(Object packetListener, boolean login);
void setOnFirePackets(boolean onFire);
UUID getTargetPlayer();
void setTargetPlayer(UUID target);
}

View File

@@ -11,9 +11,10 @@ public enum EnumTargetGoal {
NEAREST_BOT("Locate the nearest bot."),
NEAREST_BOT_DIFFER("Locate the nearest bot with a different username."),
NEAREST_BOT_DIFFER_ALPHA("Locate the nearest bot with a different username after filtering out non-alpha characters."),
PLAYER("Target a single player. Defaults to NEAREST_VULNERABLE_PLAYER if no player found."),
NONE("No target goal.");
private static final Map<String, EnumTargetGoal> VALUES = new HashMap<String, EnumTargetGoal>() {
private static final Map<String, EnumTargetGoal> VALUES = new HashMap<>() {
{
this.put("none", NONE);
this.put("nearestvulnerableplayer", NEAREST_VULNERABLE_PLAYER);

View File

@@ -1115,10 +1115,12 @@ public class LegacyAgent extends Agent {
this.goal = goal;
}
public LivingEntity locateTarget(Terminator bot, Location loc) {
public LivingEntity locateTarget(Terminator bot, Location loc, EnumTargetGoal... targetGoal) {
LivingEntity result = null;
switch (goal) {
EnumTargetGoal g = goal;
if (targetGoal.length > 0) g = targetGoal[0];
switch (g) {
default:
return null;
@@ -1205,6 +1207,15 @@ public class LegacyAgent extends Agent {
}
}
}
case PLAYER: { //Target a single player. Defaults to NEAREST_VULNERABLE_PLAYER if no player found.
if (bot.getTargetPlayer() != null) {
Player player = Bukkit.getPlayer(bot.getTargetPlayer());
if (player != null) {
return player;
}
}
return locateTarget(bot, loc, EnumTargetGoal.NEAREST_VULNERABLE_PLAYER);
}
}
return result;