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:
@@ -1,7 +1,7 @@
|
|||||||
package net.nuggetmc.ai;
|
package net.nuggetmc.ai;
|
||||||
|
|
||||||
import net.nuggetmc.ai.commands.CommandHandler;
|
import net.nuggetmc.ai.commands.CommandHandler;
|
||||||
import net.nuggetmc.ai.npc.NPCManager;
|
import net.nuggetmc.ai.bot.BotManager;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
public class PlayerAI extends JavaPlugin {
|
public class PlayerAI extends JavaPlugin {
|
||||||
@@ -11,7 +11,7 @@ public class PlayerAI extends JavaPlugin {
|
|||||||
private static PlayerAI instance;
|
private static PlayerAI instance;
|
||||||
|
|
||||||
private CommandHandler handler;
|
private CommandHandler handler;
|
||||||
private NPCManager manager;
|
private BotManager manager;
|
||||||
|
|
||||||
public static PlayerAI getInstance() {
|
public static PlayerAI getInstance() {
|
||||||
return instance;
|
return instance;
|
||||||
@@ -21,7 +21,7 @@ public class PlayerAI extends JavaPlugin {
|
|||||||
return handler;
|
return handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NPCManager getManager() {
|
public BotManager getManager() {
|
||||||
return manager;
|
return manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ public class PlayerAI extends JavaPlugin {
|
|||||||
|
|
||||||
// Create Instances
|
// Create Instances
|
||||||
this.handler = new CommandHandler(this);
|
this.handler = new CommandHandler(this);
|
||||||
this.manager = new NPCManager(this);
|
this.manager = new BotManager(this);
|
||||||
|
|
||||||
// Register all the things
|
// Register all the things
|
||||||
this.registerEvents();
|
this.registerEvents();
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package net.nuggetmc.ai.npc;
|
package net.nuggetmc.ai.bot;
|
||||||
|
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import com.mojang.authlib.properties.Property;
|
import com.mojang.authlib.properties.Property;
|
||||||
@@ -19,7 +19,7 @@ import org.bukkit.util.Vector;
|
|||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class NPC extends EntityPlayer {
|
public class Bot extends EntityPlayer {
|
||||||
|
|
||||||
public Vector velocity;
|
public Vector velocity;
|
||||||
|
|
||||||
@@ -28,14 +28,14 @@ public class NPC extends EntityPlayer {
|
|||||||
private final double regenAmount = 0.05;
|
private final double regenAmount = 0.05;
|
||||||
private final double bbOffset = 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);
|
super(minecraftServer, worldServer, profile, manager);
|
||||||
|
|
||||||
velocity = new Vector(0, 0, 0);
|
velocity = new Vector(0, 0, 0);
|
||||||
kbTicks = 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();
|
MinecraftServer nmsServer = ((CraftServer) Bukkit.getServer()).getServer();
|
||||||
WorldServer nmsWorld = ((CraftWorld) loc.getWorld()).getHandle();
|
WorldServer nmsWorld = ((CraftWorld) loc.getWorld()).getHandle();
|
||||||
|
|
||||||
@@ -48,18 +48,18 @@ public class NPC extends EntityPlayer {
|
|||||||
setSkin(profile, skin);
|
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);
|
bot.playerConnection = new PlayerConnection(nmsServer, new NetworkManager(EnumProtocolDirection.CLIENTBOUND), bot);
|
||||||
npc.setLocation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
|
bot.setLocation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
|
||||||
npc.getBukkitEntity().setNoDamageTicks(0);
|
bot.getBukkitEntity().setNoDamageTicks(0);
|
||||||
nmsWorld.addEntity(npc);
|
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) {
|
private static void setSkin(GameProfile profile, String skin) {
|
||||||
@@ -70,13 +70,13 @@ public class NPC extends EntityPlayer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void sendSpawnPackets(NPC npc) {
|
private static void sendSpawnPackets(Bot bot) {
|
||||||
DataWatcher watcher = npc.getDataWatcher();
|
DataWatcher watcher = bot.getDataWatcher();
|
||||||
watcher.set(new DataWatcherObject<>(16, DataWatcherRegistry.a), (byte) 0xFF);
|
watcher.set(new DataWatcherObject<>(16, DataWatcherRegistry.a), (byte) 0xFF);
|
||||||
|
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection;
|
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;
|
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();
|
Vector diff = loc1.toVector().subtract(loc2.toVector()).normalize();
|
||||||
diff.multiply(0.25);
|
diff.multiply(0.25);
|
||||||
diff.setY(0.5);
|
diff.setY(0.5);
|
||||||
@@ -259,14 +259,14 @@ public class NPC extends EntityPlayer {
|
|||||||
|
|
||||||
public void faceLocation(Location loc) {
|
public void faceLocation(Location loc) {
|
||||||
try {
|
try {
|
||||||
CraftPlayer playerNPC = this.getBukkitEntity();
|
CraftPlayer playerBot = this.getBukkitEntity();
|
||||||
Vector dir = loc.toVector().subtract(playerNPC.getLocation().toVector()).normalize();
|
Vector dir = loc.toVector().subtract(playerBot.getLocation().toVector()).normalize();
|
||||||
Location facing = playerNPC.getLocation().setDirection(dir);
|
Location facing = playerBot.getLocation().setDirection(dir);
|
||||||
playerNPC.teleport(facing);
|
playerBot.teleport(facing);
|
||||||
|
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection;
|
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) { }
|
} catch (IllegalArgumentException ignored) { }
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package net.nuggetmc.ai.npc;
|
package net.nuggetmc.ai.bot;
|
||||||
|
|
||||||
import net.minecraft.server.v1_16_R3.PlayerConnection;
|
import net.minecraft.server.v1_16_R3.PlayerConnection;
|
||||||
import net.nuggetmc.ai.PlayerAI;
|
import net.nuggetmc.ai.PlayerAI;
|
||||||
@@ -10,38 +10,38 @@ import org.bukkit.event.player.PlayerJoinEvent;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class NPCManager implements Listener {
|
public class BotManager implements Listener {
|
||||||
|
|
||||||
private final PlayerAI plugin;
|
private final PlayerAI plugin;
|
||||||
|
|
||||||
private final Set<NPC> npcs = new HashSet<>();
|
private final Set<Bot> bots = new HashSet<>();
|
||||||
|
|
||||||
public Set<NPC> fetch() {
|
public Set<Bot> fetch() {
|
||||||
return npcs;
|
return bots;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(NPC npc) {
|
public void add(Bot bot) {
|
||||||
npcs.add(npc);
|
bots.add(bot);
|
||||||
}
|
}
|
||||||
|
|
||||||
public NPCManager(PlayerAI plugin) {
|
public BotManager(PlayerAI plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reset() {
|
public void reset() {
|
||||||
for (NPC npc : npcs) {
|
for (Bot bot : bots) {
|
||||||
npc.despawn();
|
bot.despawn();
|
||||||
}
|
}
|
||||||
|
|
||||||
npcs.clear();
|
bots.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onJoin(PlayerJoinEvent event) {
|
public void onJoin(PlayerJoinEvent event) {
|
||||||
PlayerConnection connection = ((CraftPlayer) event.getPlayer()).getHandle().playerConnection;
|
PlayerConnection connection = ((CraftPlayer) event.getPlayer()).getHandle().playerConnection;
|
||||||
|
|
||||||
for (NPC npc : npcs) {
|
for (Bot bot : bots) {
|
||||||
npc.render(connection, true);
|
bot.render(connection, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -7,8 +7,8 @@ import com.jonahseguin.drink.annotation.Sender;
|
|||||||
import net.nuggetmc.ai.PlayerAI;
|
import net.nuggetmc.ai.PlayerAI;
|
||||||
import net.nuggetmc.ai.commands.CommandHandler;
|
import net.nuggetmc.ai.commands.CommandHandler;
|
||||||
import net.nuggetmc.ai.commands.CommandInstance;
|
import net.nuggetmc.ai.commands.CommandInstance;
|
||||||
import net.nuggetmc.ai.npc.NPC;
|
import net.nuggetmc.ai.bot.Bot;
|
||||||
import net.nuggetmc.ai.npc.NPCManager;
|
import net.nuggetmc.ai.bot.BotManager;
|
||||||
import net.nuggetmc.ai.utils.ChatUtils;
|
import net.nuggetmc.ai.utils.ChatUtils;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@@ -38,7 +38,7 @@ public class PlayerAICommand extends CommandInstance {
|
|||||||
@Command(name = "create", desc = "Create bots.", usage = "<name> [skin]")
|
@Command(name = "create", desc = "Create bots.", usage = "<name> [skin]")
|
||||||
@Require("playerai.manage")
|
@Require("playerai.manage")
|
||||||
public void createBotCommand(@Sender Player sender, String name, @OptArg String skin) {
|
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.")
|
@Command(name = "debug", desc = "Debug bot stats.")
|
||||||
@@ -58,7 +58,7 @@ public class PlayerAICommand extends CommandInstance {
|
|||||||
public void resetCommand(@Sender Player sender) {
|
public void resetCommand(@Sender Player sender) {
|
||||||
sender.sendMessage("Removing every bot...");
|
sender.sendMessage("Removing every bot...");
|
||||||
|
|
||||||
NPCManager manager = PlayerAI.getInstance().getManager();
|
BotManager manager = PlayerAI.getInstance().getManager();
|
||||||
int size = manager.fetch().size();
|
int size = manager.fetch().size();
|
||||||
manager.reset();
|
manager.reset();
|
||||||
|
|
||||||
|
|||||||
@@ -11,5 +11,5 @@ permissions:
|
|||||||
children:
|
children:
|
||||||
playerai.manage: true
|
playerai.manage: true
|
||||||
playerai.manage:
|
playerai.manage:
|
||||||
description: Allows for PlayerAI NPC management.
|
description: Allows for PlayerAI bot management.
|
||||||
default: op
|
default: op
|
||||||
Reference in New Issue
Block a user