Better bot creation, faceLocation() improved, Mojang API fetching cache added.

This commit is contained in:
batchprogrammer314
2021-06-28 13:18:49 -05:00
parent 70490d55bb
commit 79add1b78d
6 changed files with 130 additions and 27 deletions

View File

@@ -2,10 +2,16 @@ package net.nuggetmc.ai.bot;
import net.minecraft.server.v1_16_R3.PlayerConnection;
import net.nuggetmc.ai.PlayerAI;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Particle;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.util.Vector;
import java.util.HashSet;
import java.util.Set;
@@ -28,6 +34,35 @@ public class BotManager implements Listener {
this.plugin = plugin;
}
public void createBots(Player sender, String name, String skin, int n) {
long timestamp = System.currentTimeMillis();
if (n < 1) n = 1;
World world = sender.getWorld();
Location loc = sender.getLocation();
if (name.length() > 16) name = name.substring(0, 16);
if (skin != null && skin.length() > 16) skin = skin.substring(0, 16);
sender.sendMessage("Creating " + (n == 1 ? "new bot" : ChatColor.RED + String.valueOf(n) + ChatColor.RESET + " new bots")
+ " with name " + ChatColor.GREEN + name
+ (skin == null ? "" : ChatColor.RESET + " and skin " + ChatColor.GREEN + skin) + ChatColor.RESET + "...");
skin = skin == null ? name : skin;
for (int i = 0; i < n; i++) {
Bot bot = Bot.createBot(loc, name, skin);
if (i > 0) bot.setVelocity(new Vector(Math.random() - 0.5, 0.5, Math.random() - 0.5).normalize().multiply(0.4));
}
world.spawnParticle(Particle.CLOUD, loc, 100, 1, 1, 1, 0.5);
double time = (System.currentTimeMillis() - timestamp) / 1000D;
sender.sendMessage("Process completed (" + ChatColor.RED + time + "s" + ChatColor.RESET + ").");
}
public void reset() {
for (Bot bot : bots) {
bot.despawn();