Solved NPCs with reloading, skins, and head rotation.

Discussion in 'Plugin Development' started by Corndogoz, Jul 24, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    Corndogoz

    Hi, so I have never actually made human npcs before with bukkit, so today I followed a tutorial, and came up with this code:
    Code:
            MinecraftServer ms = ((CraftServer) Bukkit.getServer()).getServer();
            WorldServer ws = ((CraftWorld) Bukkit.getServer().getWorld(getConfig().getString("npcworld"))).getHandle();
            vnpc = new EntityPlayer(ms,ws,new GameProfile(UUID.fromString("95ec2ce5-5f17-424a-8ae5-622fb911fd3a"), "Hero Selector"),new PlayerInteractManager(ws));
            Location vl = new Location(ws.getWorld(), Double.valueOf(getConfig().getString("vnpc").split(",")[0]), Double.valueOf(getConfig().getString("vnpc").split(",")[1]), Double.valueOf(getConfig().getString("vnpc").split(",")[2]));
            vl.setPitch(Float.valueOf(getConfig().getString("vnpc").split(",")[3]));
            vl.setYaw(Float.valueOf(getConfig().getString("vnpc").split(",")[4]));
            vnpc.teleportTo(vl, false);
            ((EntityLiving) vnpc).aP = Float.valueOf(getConfig().getString("vnpc").split(",")[5]);
            hnpc = new EntityPlayer(ms,ws,new GameProfile(UUID.fromString("b848fd93-621b-4c0f-b8c7-874e0e1bca2a"), "Villain Selector"),new PlayerInteractManager(ws));
            Location hl = new Location(ws.getWorld(), Double.valueOf(getConfig().getString("hnpc").split(",")[0]), Double.valueOf(getConfig().getString("hnpc").split(",")[1]), Double.valueOf(getConfig().getString("hnpc").split(",")[2]));
            hl.setPitch(Float.valueOf(getConfig().getString("hnpc").split(",")[3]));
            hl.setYaw(Float.valueOf(getConfig().getString("hnpc").split(",")[4]));
            hnpc.teleportTo(hl, false);
            ((EntityLiving) hnpc).aP = Float.valueOf(getConfig().getString("hnpc").split(",")[5]);
    and then this for on player join:
    Code:
    public void onPlayerJoin(PlayerJoinEvent e){
            PlayerConnection connection = ((CraftPlayer) e.getPlayer()).getHandle().playerConnection;
            connection.sendPacket(new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, vnpc));
            connection.sendPacket(new PacketPlayOutNamedEntitySpawn(vnpc));
            connection.sendPacket(new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, vnpc));
            connection.sendPacket(new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, hnpc));
            connection.sendPacket(new PacketPlayOutNamedEntitySpawn(hnpc));
            connection.sendPacket(new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, hnpc));
        }
    I have a few problems:

    #1
    I would like reloading the plugin to update the npcs to the newest configuration value, without needing to rejoin the server, however I have no clue how to check if the game has the npc already(I would put it in on enable)

    #2
    When changing the head rotation with ((EntityLiving) hnpc).aP = Float.valueOf(getConfig().getString("hnpc").split(",")[5]); The head will rotate no more then about 10 degrees.

    #3
    Only the player which has the same uuid as the npcs uuid can see the npcs skin(The npc was suppose to get the skin from the uuid).

    #4
    For some reason, when I set the npcs yaw, it never actually matches the yaw in the config???

    Any help is appreciated, thanks!
     
    Last edited: Jul 26, 2016
  2. Offline

    Corndogoz

  3. Offline

    Corndogoz

  4. Offline

    Corndogoz

Thread Status:
Not open for further replies.

Share This Page