Can't hit npc player spawn by NMS

Discussion in 'Spigot Plugin Development' started by chunza2542, Jun 8, 2017.

  1. I try to make a player npc that player can hit it. but when I spawn the player npc (see my code below) the npc seem like in Gamemode 1. How can I fix this. thx

    Here is my spawn method:
    Code (Text):
    public void spawn() {
            if(!this.isAlive){
                MinecraftServer nmsServer = ((CraftServer) Bukkit.getServer()).getServer();
                WorldServer nmsWorld = ((CraftWorld) this.location.getWorld()).getHandle();
                this.herobrine = new EntityPlayer(nmsServer, nmsWorld, new GameProfile(UUID.fromString("f84c6a79-0a4e-45e0-879b-cd49ebd4c4e2"), "Herobrine"), new PlayerInteractManager(nmsWorld));
                this.herobrine.setLocation(location.getX(), location.getY(), location.getZ(), 0, 0);
                this.isAlive = true;
                for(Player player : Bukkit.getOnlinePlayers()){
                    PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection;
                    connection.sendPacket(new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.ADD_PLAYER, this.herobrine));
                    connection.sendPacket(new PacketPlayOutNamedEntitySpawn(this.herobrine));
                }
            }
        }
     
  2. You need to add an packetinjector to the player to listen to the PacketPlayInUseEntity packet
     
    • Like Like x 1
  3. @Pxlogz can you give me some example code
     
  4. Ty for spelling my Name completly wrong xd but nvm, i won't spoonfeed you sry
     
    • Like Like x 1
  5. Ok thx I will try