diff --git a/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/Terminator.java b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/Terminator.java index 615b948..9d368d2 100644 --- a/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/Terminator.java +++ b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/Terminator.java @@ -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); } diff --git a/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/EnumTargetGoal.java b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/EnumTargetGoal.java index 1f9c71e..c2e8a1c 100644 --- a/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/EnumTargetGoal.java +++ b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/EnumTargetGoal.java @@ -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 VALUES = new HashMap() { + private static final Map VALUES = new HashMap<>() { { this.put("none", NONE); this.put("nearestvulnerableplayer", NEAREST_VULNERABLE_PLAYER); diff --git a/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/LegacyAgent.java b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/LegacyAgent.java index bbc8213..fe558d3 100644 --- a/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/LegacyAgent.java +++ b/TerminatorPlus-API/src/main/java/net/nuggetmc/tplus/api/agent/legacyagent/LegacyAgent.java @@ -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; diff --git a/TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/bot/Bot.java b/TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/bot/Bot.java index a15c04e..017176f 100644 --- a/TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/bot/Bot.java +++ b/TerminatorPlus-Plugin/src/main/java/net/nuggetmc/tplus/bot/Bot.java @@ -73,7 +73,7 @@ public class Bot extends ServerPlayer implements Terminator { private byte jumpTicks; private byte noFallTicks; private boolean ignoredByMobs = true; - + private UUID targetPlayer = null; private Bot(MinecraftServer minecraftServer, ServerLevel worldServer, GameProfile profile) { super(minecraftServer, worldServer, profile, null); @@ -373,6 +373,16 @@ public class Bot extends ServerPlayer implements Terminator { //sendPacket(new ClientboundSetEntityDataPacket(getId(), entityData, false)); } + @Override + public UUID getTargetPlayer() { + return targetPlayer; + } + + @Override + public void setTargetPlayer(UUID target) { + this.targetPlayer = target; + } + @Override public boolean isBotOnFire() { return fireTicks != 0;