Solved Fake player spawning with ProtocolLib

Discussion in 'Spigot Plugin Development' started by Vytska111, Feb 22, 2020.

  1. Hello,
    I'm trying to spawn a fake player with ProtocolLib. Here's my whole class:
    Code (Text):
    package net.VytskaLT.NPCLibrary;

    import com.comphenix.protocol.ProtocolManager;
    import com.comphenix.protocol.wrappers.*;
    import net.VytskaLT.NPCLibrary.wrapper.WrapperPlayServerNamedEntitySpawn;
    import net.VytskaLT.NPCLibrary.wrapper.WrapperPlayServerPlayerInfo;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;

    import java.lang.reflect.InvocationTargetException;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Random;
    import java.util.UUID;

    public class TestCommand implements CommandExecutor {

        private ProtocolManager manager;
        private Random random;

        public TestCommand(ProtocolManager manager) {
            this.manager = manager;
            this.random = new Random();

        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {

            Player player = (Player) sender;

            WrapperPlayServerNamedEntitySpawn body = new WrapperPlayServerNamedEntitySpawn();

            UUID id = UUID.randomUUID();
            int corpseId = random.nextInt(1000);



            WrapperPlayServerPlayerInfo info = new WrapperPlayServerPlayerInfo();


            PlayerInfoData data = new PlayerInfoData(new WrappedGameProfile(id, "Test"), 1, EnumWrappers.NativeGameMode.CREATIVE, WrappedChatComponent.fromText("Test"));
            List<PlayerInfoData> dataList = new ArrayList<PlayerInfoData>();

            try {
                manager.sendServerPacket(player, info.getHandle());
                manager.sendServerPacket(player, body.getHandle());
            } catch (InvocationTargetException e) {
            return true;
    Now, when I execute the code, nothing happens. No errors. I have tried to fix this for some time and had no luck. If you know what's wrong with my code, please help me.
    Thank you
  2. Did you register the command in the Main method and in the Plugin.yml?
  3. Yes, of course I did. I know for a fact that those packets are sent to the client, but there's something wrong with them, so that's why I made this thread.
    #3 Vytska111, Feb 22, 2020
    Last edited: Feb 22, 2020
  4. Update: I found out that the fake player actually shows up in tab, so that means that the player info packet worked, and that means that the issue is most likely in the entity spawn event. I'm not sure, but I think that the issue is happening because I dont send any metadata in the event, because I don't know how to.
    #4 Vytska111, Feb 22, 2020
    Last edited: Feb 22, 2020
  5. Bump and another update: I have found out how to add the entity metadata with ProtocolLib. It goes something like this:
    Code (Text):
    WrappedDataWatcher watcher = new WrappedDataWatcher();

    watcher.setObject(0, WrappedDataWatcher.Registry.get(Byte.class), (byte) 0);

    theEntitySpawnPacket.getDataWatcherModifier().write(0, watcher);
    But the thing is, that the data watcher registry doesn't exist in 1.8.8. I know that there is a 1.8.8 way without the registry thing, but I cannot find any examples. Does anybody know how to do this?

    EDIT: Fixed. I didn't even need to add any metadata, the coordinate fields in named entity spawn packet were just wrong.
    #5 Vytska111, Feb 23, 2020
    Last edited: Feb 23, 2020