Hiding NPC from tab hides skins

Discussion in 'Spigot Plugin Development' started by Kingbluesapphire, May 26, 2018.

  1. I am working on a Spigot 1.8.9 plugin with NPCs.

    My issue is when a player joins I have to loop through all the npcs and respawn them for everyone, is there a way to do only respawn the npcs for a single player? Also when a player teleports to another world and then comes back the npcs are gone.

    Code (Java):
    public void spawn(){
        PacketPlayOutNamedEntitySpawn packet = new PacketPlayOutNamedEntitySpawn();

        setValue(packet, "a", entityID);
        setValue(packet, "b", gameprofile.getId());
        setValue(packet, "c", getFixLocation(location.getX()));
        setValue(packet, "d", getFixLocation(location.getY()));
        setValue(packet, "e", getFixLocation(location.getZ()));
        setValue(packet, "f", getFixRotation(location.getYaw()));
        setValue(packet, "g", getFixRotation(location.getPitch()));
        setValue(packet, "h", 0);
        DataWatcher w = new DataWatcher(null);
        setValue(packet, "i", w);
        headRotation(location.getYaw(), location.getPitch());

        PacketPlayOutPlayerInfo packet1 = new PacketPlayOutPlayerInfo();
        PacketPlayOutPlayerInfo.PlayerInfoData data = packet1.new PlayerInfoData(gameprofile, 1, EnumGamemode.NOT_SET, CraftChatMessage.fromString(gameprofile.getName())[0]);
        List<PacketPlayOutPlayerInfo.PlayerInfoData> players = (List<PacketPlayOutPlayerInfo.PlayerInfoData>) getValue(packet1, "b");

        setValue(packet1, "a", PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER);
        setValue(packet1, "b", players);

    #1 Kingbluesapphire, May 26, 2018
    Last edited: May 26, 2018
  2. Serializator


    In case of not respawning the NPCs for all players, you're using packets, so you can easily respawn the NPCs for a single player by only sending the packets to a single player?

    For the switching of worlds, do the same thing as when a player joins.
    • Agree Agree x 1