ooops
This commit is contained in:
2
LICENSE
2
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
|
||||
|
||||
8
pom.xml
8
pom.xml
@@ -43,6 +43,14 @@
|
||||
</transformers>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.3.1</version>
|
||||
<configuration>
|
||||
<outputDirectory>D:\Minecraft Server\plugins</outputDirectory>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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() {
|
||||
if (!bots.isEmpty()) {
|
||||
bots.forEach(Bot::removeVisually);
|
||||
bots.clear(); // Not always necessary, but a good security measure
|
||||
agent.stopAllTasks();
|
||||
}
|
||||
|
||||
System.gc();
|
||||
agent.stopAllTasks();
|
||||
}
|
||||
|
||||
public Bot getBot(Player player) { // potentially memory intensive
|
||||
|
||||
@@ -55,9 +55,11 @@ public abstract class Agent {
|
||||
}
|
||||
|
||||
public void stopAllTasks() {
|
||||
if (!taskList.isEmpty()) {
|
||||
taskList.stream().filter(t -> !t.isCancelled()).forEach(BukkitRunnable::cancel);
|
||||
taskList.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public void setDrops(boolean enabled) {
|
||||
this.drops = enabled;
|
||||
|
||||
@@ -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<String, EnumTargetGoal> VALUES = new HashMap<String, EnumTargetGoal>() {
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,117 +1121,86 @@ 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 (loc.getWorld() != player.getWorld() || player.isDead()) continue;
|
||||
|
||||
if (result == null || loc.distance(player.getLocation()) < loc.distance(result.getLocation())) {
|
||||
if (validateCloserPlayer(player, loc, result)) {
|
||||
result = player;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
break;
|
||||
}
|
||||
|
||||
private Player nearestRealVulnerablePlayer(Location loc) {
|
||||
Player result = null;
|
||||
|
||||
case NEAREST_VULNERABLE_PLAYER: {
|
||||
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())) {
|
||||
if (!PlayerUtils.isInvincible(player.getGameMode()) && validateCloserPlayer(player, loc, result)) {
|
||||
result = player;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
break;
|
||||
}
|
||||
|
||||
private Player nearestBot(Bot bot, Location loc) {
|
||||
Player result = null;
|
||||
|
||||
case NEAREST_BOT: {
|
||||
for (Bot otherBot : manager.fetch()) {
|
||||
if (bot == otherBot) continue;
|
||||
|
||||
if (bot != otherBot) {
|
||||
Player player = otherBot.getBukkitEntity();
|
||||
|
||||
if (loc.getWorld() != player.getWorld() || player.isDead()) continue;
|
||||
|
||||
if (result == null || loc.distance(player.getLocation()) < loc.distance(result.getLocation())) {
|
||||
if (validateCloserPlayer(player, loc, result)) {
|
||||
result = player;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private Player nearestBotDiffer(Bot bot, Location loc) {
|
||||
Player result = null;
|
||||
break;
|
||||
}
|
||||
|
||||
case NEAREST_BOT_DIFFER: {
|
||||
String name = bot.getName();
|
||||
|
||||
for (Bot otherBot : manager.fetch()) {
|
||||
if (bot == otherBot) continue;
|
||||
|
||||
if (bot != otherBot) {
|
||||
Player player = otherBot.getBukkitEntity();
|
||||
|
||||
if (!bot.getName().equals(otherBot.getName())) {
|
||||
if (loc.getWorld() != player.getWorld() || player.isDead()) continue;
|
||||
|
||||
if (result == null || loc.distance(player.getLocation()) < loc.distance(result.getLocation())) {
|
||||
if (!name.equals(otherBot.getName()) && validateCloserPlayer(player, loc, result)) {
|
||||
result = player;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
break;
|
||||
}
|
||||
|
||||
private Player nearestBotDifferAlpha(Bot bot, Location loc) {
|
||||
Player result = null;
|
||||
case NEAREST_BOT_DIFFER_ALPHA: {
|
||||
String name = bot.getName().replaceAll("[^A-Za-z]+", "");
|
||||
|
||||
for (Bot otherBot : manager.fetch()) {
|
||||
if (bot == otherBot) continue;
|
||||
|
||||
if (bot != otherBot) {
|
||||
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())) {
|
||||
if (!name.equals(otherBot.getName().replaceAll("[^A-Za-z]+", "")) && validateCloserPlayer(player, loc, result)) {
|
||||
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()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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<CommandSender> users;
|
||||
|
||||
private final Map<Integer, Set<Map<BotNode, Map<BotDataType, Double>>>> genProfiles;
|
||||
|
||||
public IntelligenceAgent(AICommand aiManager, int populationSize, String name, String skin) {
|
||||
@@ -215,7 +215,7 @@ public class IntelligenceAgent {
|
||||
|
||||
Set<Map<BotNode, Map<BotDataType, Double>>> profiles = new HashSet<>();
|
||||
|
||||
double mutationSize = MathUtils.getMutationSize(generation);
|
||||
double mutationSize = Math.pow(Math.E, 2); //MathUtils.getMutationSize(generation);
|
||||
|
||||
for (int j = 0; j < populationSize; j++) {
|
||||
Map<BotNode, Map<BotDataType, Double>> profile = new HashMap<>();
|
||||
@@ -272,6 +272,8 @@ public class IntelligenceAgent {
|
||||
}
|
||||
|
||||
public void addUser(CommandSender sender) {
|
||||
if (users.contains(sender)) return;
|
||||
|
||||
users.add(sender);
|
||||
print(sender.getName() + " has been added to the userlist.");
|
||||
|
||||
@@ -322,7 +324,14 @@ public class IntelligenceAgent {
|
||||
}
|
||||
|
||||
private void clearBots() {
|
||||
print("Removing all current bots...");
|
||||
if (!bots.isEmpty()) {
|
||||
print("Removing all cached bots...");
|
||||
|
||||
bots.values().forEach(Bot::removeVisually);
|
||||
bots.clear();
|
||||
}
|
||||
|
||||
/*print("Removing all current bots...");
|
||||
|
||||
int size = manager.fetch().size();
|
||||
manager.reset();
|
||||
@@ -330,6 +339,6 @@ public class IntelligenceAgent {
|
||||
String formatted = NumberFormat.getNumberInstance(Locale.US).format(size);
|
||||
print("Removed " + ChatColor.RED + formatted + ChatColor.RESET + " entit" + (size == 1 ? "y" : "ies") + ".");
|
||||
|
||||
bots.clear();
|
||||
bots.clear();*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package net.nuggetmc.ai.bot.agent.legacyagent.ai;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class NodeConnections {
|
||||
|
||||
@@ -30,7 +31,7 @@ public class NodeConnections {
|
||||
}
|
||||
|
||||
private double generateValue() {
|
||||
return Math.random() * 20 - 10;
|
||||
return ThreadLocalRandom.current().nextDouble(-10, 10);
|
||||
}
|
||||
|
||||
public boolean check() {
|
||||
|
||||
@@ -37,6 +37,7 @@ public class CommandHandler {
|
||||
this.commandMap = new HashMap<>();
|
||||
this.registerCommands();
|
||||
this.drink.registerCommands();
|
||||
this.commandMap.values().forEach(CommandInstance::onLoad);
|
||||
}
|
||||
|
||||
private void registerCommands() {
|
||||
@@ -52,7 +53,7 @@ public class CommandHandler {
|
||||
setHelp(handler.getClass());
|
||||
}
|
||||
|
||||
public CommandInstance getComand(String name) {
|
||||
public CommandInstance getCommand(String name) {
|
||||
return commandMap.get(name);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,4 +21,6 @@ public abstract class CommandInstance {
|
||||
public CommandHandler getCommandHandler() {
|
||||
return commandHandler;
|
||||
}
|
||||
|
||||
protected void onLoad() { }
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.nuggetmc.ai.command.commands;
|
||||
|
||||
import com.jonahseguin.drink.annotation.Autofill;
|
||||
import com.jonahseguin.drink.annotation.Command;
|
||||
import com.jonahseguin.drink.annotation.OptArg;
|
||||
import com.jonahseguin.drink.annotation.Sender;
|
||||
@@ -82,6 +83,10 @@ public class AICommand extends CommandInstance {
|
||||
agent.addUser(sender);
|
||||
}
|
||||
|
||||
public IntelligenceAgent getSession() {
|
||||
return agent;
|
||||
}
|
||||
|
||||
@Command(
|
||||
name = "stop",
|
||||
desc = "End a currently running AI training session."
|
||||
@@ -157,6 +162,7 @@ public class AICommand extends CommandInstance {
|
||||
});
|
||||
}
|
||||
|
||||
@Autofill
|
||||
public List<String> infoAutofill(CommandSender sender, String[] args) {
|
||||
if (args.length == 2) {
|
||||
return manager.fetchNames();
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
package net.nuggetmc.ai.command.commands;
|
||||
|
||||
import com.jonahseguin.drink.annotation.Command;
|
||||
import com.jonahseguin.drink.annotation.OptArg;
|
||||
import com.jonahseguin.drink.annotation.Sender;
|
||||
import com.jonahseguin.drink.annotation.Text;
|
||||
import com.jonahseguin.drink.annotation.*;
|
||||
import com.jonahseguin.drink.utils.ChatUtils;
|
||||
import net.nuggetmc.ai.TerminatorPlus;
|
||||
import net.nuggetmc.ai.bot.Bot;
|
||||
import net.nuggetmc.ai.bot.BotManager;
|
||||
import net.nuggetmc.ai.bot.agent.legacyagent.EnumTargetGoal;
|
||||
import net.nuggetmc.ai.bot.agent.legacyagent.LegacyAgent;
|
||||
import net.nuggetmc.ai.command.CommandHandler;
|
||||
import net.nuggetmc.ai.command.CommandInstance;
|
||||
import net.nuggetmc.ai.utils.Debugger;
|
||||
import net.nuggetmc.ai.utils.StringUtilities;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
@@ -20,15 +20,16 @@ import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class BotCommand extends CommandInstance {
|
||||
|
||||
private final TerminatorPlus plugin;
|
||||
private final CommandHandler handler;
|
||||
private final BotManager manager;
|
||||
private final LegacyAgent agent;
|
||||
private final BukkitScheduler scheduler;
|
||||
private final DecimalFormat formatter;
|
||||
|
||||
@@ -37,12 +38,17 @@ public class BotCommand extends CommandInstance {
|
||||
public BotCommand(CommandHandler commandHandler) {
|
||||
super(commandHandler);
|
||||
|
||||
this.handler = commandHandler;
|
||||
this.plugin = TerminatorPlus.getInstance();
|
||||
this.manager = plugin.getManager();
|
||||
this.agent = (LegacyAgent) manager.getAgent();
|
||||
this.scheduler = Bukkit.getScheduler();
|
||||
this.formatter = new DecimalFormat("0.##");
|
||||
}
|
||||
|
||||
scheduler.runTask(plugin, () -> aiManager = (AICommand) plugin.getHandler().getComand("ai"));
|
||||
@Override
|
||||
public void onLoad() {
|
||||
this.aiManager = (AICommand) handler.getCommand("ai");
|
||||
}
|
||||
|
||||
@Command(
|
||||
@@ -101,7 +107,7 @@ public class BotCommand extends CommandInstance {
|
||||
* current target
|
||||
* current kills
|
||||
* skin
|
||||
* neural network values
|
||||
* neural network values (network name if loaded, otherwise RANDOM)
|
||||
*/
|
||||
|
||||
String botName = bot.getName();
|
||||
@@ -125,12 +131,9 @@ public class BotCommand extends CommandInstance {
|
||||
});
|
||||
}
|
||||
|
||||
@Autofill
|
||||
public List<String> infoAutofill(CommandSender sender, String[] args) {
|
||||
if (args.length == 2) {
|
||||
return manager.fetchNames();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return args.length == 2 ? manager.fetchNames() : null;
|
||||
}
|
||||
|
||||
@Command(
|
||||
@@ -139,12 +142,9 @@ public class BotCommand extends CommandInstance {
|
||||
)
|
||||
public void reset(@Sender CommandSender sender) {
|
||||
sender.sendMessage("Removing every bot...");
|
||||
|
||||
int size = manager.fetch().size();
|
||||
manager.reset();
|
||||
|
||||
String formatted = NumberFormat.getNumberInstance(Locale.US).format(size);
|
||||
sender.sendMessage("Removed " + ChatColor.RED + formatted + ChatColor.RESET + " entit" + (size == 1 ? "y" : "ies") + ".");
|
||||
sender.sendMessage("Removed " + ChatColor.RED + StringUtilities.NUMBER_FORMAT.format(size) + ChatColor.RESET + " entit" + (size == 1 ? "y" : "ies") + ".");
|
||||
|
||||
if (aiManager.hasActiveSession()) {
|
||||
Bukkit.dispatchCommand(sender, "ai stop");
|
||||
@@ -152,26 +152,58 @@ public class BotCommand extends CommandInstance {
|
||||
}
|
||||
|
||||
@Command(
|
||||
name = "options",
|
||||
name = "settings",
|
||||
desc = "Make changes to the global configuration file and bot-specific settings.",
|
||||
aliases = "settings",
|
||||
autofill = "optionsAutofill"
|
||||
aliases = "options",
|
||||
autofill = "settingsAutofill"
|
||||
)
|
||||
public void options(@Sender CommandSender sender) {
|
||||
sender.sendMessage(ChatColor.YELLOW + "This feature is coming soon!");
|
||||
public void settings(@Sender CommandSender sender, @OptArg String arg1, @OptArg String arg2) {
|
||||
String extra = ChatColor.GRAY + " [" + ChatColor.YELLOW + "/bot settings" + ChatColor.GRAY + "]";
|
||||
|
||||
if (arg1 == null || !arg1.equals("setgoal")) {
|
||||
sender.sendMessage(ChatUtils.LINE);
|
||||
sender.sendMessage(ChatColor.GOLD + "Bot Settings" + extra);
|
||||
sender.sendMessage(ChatUtils.BULLET_FORMATTED + ChatColor.YELLOW + "setgoal" + ChatUtils.BULLET_FORMATTED + "Set the global bot target selection method.");
|
||||
sender.sendMessage(ChatUtils.LINE);
|
||||
return;
|
||||
}
|
||||
|
||||
public List<String> optionsAutofill(CommandSender sender, String[] args) {
|
||||
EnumTargetGoal goal = EnumTargetGoal.from(arg2 == null ? "" : arg2);
|
||||
|
||||
if (goal == null) {
|
||||
sender.sendMessage(ChatUtils.LINE);
|
||||
sender.sendMessage(ChatColor.GOLD + "Goal Selection Types" + extra);
|
||||
Arrays.stream(EnumTargetGoal.values()).forEach(g -> sender.sendMessage(ChatUtils.BULLET_FORMATTED + ChatColor.YELLOW + g.name().replace("_", "").toLowerCase()
|
||||
+ ChatUtils.BULLET_FORMATTED + g.description()));
|
||||
sender.sendMessage(ChatUtils.LINE);
|
||||
return;
|
||||
}
|
||||
|
||||
agent.setTargetType(goal);
|
||||
|
||||
sender.sendMessage("The global bot goal has been set to " + ChatColor.BLUE + goal.name() + ChatColor.RESET + ".");
|
||||
}
|
||||
|
||||
@Autofill
|
||||
public List<String> settingsAutofill(CommandSender sender, String[] args) {
|
||||
List<String> output = new ArrayList<>();
|
||||
|
||||
// More settings:
|
||||
// setitem
|
||||
// tpall
|
||||
// tprandom
|
||||
// hidenametags or nametags <show/hide>
|
||||
// sitall
|
||||
// lookall
|
||||
|
||||
if (args.length == 2) {
|
||||
output.add("setgoal");
|
||||
output.add("setitem");
|
||||
output.add("tpall");
|
||||
output.add("tprandom");
|
||||
output.add("hidenametags");
|
||||
output.add("sitall");
|
||||
output.add("lookall");
|
||||
}
|
||||
|
||||
else if (args.length == 3) {
|
||||
if (args[1].equalsIgnoreCase("setgoal")) {
|
||||
Arrays.stream(EnumTargetGoal.values()).forEach(goal -> output.add(goal.name().replace("_", "").toLowerCase()));
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
|
||||
@@ -57,7 +57,7 @@ public class MainCommand extends CommandInstance {
|
||||
message.event((ClickEvent) null);
|
||||
message.event((HoverEvent) null);
|
||||
message.append(ChatColor.BLUE + "Discord");
|
||||
message.event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "lol okay this isn't actually ready yet"));
|
||||
message.event(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://discord.gg/horsenuggets"));
|
||||
message.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text("Click to visit HorseNuggets' " + ChatColor.BLUE + "Discord" + ChatColor.RESET + "!")));
|
||||
message.append("\n");
|
||||
message.event((ClickEvent) null);
|
||||
|
||||
6
src/main/java/net/nuggetmc/ai/command/nms/TPCommand.java
Normal file
6
src/main/java/net/nuggetmc/ai/command/nms/TPCommand.java
Normal file
@@ -0,0 +1,6 @@
|
||||
package net.nuggetmc.ai.command.nms;
|
||||
|
||||
public class TPCommand {
|
||||
// this class (as well as some others like "give", "effect", etc.) will listen into the PlayerCommandPreProcessEvent
|
||||
// and will perform the actions accordingly to the bots as well as the real players
|
||||
}
|
||||
@@ -4,8 +4,9 @@ import net.minecraft.server.v1_16_R3.EntityLiving;
|
||||
import net.nuggetmc.ai.TerminatorPlus;
|
||||
import net.nuggetmc.ai.bot.Bot;
|
||||
import net.nuggetmc.ai.bot.agent.Agent;
|
||||
import net.nuggetmc.ai.bot.agent.legacyagent.EnumTargetGoal;
|
||||
import net.nuggetmc.ai.bot.agent.legacyagent.LegacyAgent;
|
||||
import net.nuggetmc.ai.bot.agent.legacyagent.ai.IntelligenceAgent;
|
||||
import net.nuggetmc.ai.command.commands.AICommand;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.ArmorStand;
|
||||
@@ -96,6 +97,41 @@ public class Debugger {
|
||||
* DEBUGGER METHODS
|
||||
*/
|
||||
|
||||
public void colorTest() {
|
||||
Player player = (Player) sender;
|
||||
Location loc = player.getLocation();
|
||||
|
||||
String[] skin = MojangAPI.getSkin("Kubepig");
|
||||
|
||||
TerminatorPlus plugin = TerminatorPlus.getInstance();
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
for (int n = 1; n <= 40; n++) {
|
||||
int wait = (int) (Math.pow(1.05, 130 - n) + 100);
|
||||
|
||||
try {
|
||||
Thread.sleep(wait);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Bukkit.getScheduler().runTask(plugin, () -> Bot.createBot(PlayerUtils.findBottom(loc.clone().add(Math.random() * 20 - 10, 0, Math.random() * 20 - 10)), ChatColor.GREEN + "-$26.95", skin));
|
||||
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_ITEM_PICKUP, 1, 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void tpall() {
|
||||
Player player = (Player) sender;
|
||||
TerminatorPlus.getInstance().getManager().fetch().stream().filter(EntityLiving::isAlive).forEach(bot -> bot.getBukkitEntity().teleport(player));
|
||||
}
|
||||
|
||||
public void viewsession() {
|
||||
IntelligenceAgent session = ((AICommand) TerminatorPlus.getInstance().getHandler().getCommand("ai")).getSession();
|
||||
Bukkit.getOnlinePlayers().stream().filter(ServerOperator::isOp).forEach(session::addUser);
|
||||
}
|
||||
|
||||
public void block() {
|
||||
TerminatorPlus.getInstance().getManager().fetch().forEach(bot -> bot.block(10, 10));
|
||||
}
|
||||
@@ -234,18 +270,7 @@ public class Debugger {
|
||||
}
|
||||
|
||||
public void setTarget(int n) {
|
||||
Agent agent = TerminatorPlus.getInstance().getManager().getAgent();
|
||||
if (!(agent instanceof LegacyAgent)) {
|
||||
print("This method currently only supports " + ChatColor.AQUA + "LegacyAgent" + ChatColor.RESET + ".");
|
||||
return;
|
||||
}
|
||||
|
||||
LegacyAgent legacyAgent = (LegacyAgent) agent;
|
||||
EnumTargetGoal goal = EnumTargetGoal.of(n);
|
||||
|
||||
legacyAgent.setTargetType(goal);
|
||||
|
||||
print("The goal has been set to " + ChatColor.BLUE + goal.name() + ChatColor.RESET + ".");
|
||||
print("This has been established as a feature as \"" + ChatColor.AQUA + "/bot settings setgoal" + ChatColor.RESET + "\"!");
|
||||
}
|
||||
|
||||
public void fire(boolean b) {
|
||||
|
||||
@@ -67,4 +67,22 @@ public class PlayerUtils {
|
||||
return loc.clone().add(0, amount, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public static Location findBottom(Location loc) {
|
||||
loc.setY(loc.getBlockY());
|
||||
|
||||
for (int i = 0; i < 255; i++) {
|
||||
Location check = loc.clone().add(0, -i, 0);
|
||||
|
||||
if (check.getY() <= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (check.getBlock().getType().isSolid()) {
|
||||
return check.add(0, 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
return loc;
|
||||
}
|
||||
}
|
||||
|
||||
26
src/main/java/net/nuggetmc/ai/utils/Singularity.java
Normal file
26
src/main/java/net/nuggetmc/ai/utils/Singularity.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package net.nuggetmc.ai.utils;
|
||||
|
||||
public class Singularity {
|
||||
|
||||
private Object value;
|
||||
|
||||
public Singularity(Object value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Singularity() {
|
||||
this.value = null;
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(Object value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public boolean hasValue() {
|
||||
return value != null;
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,13 @@ package net.nuggetmc.ai.utils;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
import java.util.Locale;
|
||||
|
||||
public class StringUtilities {
|
||||
|
||||
public static final NumberFormat NUMBER_FORMAT = NumberFormat.getNumberInstance(Locale.US);
|
||||
|
||||
public static final String ON = ChatColor.GREEN.toString();
|
||||
public static final String OFF = ChatColor.GRAY.toString();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user