diff --git a/LICENSE b/LICENSE
index eab556a..74bdf5c 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
MIT License
-Copyright (c) 2021 batchprogrammer314
+Copyright (c) 2021 HorseNuggets
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/pom.xml b/pom.xml
index 65e790c..f720484 100644
--- a/pom.xml
+++ b/pom.xml
@@ -43,6 +43,14 @@
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+ 2.3.1
+
+ D:\Minecraft Server\plugins
+
+
diff --git a/src/main/java/net/nuggetmc/ai/bot/Bot.java b/src/main/java/net/nuggetmc/ai/bot/Bot.java
index 8f57605..227d70e 100644
--- a/src/main/java/net/nuggetmc/ai/bot/Bot.java
+++ b/src/main/java/net/nuggetmc/ai/bot/Bot.java
@@ -2,6 +2,8 @@ package net.nuggetmc.ai.bot;
import com.mojang.authlib.GameProfile;
import com.mojang.datafixers.util.Pair;
+import io.netty.util.concurrent.Future;
+import io.netty.util.concurrent.GenericFutureListener;
import net.minecraft.server.v1_16_R3.Chunk;
import net.minecraft.server.v1_16_R3.*;
import net.nuggetmc.ai.TerminatorPlus;
@@ -27,6 +29,7 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitScheduler;
import org.bukkit.util.Vector;
+import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Objects;
@@ -105,7 +108,13 @@ public class Bot extends EntityPlayer {
Bot bot = new Bot(nmsServer, nmsWorld, profile, interactManager);
- bot.playerConnection = new PlayerConnection(nmsServer, new NetworkManager(EnumProtocolDirection.CLIENTBOUND), bot);
+ bot.playerConnection = new PlayerConnection(nmsServer, new NetworkManager(EnumProtocolDirection.CLIENTBOUND) {
+
+ @Override
+ public void sendPacket(Packet> packet, @Nullable GenericFutureListener extends Future super Void>> genericfuturelistener) { }
+
+ }, bot);
+
bot.setLocation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
bot.getBukkitEntity().setNoDamageTicks(0);
nmsWorld.addEntity(bot);
@@ -234,7 +243,7 @@ public class Bot extends EntityPlayer {
Chunk chunk = world.getChunkAt(i, j);
if (!chunk.loaded) {
- chunk.setLoaded(true);
+ chunk.loaded = true;
}
}
}
@@ -400,8 +409,10 @@ public class Bot extends EntityPlayer {
faceLocation(entity.getLocation());
punch();
+ double damage = ItemUtils.getLegacyAttackDamage(defaultItem);
+
if (entity instanceof Damageable) {
- ((Damageable) entity).damage(ItemUtils.getLegacyAttackDamage(defaultItem), getBukkitEntity());
+ ((Damageable) entity).damage(damage, getBukkitEntity());
}
}
@@ -472,6 +483,8 @@ public class Bot extends EntityPlayer {
}
private void setDead() {
+ sendPacket(new PacketPlayOutEntityDestroy(getId()));
+
this.dead = true;
this.defaultContainer.b(this);
if (this.activeContainer != null) {
@@ -481,7 +494,7 @@ public class Bot extends EntityPlayer {
private void dieCheck() {
if (removeOnDeath) {
- scheduler.runTask(plugin, () -> plugin.getManager().remove(this));
+ scheduler.runTask(plugin, () -> plugin.getManager().remove(this)); // maybe making this later will fix the concurrentmodificationexception?
scheduler.runTaskLater(plugin, this::setDead, 30);
this.removeTab();
diff --git a/src/main/java/net/nuggetmc/ai/bot/BotManager.java b/src/main/java/net/nuggetmc/ai/bot/BotManager.java
index cf2edb0..2d20e00 100644
--- a/src/main/java/net/nuggetmc/ai/bot/BotManager.java
+++ b/src/main/java/net/nuggetmc/ai/bot/BotManager.java
@@ -111,7 +111,7 @@ public class BotManager implements Listener {
bot.setNeuralNetwork(network == NeuralNetwork.RANDOM ? NeuralNetwork.generateRandomNetwork() : network);
bot.setShield(true);
bot.setDefaultItem(new ItemStack(Material.WOODEN_AXE));
- bot.setRemoveOnDeath(false);
+ //bot.setRemoveOnDeath(false);
}
if (network != null) {
@@ -140,11 +140,12 @@ public class BotManager implements Listener {
}
public void reset() {
- bots.forEach(Bot::removeVisually);
- bots.clear(); // Not always necessary, but a good security measure
- agent.stopAllTasks();
+ if (!bots.isEmpty()) {
+ bots.forEach(Bot::removeVisually);
+ bots.clear(); // Not always necessary, but a good security measure
+ }
- System.gc();
+ agent.stopAllTasks();
}
public Bot getBot(Player player) { // potentially memory intensive
diff --git a/src/main/java/net/nuggetmc/ai/bot/agent/Agent.java b/src/main/java/net/nuggetmc/ai/bot/agent/Agent.java
index e182a30..a64ed77 100644
--- a/src/main/java/net/nuggetmc/ai/bot/agent/Agent.java
+++ b/src/main/java/net/nuggetmc/ai/bot/agent/Agent.java
@@ -55,8 +55,10 @@ public abstract class Agent {
}
public void stopAllTasks() {
- taskList.stream().filter(t -> !t.isCancelled()).forEach(BukkitRunnable::cancel);
- taskList.clear();
+ if (!taskList.isEmpty()) {
+ taskList.stream().filter(t -> !t.isCancelled()).forEach(BukkitRunnable::cancel);
+ taskList.clear();
+ }
}
public void setDrops(boolean enabled) {
diff --git a/src/main/java/net/nuggetmc/ai/bot/agent/legacyagent/EnumTargetGoal.java b/src/main/java/net/nuggetmc/ai/bot/agent/legacyagent/EnumTargetGoal.java
index 5d1d2ca..94e2454 100644
--- a/src/main/java/net/nuggetmc/ai/bot/agent/legacyagent/EnumTargetGoal.java
+++ b/src/main/java/net/nuggetmc/ai/bot/agent/legacyagent/EnumTargetGoal.java
@@ -1,32 +1,38 @@
package net.nuggetmc.ai.bot.agent.legacyagent;
-public enum EnumTargetGoal { // TODO USE ORDINAL!!!!!
- NEAREST_REAL_VULNERABLE_PLAYER,
- NEAREST_REAL_PLAYER,
- NEAREST_BOT_DIFFER,
- NEAREST_BOT,
- NEAREST_BOT_DIFFER_ALPHA,
- NONE;
+import java.util.HashMap;
+import java.util.Map;
- public static EnumTargetGoal of(int n) {
- switch (n) {
- default:
- return NONE;
+public enum EnumTargetGoal {
+ NEAREST_VULNERABLE_PLAYER("Locate the nearest real player that is in either Survival or Adventure mode."),
+ NEAREST_PLAYER("Locate the nearest real online player, despite the gamemode."),
+ 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."),
+ NONE("No target goal.");
- case 1:
- return NEAREST_REAL_VULNERABLE_PLAYER;
-
- case 2:
- return NEAREST_REAL_PLAYER;
-
- case 3:
- return NEAREST_BOT_DIFFER;
-
- case 4:
- return NEAREST_BOT;
-
- case 5:
- return NEAREST_BOT_DIFFER_ALPHA;
+ private static final Map VALUES = new HashMap() {
+ {
+ this.put("none", NONE);
+ this.put("nearestvulnerableplayer", NEAREST_VULNERABLE_PLAYER);
+ this.put("nearestplayer", NEAREST_PLAYER);
+ this.put("nearestbot", NEAREST_BOT);
+ this.put("nearestbotdiffer", NEAREST_BOT_DIFFER);
+ this.put("nearestbotdifferalpha", NEAREST_BOT_DIFFER_ALPHA);
}
+ };
+
+ private final String description;
+
+ EnumTargetGoal(String description) {
+ this.description = description;
+ }
+
+ public static EnumTargetGoal from(String name) {
+ return VALUES.get(name);
+ }
+
+ public String description() {
+ return description;
}
}
diff --git a/src/main/java/net/nuggetmc/ai/bot/agent/legacyagent/LegacyAgent.java b/src/main/java/net/nuggetmc/ai/bot/agent/legacyagent/LegacyAgent.java
index ca42532..c9d5acd 100644
--- a/src/main/java/net/nuggetmc/ai/bot/agent/legacyagent/LegacyAgent.java
+++ b/src/main/java/net/nuggetmc/ai/bot/agent/legacyagent/LegacyAgent.java
@@ -11,7 +11,6 @@ import net.nuggetmc.ai.bot.agent.legacyagent.ai.NeuralNetwork;
import net.nuggetmc.ai.bot.event.BotDamageByPlayerEvent;
import net.nuggetmc.ai.bot.event.BotDeathEvent;
import net.nuggetmc.ai.bot.event.BotFallDamageEvent;
-import net.nuggetmc.ai.bot.event.BotKilledByPlayerEvent;
import net.nuggetmc.ai.utils.MathUtils;
import net.nuggetmc.ai.utils.PlayerUtils;
import org.bukkit.*;
@@ -35,12 +34,14 @@ public class LegacyAgent extends Agent {
private final LegacyBlockCheck blockCheck;
+ private EnumTargetGoal goal;
+
public boolean offsets = true;
public LegacyAgent(BotManager manager) {
super(manager);
- this.goal = EnumTargetGoal.NEAREST_REAL_VULNERABLE_PLAYER;
+ this.goal = EnumTargetGoal.NEAREST_VULNERABLE_PLAYER;
this.blockCheck = new LegacyBlockCheck(this);
}
@@ -93,17 +94,18 @@ public class LegacyAgent extends Agent {
}
private void tickBot(Bot bot) {
- if (!bot.isAlive()) return;
+ if (!bot.isAlive()) {
+ return;
+ }
if (bot.tickDelay(20)) {
center(bot);
}
Location loc = bot.getLocation();
+ Player player = locateTarget(bot, loc);
- Player player = nearestPlayer(bot, loc);
if (player == null) {
- // LESSLAG if (bot.tickDelay(20))
stopMining(bot);
return;
}
@@ -114,33 +116,28 @@ public class LegacyAgent extends Agent {
miscellaneousChecks(bot, player);
Player botPlayer = bot.getBukkitEntity();
-
Location target = offsets ? player.getLocation().add(bot.getOffset()) : player.getLocation();
- NeuralNetwork network;
boolean ai = bot.hasNeuralNetwork();
- if (ai) {
- BotData data = BotData.generate(bot, player);
+ NeuralNetwork network = ai ? bot.getNeuralNetwork() : null;
- network = bot.getNeuralNetwork();
- network.feed(data);
- } else {
- network = null;
+ if (ai) {
+ network.feed(BotData.generate(bot, player));
}
if (bot.tickDelay(3) && !miningAnim.containsKey(botPlayer)) {
- Location a = botPlayer.getEyeLocation();
- Location b = player.getEyeLocation();
- Location c1 = player.getLocation();
+ Location botEyeLoc = botPlayer.getEyeLocation();
+ Location playerEyeLoc = player.getEyeLocation();
+ Location playerLoc = player.getLocation();
- if (ai) { // force unable to block if they are more than 6/7 blocks away
+ if (ai) {
if (network.check(BotNode.BLOCK) && loc.distance(player.getLocation()) < 6) {
bot.block(10, 10);
}
}
- if (LegacyUtils.checkFreeSpace(a, b) || LegacyUtils.checkFreeSpace(a, c1)) {
+ if (LegacyUtils.checkFreeSpace(botEyeLoc, playerEyeLoc) || LegacyUtils.checkFreeSpace(botEyeLoc, playerLoc)) {
attack(bot, player, loc);
}
}
@@ -1124,93 +1121,78 @@ public class LegacyAgent extends Agent {
bot.attack(player);
}
- private EnumTargetGoal goal;
-
public void setTargetType(EnumTargetGoal goal) {
this.goal = goal;
}
- private Player nearestPlayer(Bot bot, Location loc) {
+ public Player locateTarget(Bot bot, Location loc) {
+ Player result = null;
+
switch (goal) {
- case NEAREST_REAL_VULNERABLE_PLAYER:
- return nearestRealVulnerablePlayer(loc);
-
- case NEAREST_REAL_PLAYER:
- return nearestRealPlayer(loc);
-
- case NEAREST_BOT_DIFFER:
- return nearestBotDiffer(bot, loc);
-
- case NEAREST_BOT_DIFFER_ALPHA:
- return nearestBotDifferAlpha(bot, loc);
-
- case NEAREST_BOT:
- return nearestBot(bot, loc);
-
default:
return null;
- }
- }
- private Player nearestRealPlayer(Location loc) {
- Player result = null;
+ case NEAREST_PLAYER: {
+ for (Player player : Bukkit.getOnlinePlayers()) {
+ if (validateCloserPlayer(player, loc, result)) {
+ result = player;
+ }
+ }
- for (Player player : Bukkit.getOnlinePlayers()) {
- if (loc.getWorld() != player.getWorld() || player.isDead()) continue;
-
- if (result == null || loc.distance(player.getLocation()) < loc.distance(result.getLocation())) {
- result = player;
+ break;
}
- }
- return result;
- }
+ case NEAREST_VULNERABLE_PLAYER: {
+ for (Player player : Bukkit.getOnlinePlayers()) {
+ if (!PlayerUtils.isInvincible(player.getGameMode()) && validateCloserPlayer(player, loc, result)) {
+ result = player;
+ }
+ }
- private Player nearestRealVulnerablePlayer(Location loc) {
- Player result = null;
-
- for (Player player : Bukkit.getOnlinePlayers()) {
- if (PlayerUtils.isInvincible(player.getGameMode()) || loc.getWorld() != player.getWorld() || player.isDead()) continue;
-
- if (result == null || loc.distance(player.getLocation()) < loc.distance(result.getLocation())) {
- result = player;
+ break;
}
- }
- return result;
- }
+ case NEAREST_BOT: {
+ for (Bot otherBot : manager.fetch()) {
+ if (bot != otherBot) {
+ Player player = otherBot.getBukkitEntity();
- private Player nearestBot(Bot bot, Location loc) {
- Player result = null;
+ if (validateCloserPlayer(player, loc, result)) {
+ result = player;
+ }
+ }
+ }
- for (Bot otherBot : manager.fetch()) {
- if (bot == otherBot) continue;
-
- Player player = otherBot.getBukkitEntity();
-
- if (loc.getWorld() != player.getWorld() || player.isDead()) continue;
-
- if (result == null || loc.distance(player.getLocation()) < loc.distance(result.getLocation())) {
- result = player;
+ break;
}
- }
- return result;
- }
+ case NEAREST_BOT_DIFFER: {
+ String name = bot.getName();
- private Player nearestBotDiffer(Bot bot, Location loc) {
- Player result = null;
+ for (Bot otherBot : manager.fetch()) {
+ if (bot != otherBot) {
+ Player player = otherBot.getBukkitEntity();
- for (Bot otherBot : manager.fetch()) {
- if (bot == otherBot) continue;
+ if (!name.equals(otherBot.getName()) && validateCloserPlayer(player, loc, result)) {
+ result = player;
+ }
+ }
+ }
- Player player = otherBot.getBukkitEntity();
+ break;
+ }
- if (!bot.getName().equals(otherBot.getName())) {
- if (loc.getWorld() != player.getWorld() || player.isDead()) continue;
+ case NEAREST_BOT_DIFFER_ALPHA: {
+ String name = bot.getName().replaceAll("[^A-Za-z]+", "");
- if (result == null || loc.distance(player.getLocation()) < loc.distance(result.getLocation())) {
- result = player;
+ for (Bot otherBot : manager.fetch()) {
+ if (bot != otherBot) {
+ Player player = otherBot.getBukkitEntity();
+
+ if (!name.equals(otherBot.getName().replaceAll("[^A-Za-z]+", "")) && validateCloserPlayer(player, loc, result)) {
+ result = player;
+ }
+ }
}
}
}
@@ -1218,23 +1200,7 @@ public class LegacyAgent extends Agent {
return result;
}
- private Player nearestBotDifferAlpha(Bot bot, Location loc) {
- Player result = null;
-
- for (Bot otherBot : manager.fetch()) {
- if (bot == otherBot) continue;
-
- Player player = otherBot.getBukkitEntity();
-
- if (!bot.getName().replaceAll("[^A-Za-z]+", "").equals(otherBot.getName().replaceAll("[^A-Za-z]+", ""))) {
- if (loc.getWorld() != player.getWorld() || player.isDead()) continue;
-
- if (result == null || loc.distance(player.getLocation()) < loc.distance(result.getLocation())) {
- result = player;
- }
- }
- }
-
- return result;
+ private boolean validateCloserPlayer(Player player, Location loc, Player result) {
+ return loc.getWorld() == player.getWorld() && !player.isDead() && (result == null || loc.distance(player.getLocation()) < loc.distance(result.getLocation()));
}
}
diff --git a/src/main/java/net/nuggetmc/ai/bot/agent/legacyagent/LegacyWorldManager.java b/src/main/java/net/nuggetmc/ai/bot/agent/legacyagent/LegacyWorldManager.java
index 1888be7..f7c6e20 100644
--- a/src/main/java/net/nuggetmc/ai/bot/agent/legacyagent/LegacyWorldManager.java
+++ b/src/main/java/net/nuggetmc/ai/bot/agent/legacyagent/LegacyWorldManager.java
@@ -5,6 +5,10 @@ import org.bukkit.Material;
public class LegacyWorldManager {
+ /*
+ * This is where the respawning queue will be managed
+ */
+
public static boolean aboveGround(Location loc) {
int y = 1;
diff --git a/src/main/java/net/nuggetmc/ai/bot/agent/legacyagent/ai/IntelligenceAgent.java b/src/main/java/net/nuggetmc/ai/bot/agent/legacyagent/ai/IntelligenceAgent.java
index c7b0622..79cc455 100644
--- a/src/main/java/net/nuggetmc/ai/bot/agent/legacyagent/ai/IntelligenceAgent.java
+++ b/src/main/java/net/nuggetmc/ai/bot/agent/legacyagent/ai/IntelligenceAgent.java
@@ -29,6 +29,7 @@ public class IntelligenceAgent {
* commands /ai stop and /ai pause
* if a session with name already exists keep adding underscores
* /ai conclude or /ai finish
+ * default anchor location, /ai relocateanchor
*/
private final TerminatorPlus plugin;
@@ -54,7 +55,6 @@ public class IntelligenceAgent {
private Player primary;
private final Set users;
-
private final Map>>> genProfiles;
public IntelligenceAgent(AICommand aiManager, int populationSize, String name, String skin) {
@@ -215,7 +215,7 @@ public class IntelligenceAgent {
Set