Created
November 26, 2021 18:11
-
-
Save HardstylesDev/0608c0e807baf9b1b9e77d6b47c27c51 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Getter | |
@Setter | |
public class NPC { | |
private Location location; | |
private String name; | |
private EntityPlayer entity; | |
public NPC(Location location, OfflinePlayer fake) { | |
this.location = location; | |
MinecraftServer nmsServer = ((CraftServer) Bukkit.getServer()).getServer(); | |
WorldServer nmsWorld = ((CraftWorld) location.getWorld()).getHandle(); | |
entity = new EntityPlayer(nmsServer, nmsWorld, new GameProfile(fake.getUniqueId(), fake.getName()), new PlayerInteractManager(nmsWorld)); | |
entity.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw() * 256.0F / 360.0F, location.getPitch() * 256.0F / 360.0F); | |
} | |
public void show(Player... target) { | |
PacketPlayOutPlayerInfo add = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, entity); | |
PacketPlayOutNamedEntitySpawn spawn = new PacketPlayOutNamedEntitySpawn(entity); | |
PacketPlayOutEntityHeadRotation rotate = new PacketPlayOutEntityHeadRotation(entity, (byte) (location.getYaw() * 256.0F / 360.0F)); | |
for (Player player : target) { | |
PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection; | |
connection.sendPacket(add); | |
connection.sendPacket(spawn); | |
connection.sendPacket(rotate); | |
} | |
} | |
public void setHand(ItemStack item) { | |
entity.inventory.setItem(entity.inventory.itemInHandIndex, CraftItemStack.asNMSCopy(item)); | |
} | |
public void remove(Player... player) { | |
PacketPlayOutEntityDestroy packet = new PacketPlayOutEntityDestroy(entity.getId()); | |
for (Player viewer : player) { | |
((CraftPlayer) viewer).getHandle().playerConnection.sendPacket(packet); | |
} | |
} | |
public void onInteract(Player p) { | |
p.sendMessage(ChatColor.GREEN + "Thanks for interacting with me, " + p.getName() + "!"); | |
//todo open inventory or sth | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment