- Баллы
- 66
- Имя в Minecraft
- kolia1_1
PHP:
public void createNPC(Player player, String npcName) {
Location location = player.getLocation();
MinecraftServer nmsServer = ((CraftServer) Bukkit.getServer()).getServer();
WorldServer nmsWorld = ((CraftWorld) player.getWorld()).getHandle();
GameProfile gameProfile = new GameProfile(UUID.randomUUID(), npcName);
EntityPlayer npc = new EntityPlayer(nmsServer, nmsWorld, gameProfile, new PlayerInteractManager(nmsWorld));
Player npcPlayer = npc.getBukkitEntity().getPlayer();
npcPlayer.setPlayerListName("");
npc.setLocation(location.getX(), location.getY(), location.getZ(), player.getLocation().getYaw(), player.getLocation().getPitch());
PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection;
connection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, npc));
connection.sendPacket(new PacketPlayOutNamedEntitySpawn(npc));
connection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, npc));
DataWatcher w = npc.getDataWatcher(); //DataWatcher for client side NPC
w.set(new DataWatcherObject<>(0, DataWatcherRegistry.a), (byte) 0x40); //0x20 makes NPC invisible but still rendered
connection.sendPacket(new PacketPlayOutEntityMetadata(npc.getId(), w, true));
}