added readme and refactored NPC to Bot because bot sounds cooler and NPC sounds too much like Citizens and citizens yuck amirite

This commit is contained in:
batchprogrammer314
2021-06-27 00:26:45 -05:00
parent 19abd19a9d
commit 30e8ee3f82
5 changed files with 43 additions and 43 deletions

View File

@@ -1,7 +1,7 @@
package net.nuggetmc.ai;
import net.nuggetmc.ai.commands.CommandHandler;
import net.nuggetmc.ai.npc.NPCManager;
import net.nuggetmc.ai.bot.BotManager;
import org.bukkit.plugin.java.JavaPlugin;
public class PlayerAI extends JavaPlugin {
@@ -11,7 +11,7 @@ public class PlayerAI extends JavaPlugin {
private static PlayerAI instance;
private CommandHandler handler;
private NPCManager manager;
private BotManager manager;
public static PlayerAI getInstance() {
return instance;
@@ -21,7 +21,7 @@ public class PlayerAI extends JavaPlugin {
return handler;
}
public NPCManager getManager() {
public BotManager getManager() {
return manager;
}
@@ -31,7 +31,7 @@ public class PlayerAI extends JavaPlugin {
// Create Instances
this.handler = new CommandHandler(this);
this.manager = new NPCManager(this);
this.manager = new BotManager(this);
// Register all the things
this.registerEvents();

View File

@@ -1,4 +1,4 @@
package net.nuggetmc.ai.npc;
package net.nuggetmc.ai.bot;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
@@ -19,7 +19,7 @@ import org.bukkit.util.Vector;
import java.util.UUID;
public class NPC extends EntityPlayer {
public class Bot extends EntityPlayer {
public Vector velocity;
@@ -28,14 +28,14 @@ public class NPC extends EntityPlayer {
private final double regenAmount = 0.05;
private final double bbOffset = 0.05;
public NPC(MinecraftServer minecraftServer, WorldServer worldServer, GameProfile profile, PlayerInteractManager manager) {
public Bot(MinecraftServer minecraftServer, WorldServer worldServer, GameProfile profile, PlayerInteractManager manager) {
super(minecraftServer, worldServer, profile, manager);
velocity = new Vector(0, 0, 0);
kbTicks = 0;
}
public static NPC createNPC(String name, Location loc, String skin) {
public static Bot createBot(String name, Location loc, String skin) {
MinecraftServer nmsServer = ((CraftServer) Bukkit.getServer()).getServer();
WorldServer nmsWorld = ((CraftWorld) loc.getWorld()).getHandle();
@@ -48,18 +48,18 @@ public class NPC extends EntityPlayer {
setSkin(profile, skin);
}
NPC npc = new NPC(nmsServer, nmsWorld, profile, interactManager);
Bot bot = new Bot(nmsServer, nmsWorld, profile, interactManager);
npc.playerConnection = new PlayerConnection(nmsServer, new NetworkManager(EnumProtocolDirection.CLIENTBOUND), npc);
npc.setLocation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
npc.getBukkitEntity().setNoDamageTicks(0);
nmsWorld.addEntity(npc);
bot.playerConnection = new PlayerConnection(nmsServer, new NetworkManager(EnumProtocolDirection.CLIENTBOUND), bot);
bot.setLocation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
bot.getBukkitEntity().setNoDamageTicks(0);
nmsWorld.addEntity(bot);
sendSpawnPackets(npc);
sendSpawnPackets(bot);
PlayerAI.getInstance().getManager().add(npc);
PlayerAI.getInstance().getManager().add(bot);
return npc;
return bot;
}
private static void setSkin(GameProfile profile, String skin) {
@@ -70,13 +70,13 @@ public class NPC extends EntityPlayer {
}
}
private static void sendSpawnPackets(NPC npc) {
DataWatcher watcher = npc.getDataWatcher();
private static void sendSpawnPackets(Bot bot) {
DataWatcher watcher = bot.getDataWatcher();
watcher.set(new DataWatcherObject<>(16, DataWatcherRegistry.a), (byte) 0xFF);
for (Player player : Bukkit.getOnlinePlayers()) {
PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection;
npc.render(connection, false);
bot.render(connection, false);
}
}
@@ -248,7 +248,7 @@ public class NPC extends EntityPlayer {
return damaged;
}
private void kb(Player playerNPC, Location loc1, Location loc2) {
private void kb(Player playerBot, Location loc1, Location loc2) {
Vector diff = loc1.toVector().subtract(loc2.toVector()).normalize();
diff.multiply(0.25);
diff.setY(0.5);
@@ -259,14 +259,14 @@ public class NPC extends EntityPlayer {
public void faceLocation(Location loc) {
try {
CraftPlayer playerNPC = this.getBukkitEntity();
Vector dir = loc.toVector().subtract(playerNPC.getLocation().toVector()).normalize();
Location facing = playerNPC.getLocation().setDirection(dir);
playerNPC.teleport(facing);
CraftPlayer playerBot = this.getBukkitEntity();
Vector dir = loc.toVector().subtract(playerBot.getLocation().toVector()).normalize();
Location facing = playerBot.getLocation().setDirection(dir);
playerBot.teleport(facing);
for (Player player : Bukkit.getOnlinePlayers()) {
PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection;
connection.sendPacket(new PacketPlayOutEntityHeadRotation(playerNPC.getHandle(), (byte) (facing.getYaw() * 256 / 360)));
connection.sendPacket(new PacketPlayOutEntityHeadRotation(playerBot.getHandle(), (byte) (facing.getYaw() * 256 / 360)));
}
} catch (IllegalArgumentException ignored) { }
}

View File

@@ -1,4 +1,4 @@
package net.nuggetmc.ai.npc;
package net.nuggetmc.ai.bot;
import net.minecraft.server.v1_16_R3.PlayerConnection;
import net.nuggetmc.ai.PlayerAI;
@@ -10,38 +10,38 @@ import org.bukkit.event.player.PlayerJoinEvent;
import java.util.HashSet;
import java.util.Set;
public class NPCManager implements Listener {
public class BotManager implements Listener {
private final PlayerAI plugin;
private final Set<NPC> npcs = new HashSet<>();
private final Set<Bot> bots = new HashSet<>();
public Set<NPC> fetch() {
return npcs;
public Set<Bot> fetch() {
return bots;
}
public void add(NPC npc) {
npcs.add(npc);
public void add(Bot bot) {
bots.add(bot);
}
public NPCManager(PlayerAI plugin) {
public BotManager(PlayerAI plugin) {
this.plugin = plugin;
}
public void reset() {
for (NPC npc : npcs) {
npc.despawn();
for (Bot bot : bots) {
bot.despawn();
}
npcs.clear();
bots.clear();
}
@EventHandler
public void onJoin(PlayerJoinEvent event) {
PlayerConnection connection = ((CraftPlayer) event.getPlayer()).getHandle().playerConnection;
for (NPC npc : npcs) {
npc.render(connection, true);
for (Bot bot : bots) {
bot.render(connection, true);
}
}

View File

@@ -7,8 +7,8 @@ import com.jonahseguin.drink.annotation.Sender;
import net.nuggetmc.ai.PlayerAI;
import net.nuggetmc.ai.commands.CommandHandler;
import net.nuggetmc.ai.commands.CommandInstance;
import net.nuggetmc.ai.npc.NPC;
import net.nuggetmc.ai.npc.NPCManager;
import net.nuggetmc.ai.bot.Bot;
import net.nuggetmc.ai.bot.BotManager;
import net.nuggetmc.ai.utils.ChatUtils;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
@@ -38,7 +38,7 @@ public class PlayerAICommand extends CommandInstance {
@Command(name = "create", desc = "Create bots.", usage = "<name> [skin]")
@Require("playerai.manage")
public void createBotCommand(@Sender Player sender, String name, @OptArg String skin) {
NPC.createNPC(name, sender.getLocation(), skin == null ? name : skin);
Bot.createBot(name, sender.getLocation(), skin == null ? name : skin);
}
@Command(name = "debug", desc = "Debug bot stats.")
@@ -58,7 +58,7 @@ public class PlayerAICommand extends CommandInstance {
public void resetCommand(@Sender Player sender) {
sender.sendMessage("Removing every bot...");
NPCManager manager = PlayerAI.getInstance().getManager();
BotManager manager = PlayerAI.getInstance().getManager();
int size = manager.fetch().size();
manager.reset();

View File

@@ -11,5 +11,5 @@ permissions:
children:
playerai.manage: true
playerai.manage:
description: Allows for PlayerAI NPC management.
description: Allows for PlayerAI bot management.
default: op